Package jakarta.json.bind.serializer
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 usingJsonGenerator
.SerializationContext
acts as JSONB runtime, able to serialize any java object provided.Serializers are registered using
JsonbConfig.withSerializers(JsonbSerializer[])
method or usingJsonbTypeSerializer
annotation on typeSample 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:
JsonbConfig
,JsonbTypeSerializer
,JsonbDeserializer
,JsonbAdapter
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
serialize(T obj, JsonGenerator generator, SerializationContext ctx)
Serializes object into JSON stream.
-
-
-
Method Detail
-
serialize
void serialize(T obj, JsonGenerator generator, SerializationContext ctx)
Serializes object into JSON stream.- Parameters:
obj
- Object to serialize.generator
- JSON generator used to write java object to JSON stream.ctx
- JSONB mapper context. Use it to serialize sub-objects.
-
-