Home

Awesome

Introduction

This project provides a Serializer, Deserializer and a Serde for Kafka Streams using Jackson for JSON processing. All of the available settings for Jackson are configurable.

Maven Central

What if I don't know what settings to use.

If you are already defining a ObjectMapper that works for you and you want to use it's settings. Use this method to dump the non default settings. This will compare all of the default settings against the supplied ObjectMapper and return the configuration values that the equivalent.

ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(SerializationFeature.INDENT_OUTPUT, true)
Map<String, String> actual = JacksonSerializer.nonDefaultSettings(objectMapper);

Kafka Streams Serde

The Serde can be configured by passing in the class to deserialize to. This will return a Serde with configured to the object type. When configure is called it will ignore any output.class supplied since it has already been configured.

Serde<TestPojo> serde = JacksonSerde.of(TestPojo.class);

Serializer

The Serializer does not need to be specified with a type. It will serialize any object that is passed to it.

Map<String, String> settings = ImmutableMap.of(
    ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, JacksonSerializer.class.getName(),
    ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, JacksonSerializer.class.getName()
);
Producer<String, TestPojo> producer = new KafkaProducer<>(settings);
// Do your thing

Configuration

NameDescriptionTypeDefaultValid ValuesImportance
accept.case.insensitive.enums.enableSee ACCEPT_CASE_INSENSITIVE_ENUMSbooleanfalsemedium
accept.case.insensitive.properties.enableSee ACCEPT_CASE_INSENSITIVE_PROPERTIESbooleanfalsemedium
allow.coercion.of.scalars.enableSee ALLOW_COERCION_OF_SCALARSbooleantruemedium
allow.explicit.property.renaming.enableSee ALLOW_EXPLICIT_PROPERTY_RENAMINGbooleanfalsemedium
allow.final.fields.as.mutators.enableSee ALLOW_FINAL_FIELDS_AS_MUTATORSbooleantruemedium
auto.detect.creators.enableSee AUTO_DETECT_CREATORSbooleantruemedium
auto.detect.fields.enableSee AUTO_DETECT_FIELDSbooleantruemedium
auto.detect.getters.enableSee AUTO_DETECT_GETTERSbooleantruemedium
auto.detect.is.getters.enableSee AUTO_DETECT_IS_GETTERSbooleantruemedium
auto.detect.setters.enableSee AUTO_DETECT_SETTERSbooleantruemedium
can.override.access.modifiers.enableSee CAN_OVERRIDE_ACCESS_MODIFIERSbooleantruemedium
default.view.inclusion.enableSee DEFAULT_VIEW_INCLUSIONbooleantruemedium
fail.on.empty.beans.enableSee FAIL_ON_EMPTY_BEANSbooleantruemedium
fail.on.self.references.enableSee FAIL_ON_SELF_REFERENCESbooleantruemedium
fail.on.unwrapped.type.identifiers.enableSee FAIL_ON_UNWRAPPED_TYPE_IDENTIFIERSbooleantruemedium
ignore.duplicate.module.registrations.enableSee IGNORE_DUPLICATE_MODULE_REGISTRATIONSbooleantruemedium
ignore.merge.for.unmergeable.enableSee IGNORE_MERGE_FOR_UNMERGEABLEbooleantruemedium
indent.output.enableSee INDENT_OUTPUTbooleanfalsemedium
infer.creator.from.constructor.properties.enableSee INFER_CREATOR_FROM_CONSTRUCTOR_PROPERTIESbooleantruemedium
infer.property.mutators.enableSee INFER_PROPERTY_MUTATORSbooleantruemedium
java.time.module.enableFlag to register the java time module.booleanfalsemedium
order.map.entries.by.keys.enableSee ORDER_MAP_ENTRIES_BY_KEYSbooleanfalsemedium
override.public.access.modifiers.enableSee OVERRIDE_PUBLIC_ACCESS_MODIFIERSbooleantruemedium
propagate.transient.marker.enableSee PROPAGATE_TRANSIENT_MARKERbooleanfalsemedium
require.setters.for.getters.enableSee REQUIRE_SETTERS_FOR_GETTERSbooleanfalsemedium
sort.properties.alphabetically.enableSee SORT_PROPERTIES_ALPHABETICALLYbooleanfalsemedium
use.annotations.enableSee USE_ANNOTATIONSbooleantruemedium
use.equality.for.object.id.enableSee USE_EQUALITY_FOR_OBJECT_IDbooleanfalsemedium
use.getters.as.setters.enableSee USE_GETTERS_AS_SETTERSbooleantruemedium
use.static.typing.enableSee USE_STATIC_TYPINGbooleanfalsemedium
use.std.bean.naming.enableSee USE_STD_BEAN_NAMINGbooleanfalsemedium
use.wrapper.name.as.property.name.enableSee USE_WRAPPER_NAME_AS_PROPERTY_NAMEbooleanfalsemedium
wrap.exceptions.enableSee WRAP_EXCEPTIONSbooleantruemedium
wrap.root.value.enableSee WRAP_ROOT_VALUEbooleanfalsemedium
write.char.arrays.as.json.arrays.enableSee WRITE_CHAR_ARRAYS_AS_JSON_ARRAYSbooleanfalsemedium
write.date.keys.as.timestamps.enableSee WRITE_DATE_KEYS_AS_TIMESTAMPSbooleanfalsemedium
write.date.timestamps.as.nanoseconds.enableSee WRITE_DATE_TIMESTAMPS_AS_NANOSECONDSbooleantruemedium
write.dates.as.timestamps.enableSee WRITE_DATES_AS_TIMESTAMPSbooleantruemedium
write.dates.with.zone.id.enableSee WRITE_DATES_WITH_ZONE_IDbooleanfalsemedium
write.durations.as.timestamps.enableSee WRITE_DURATIONS_AS_TIMESTAMPSbooleantruemedium
write.enums.using.index.enableSee WRITE_ENUMS_USING_INDEXbooleanfalsemedium
write.enums.using.to.string.enableSee WRITE_ENUMS_USING_TO_STRINGbooleanfalsemedium
write.single.elem.arrays.unwrapped.enableSee WRITE_SINGLE_ELEM_ARRAYS_UNWRAPPEDbooleanfalsemedium

