This message was deleted.
# general
s
This message was deleted.
a
@Neng
n
@Oneeb can you share me the code snippet you are tying with? I can help take a look. Also, we internally uses:
Copy code
SomeFunction implements Function<GenericObject, Record<GenericObject>>
For some generic processing.
o
@Neng this is the function Im trying to use:
Copy code
public class CustomFunction implements Function<GenericRecord, GenericRecord> {
    @Override
    public GenericRecord process(GenericRecord input, Context context) {
        System.out.println("Schema type: " + input.getSchemaType());
        KeyValue<?, ?> kvInput = (KeyValue<?, ?>) input.getNativeObject();
        GenericRecord value = (GenericRecord) kvInput.getValue();
        
        System.out.println("kv Value: " + value);
        System.out.println("GenericRecord Value: " + value.getFields());
        
        String payloadOperation = (String) value.getField("op");
        
        GenericRecord payload = value;
        if (payloadOperation.equals("c") || payloadOperation.equals("r") || payloadOperation.equals("u")) {
            payload = (GenericRecord) value.getField("after");
        } else if (payloadOperation.equals("d")) {
            payload = (GenericRecord) value.getField("before");
        }

        return payload;

    }
}
How can I cast the
payload
as a
Record<GenericObject>
?
@Neng can you help me here or point me in the right direction?
a
@Alexander Preuß probably knows
a
n
We used something like:
Copy code
public class XFunction implements Function<GenericObject, Record<GenericObject>> {
...
}
And then you can
Copy code
Record<GenericObject> record = (Record<GenericObject>) context.getCurrentRecord();

Schema<T> schema = record.getSchema();

// conversion schema to outputSchema based on your need

FunctionRecordBuilder recordBuilder =
                context.newOutputRecordBuilder(outputSchema).destinationTopic(targetTopic);