https://github.com/toolisticon/jackson-avro-module
Serialize/Deserialize generated avro records to/from json using jackson objectMapper
https://github.com/toolisticon/jackson-avro-module
Last synced: 9 months ago
JSON representation
Serialize/Deserialize generated avro records to/from json using jackson objectMapper
- Host: GitHub
- URL: https://github.com/toolisticon/jackson-avro-module
- Owner: toolisticon
- License: apache-2.0
- Created: 2022-03-03T10:20:06.000Z (over 4 years ago)
- Default Branch: develop
- Last Pushed: 2024-10-09T20:34:07.000Z (over 1 year ago)
- Last Synced: 2025-01-14T18:11:24.384Z (over 1 year ago)
- Language: Java
- Size: 78.1 KB
- Stars: 1
- Watchers: 6
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# jackson-avro-module
A jackson-module that allows serializing and deserializing generated avro specific record instances with the jackson ObjectMapper.
[](https://github.com/holisticon#open-source-lifecycle)
[](https://github.com/toolisticon/jackson-avro-module/actions)
[](https://holisticon.de/)
[](https://maven-badges.herokuapp.com/maven-central/io.toolisticon.jackson.module/jackson-avro-module)
## 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`](./src/main/kotlin/JacksonAvroModule.kt) 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());
```