Deserializer

Generically processing Json

By default if you do not configure a class to deserialize to the serializer will deserialize to a Jackson JsonNode. Assuming that your data is Json objects you can use ObjectNode.

Map<String, String> settings = ImmutableMap.of(
    ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, JacksonDeserializer.class.getName(),
    ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, JacksonDeserializer.class.getName()
);
Consumer<JsonNode, JsonNode> consumer = new KafkaConsumer<JsonNode, JsonNode>(settings);
// Do your thing

Strongly typed Json

You can tell the deserializer to deserialize to a Pojo.

Map<String, Object> settings = ImmutableMap.of(
    ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, JacksonDeserializer.class.getName(),
    ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, JacksonDeserializer.class.getName(),
    "value.deserializer.output.class", TestPojo.class.getName()
);
Consumer<JsonNode, TestPojo> consumer = new KafkaConsumer<>(settings);

Configuration

NameDescriptionTypeDefaultValid ValuesImportance
output.classThe java class to deserialize to.classclass com.fasterxml.jackson.databind.JsonNodehigh
accept.case.insensitive.enums.enableSee ACCEPT_CASE_INSENSITIVE_ENUMSbooleanfalsemedium
accept.case.insensitive.properties.enableSee ACCEPT_CASE_INSENSITIVE_PROPERTIESbooleanfalsemedium
accept.empty.array.as.null.object.enableSee ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECTbooleanfalsemedium
accept.empty.string.as.null.object.enableSee ACCEPT_EMPTY_STRING_AS_NULL_OBJECTbooleanfalsemedium
accept.float.as.int.enableSee ACCEPT_FLOAT_AS_INTbooleantruemedium
accept.single.value.as.array.enableSee ACCEPT_SINGLE_VALUE_AS_ARRAYbooleanfalsemedium
adjust.dates.to.context.time.zone.enableSee ADJUST_DATES_TO_CONTEXT_TIME_ZONEbooleantruemedium
allow.coercion.of.scalars.enableSee ALLOW_COERCION_OF_SCALARSbooleantruemedium
allow.explicit.property.renaming.enableSee ALLOW_EXPLICIT_PROPERTY_RENAMINGbooleanfalsemedium
allow.final.fields.as.mutators.enableSee ALLOW_FINAL_FIELDS_AS_MUTATORSbooleantruemedium
auto.detect.creators.enableSee AUTO_DETECT_CREATORSbooleantruemedium
auto.detect.fields.enableSee AUTO_DETECT_FIELDSbooleantruemedium
auto.detect.getters.enableSee AUTO_DETECT_GETTERSbooleantruemedium
auto.detect.is.getters.enableSee AUTO_DETECT_IS_GETTERSbooleantruemedium
auto.detect.setters.enableSee AUTO_DETECT_SETTERSbooleantruemedium
can.override.access.modifiers.enableSee CAN_OVERRIDE_ACCESS_MODIFIERSbooleantruemedium
default.view.inclusion.enableSee DEFAULT_VIEW_INCLUSIONbooleantruemedium
eager.deserializer.fetch.enableSee EAGER_DESERIALIZER_FETCHbooleantruemedium
fail.on.ignored.properties.enableSee FAIL_ON_IGNORED_PROPERTIESbooleanfalsemedium
fail.on.invalid.subtype.enableSee FAIL_ON_INVALID_SUBTYPEbooleantruemedium
fail.on.missing.creator.properties.enableSee FAIL_ON_MISSING_CREATOR_PROPERTIESbooleanfalsemedium
fail.on.missing.external.type.id.property.enableSee FAIL_ON_MISSING_EXTERNAL_TYPE_ID_PROPERTYbooleantruemedium
fail.on.null.creator.properties.enableSee FAIL_ON_NULL_CREATOR_PROPERTIESbooleanfalsemedium
fail.on.null.for.primitives.enableSee FAIL_ON_NULL_FOR_PRIMITIVESbooleanfalsemedium
fail.on.numbers.for.enums.enableSee FAIL_ON_NUMBERS_FOR_ENUMSbooleanfalsemedium
fail.on.reading.dup.tree.key.enableSee FAIL_ON_READING_DUP_TREE_KEYbooleanfalsemedium
fail.on.trailing.tokens.enableSee FAIL_ON_TRAILING_TOKENSbooleanfalsemedium
fail.on.unknown.properties.enableSee FAIL_ON_UNKNOWN_PROPERTIESbooleantruemedium
fail.on.unresolved.object.ids.enableSee FAIL_ON_UNRESOLVED_OBJECT_IDSbooleantruemedium
ignore.duplicate.module.registrations.enableSee IGNORE_DUPLICATE_MODULE_REGISTRATIONSbooleantruemedium
ignore.merge.for.unmergeable.enableSee IGNORE_MERGE_FOR_UNMERGEABLEbooleantruemedium
infer.creator.from.constructor.properties.enableSee INFER_CREATOR_FROM_CONSTRUCTOR_PROPERTIESbooleantruemedium
infer.property.mutators.enableSee INFER_PROPERTY_MUTATORSbooleantruemedium
java.time.module.enableFlag to register the java time module.booleanfalsemedium
override.public.access.modifiers.enableSee OVERRIDE_PUBLIC_ACCESS_MODIFIERSbooleantruemedium
propagate.transient.marker.enableSee PROPAGATE_TRANSIENT_MARKERbooleanfalsemedium
read.date.timestamps.as.nanoseconds.enableSee READ_DATE_TIMESTAMPS_AS_NANOSECONDSbooleantruemedium
read.enums.using.to.string.enableSee READ_ENUMS_USING_TO_STRINGbooleanfalsemedium
read.unknown.enum.values.as.null.enableSee READ_UNKNOWN_ENUM_VALUES_AS_NULLbooleanfalsemedium
read.unknown.enum.values.using.default.value.enableSee READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUEbooleanfalsemedium
require.setters.for.getters.enableSee REQUIRE_SETTERS_FOR_GETTERSbooleanfalsemedium
sort.properties.alphabetically.enableSee SORT_PROPERTIES_ALPHABETICALLYbooleanfalsemedium
unwrap.root.value.enableSee UNWRAP_ROOT_VALUEbooleanfalsemedium
unwrap.single.value.arrays.enableSee UNWRAP_SINGLE_VALUE_ARRAYSbooleanfalsemedium
use.annotations.enableSee USE_ANNOTATIONSbooleantruemedium
use.big.decimal.for.floats.enableSee USE_BIG_DECIMAL_FOR_FLOATSbooleanfalsemedium
use.big.integer.for.ints.enableSee USE_BIG_INTEGER_FOR_INTSbooleanfalsemedium
use.getters.as.setters.enableSee USE_GETTERS_AS_SETTERSbooleantruemedium
use.java.array.for.json.array.enableSee USE_JAVA_ARRAY_FOR_JSON_ARRAYbooleanfalsemedium
use.long.for.ints.enableSee USE_LONG_FOR_INTSbooleanfalsemedium
use.static.typing.enableSee USE_STATIC_TYPINGbooleanfalsemedium
use.std.bean.naming.enableSee USE_STD_BEAN_NAMINGbooleanfalsemedium
use.wrapper.name.as.property.name.enableSee USE_WRAPPER_NAME_AS_PROPERTY_NAMEbooleanfalsemedium
wrap.exceptions.enableSee WRAP_EXCEPTIONSbooleantruemedium