Skip to content

Serialize/Deserialize generated avro records to/from json using jackson objectMapper

License

Notifications You must be signed in to change notification settings

toolisticon/jackson-avro-module

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jackson-avro-module

A jackson-module that allows serializing and deserializing generated avro specific record instances with the jackson ObjectMapper.

stable Build Status sponsored Maven Central

The problem

If you define your schema in avro and generate a class using the avro generator, the generated class contains fields (schema, specificData) that can not be serialized by the default jackson ObjectMapper.

Non working workarounds

  • avro itself provides a JacksonUtils class that can ignore fields based on visibility. Problem: The feature is hidden and modifies the global ObjectMapper, so a change only required for SpecificRecordBase classes will affect all.
  • jackson on the other hand provides the com.fasterxml.jackson.dataformat.avro.AvroSerializerModifier, but this one just ignores (current version 2.13.4) just one of the two needed properties.

The solution

This library provides a single JacksonAvroModule that uses a modified version of the jackson-databind-avro modifier to exclude bean properties from serialization.

How to use

It is as simple as adding any other jackson-module to your ObjectMapper configuration:

ObjectMapper om = new ObjectMapper()
                      .registerModule(new JacksonAvroModule());

About

Serialize/Deserialize generated avro records to/from json using jackson objectMapper

Resources

License

Stars

Watchers

Forks

Packages

No packages published