DBZ-306 make JSON serializer a RecordMakers field to avoid object recreations
also fix some checkstyle violations which are not yet reported during build process see full PR discussion about the rationale behind the taken approach here https://github.com/debezium/debezium/pull/258
This commit is contained in:
parent
1d75cbdc4e
commit
af2a55cc9b
@ -11,6 +11,7 @@
|
||||
|
||||
import com.mongodb.DBCollection;
|
||||
import com.mongodb.util.JSONSerializers;
|
||||
import com.mongodb.util.ObjectSerializer;
|
||||
import org.apache.kafka.connect.data.Schema;
|
||||
import org.apache.kafka.connect.data.SchemaBuilder;
|
||||
import org.apache.kafka.connect.data.Struct;
|
||||
@ -36,6 +37,7 @@
|
||||
@ThreadSafe
|
||||
public class RecordMakers {
|
||||
|
||||
private static final ObjectSerializer jsonSerializer = JSONSerializers.getStrict();
|
||||
private static final Map<String, Operation> operationLiterals = new HashMap<>();
|
||||
static {
|
||||
operationLiterals.put("i", Operation.CREATE);
|
||||
@ -204,13 +206,13 @@ record = new SourceRecord(sourcePartition, offset, topicName, partition, keySche
|
||||
}
|
||||
|
||||
protected String idObjToJson(Object idObj) {
|
||||
if(idObj == null) {
|
||||
if (idObj == null) {
|
||||
return null;
|
||||
}
|
||||
if(!(idObj instanceof Document)) {
|
||||
return JSONSerializers.getStrict().serialize(idObj);
|
||||
if (!(idObj instanceof Document)) {
|
||||
return jsonSerializer.serialize(idObj);
|
||||
}
|
||||
return JSONSerializers.getStrict().serialize(
|
||||
return jsonSerializer.serialize(
|
||||
((Document)idObj).get(DBCollection.ID_FIELD_NAME)
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user