Interface JsonbSerializer<T>

Type Parameters:
T - Type to bind serializer for.

public interface JsonbSerializer<T>

Interface representing a custom serializer for given type. Unlike JsonbAdapter serializer provides more fine grained control over serialization process by writing java object directly into JSON stream using JsonGenerator. SerializationContext acts as JSONB runtime, able to serialize any java object provided.

Serializers are registered using JsonbConfig.withSerializers(JsonbSerializer[]) method or using JsonbTypeSerializer annotation on type

Sample of custom Serializer:

 class Box {
     public BoxInner boxInnerObject;
     public String name;
 }

 class BoxSerializer implements JsonbSerializer<Box> {
      public void serialize(Box box, JsonGenerator generator, SerializationContext ctx) {
          generator.write("name", box.name);
          ctx.serialize("boxInnerObject", generator);
      }
 }
 
Since:
JSON Binding 1.0
See Also: