Interface JsonbDeserializer<T>

Type Parameters:
T - Type to bind deserializer for.

public interface JsonbDeserializer<T>

Interface representing a custom deserializer for a given type. It provides a low-level API for java object deserialization from JSON stream using JsonParser. Unlike JsonbAdapter, which acts more as converter from one java type to another, deserializer provides more fine grained control over deserialization process.

DeserializationContext acts as JSONB runtime, able to deserialize any java object provided.

Sample of custom Deserializer:

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

     BoxDeserializer implements JsonbDeserializer<Box> {
         public Box deserialize(JsonParser parser, DeserializationContext ctx, Type rtType) {
             Box = new Box();

             while (parser.hasNext()) {
                 Event event = parser.next();

                 if (event == JsonParser.Event.KEY_NAME && parser.getString().equals("boxInnerObject") {
                     // Deserialize inner object
                     box.boxInnerObject = ctx.deserialize(BoxInner.class, jsonParser);

                 } else if (event == JsonParser.Event.KEY_NAME && parser.getString().equals("name") {
                     // Deserialize name property
                     parser.next(); // move to VALUE
                     box.name = parser.getString();
                 }
             }

             return box;
         }
     }
 

Deserializers are registered using JsonbConfig.withDeserializers(JsonbDeserializer[]) method or using JsonbTypeDeserializer annotation on type.

Since:
JSON Binding 1.0
See Also: