Search in sources :

Example 1 with UpdatingDeserializer

use of io.micronaut.serde.UpdatingDeserializer in project micronaut-serialization by micronaut-projects.

the class JacksonJsonMapper method updateValueFromTree.

@Override
public void updateValueFromTree(Object value, JsonNode tree) throws IOException {
    if (tree != null && value != null) {
        Argument<Object> type = (Argument<Object>) Argument.of(value.getClass());
        Deserializer deserializer = registry.findDeserializer(type).createSpecific(decoderContext, type);
        if (deserializer instanceof UpdatingDeserializer) {
            try (JsonParser parser = treeCodec.treeAsTokens(tree)) {
                parser.setCodec(objectCodecImpl);
                if (!parser.hasCurrentToken()) {
                    parser.nextToken();
                }
                // for jackson compat we need to support deserializing null, but most deserializers don't support it.
                if (parser.currentToken() != JsonToken.VALUE_NULL) {
                    final Decoder decoder = JacksonDecoder.create(parser, view);
                    ((UpdatingDeserializer<Object>) deserializer).deserializeInto(decoder, decoderContext, type, value);
                }
            }
        }
    }
}
Also used : Argument(io.micronaut.core.type.Argument) Deserializer(io.micronaut.serde.Deserializer) UpdatingDeserializer(io.micronaut.serde.UpdatingDeserializer) UpdatingDeserializer(io.micronaut.serde.UpdatingDeserializer) Decoder(io.micronaut.serde.Decoder) JsonParser(com.fasterxml.jackson.core.JsonParser)

Aggregations

JsonParser (com.fasterxml.jackson.core.JsonParser)1 Argument (io.micronaut.core.type.Argument)1 Decoder (io.micronaut.serde.Decoder)1 Deserializer (io.micronaut.serde.Deserializer)1 UpdatingDeserializer (io.micronaut.serde.UpdatingDeserializer)1