Skip to content

Gson support #10104

@frank-montyne

Description

@frank-montyne

Is your enhancement request related to a problem? Please describe.
In our projects we are using Gson not Jackson for Json serialization/deserialization. On top of that we make use of immutables (immutables.org) to define our data objects. Getters and setters are of the form field(), field(type data) not getField(), setField(...). When passing these data classes to JSONSchema.of() the fields are not recognized and we end up with null data in the topic when sending messages using a producer.
Another problem is that in some cases we use json adapters to create a json representation that is different from how the fields are represented in the data class.
At this point it is not possible to set your own JSON schema and pass the JSON string representation instead of the data object.
The SchemaBuilder does not seem to support schema's of type "JSON" .
I tried passing a schema that was created by the JSONSchema class using
String json = JSONSchema.of(Data.class).getSchemaInfo().toString() and then passing the resulting string to
SchemaDefinition.builder().withJsonDef(json).build()
This produces org.apache.avro.SchemaParseException: Type not supported: JSON)

Describe the solution you'd like
Support of JSON schema's in the SchemaDefinition builder. Some documentation on JSON schema's would also be nice.
Support for passing the json representation (string) instead of a POJO.
Direct support for Gson and immutables would be nice.
It would also be nice to be able to specify a limited set of fields to be stored. The json representation of the data object should then be stored as a separate string field.

Describe alternatives you've considered
Switching to Jackson is not an option. Our whole code base is based on Gson for Json related stuff.
Creating mirror classes to convert our immutables to plain and simple POJO's but that's way too much work and a maintenance nightmare.

Additional context
Using version 2.7.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    lifecycle/staletype/enhancementThe enhancements for the existing features or docs. e.g. reduce memory usage of the delayed messages

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions