- Type Parameters:
T- the type this serializer handles
- All Superinterfaces:
JsonComponent<T>
- All Known Subinterfaces:
JsonConverter<T>
Interface for serializing Java objects to JSON.
Implementations of this interface handle the conversion of Java objects
of type T into their JSON representation using a JsonGenerator.
Custom serializers can be registered to provide specialized serialization
logic for specific types.
-
Method Summary
Modifier and TypeMethodDescriptiondefault booleanChecks if this serializer can be used for serializing map keys.voidserialize(JsonGenerator generator, T instance, boolean writeNulls) Serializes the given instance to JSON using the provided generator.default StringserializeAsMapKey(T instance) Serializes the given instance as a map key string.default voidserializeNull(JsonGenerator generator) Serializes a null value.Methods inherited from interface io.helidon.json.binding.JsonComponent
configure, type
-
Method Details
-
serialize
Serializes the given instance to JSON using the provided generator.- Parameters:
generator- the JSON generator to write toinstance- the object instance to serializewriteNulls- whether to write null values or skip them
-
serializeNull
Serializes a null value.This method is called when a null value needs to be serialized. The default implementation writes a JSON null value.
- Parameters:
generator- the JSON generator to write to
-
isMapKeySerializer
default boolean isMapKeySerializer()Checks if this serializer can be used for serializing map keys.Some types may be suitable for use as map keys in JSON objects. The default implementation returns false.
MethodserializeAsMapKey(Object)should be implemented if this method should ever return true.- Returns:
- true if this serializer can handle map key serialization, false otherwise
-
serializeAsMapKey
Serializes the given instance as a map key string.This method should only be called if
isMapKeySerializer()returns true. The default implementation throws an exception indicating the type is not supported.- Parameters:
instance- the object instance to serialize as a map key- Returns:
- the string representation suitable for use as a JSON object key
- Throws:
JsonException- if the type is not supported for map key serialization
-