Example usage for com.fasterxml.jackson.databind.jsontype TypeDeserializer forProperty

List of usage examples for com.fasterxml.jackson.databind.jsontype TypeDeserializer forProperty

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind.jsontype TypeDeserializer forProperty.

Prototype

public abstract TypeDeserializer forProperty(BeanProperty paramBeanProperty);

Source Link

Usage

From source file:org.javafunk.funk.jackson.monad.OptionDeserializer.java

/**
 * Method called to finalize setup of this deserializer, after deserializer itself has been registered. This is
 * needed to handle recursive and transitive dependencies.
 *///w  w w . j  av a  2  s  .  c o  m
@Override
public JsonDeserializer<?> createContextual(final DeserializationContext context, final BeanProperty property)
        throws JsonMappingException {
    Option<JsonDeserializer<?>> contextualValueHandler = valueHandler
            .or(new Callable<Option<? extends JsonDeserializer<?>>>() {
                @Override
                public Option<? extends JsonDeserializer<?>> call() throws Exception {
                    return option(context.findContextualValueDeserializer(referenceType, property));
                }
            });

    Option<TypeDeserializer> contextualTypeHandler = typeHandler
            .flatMap(new UnaryFunction<TypeDeserializer, Option<? extends TypeDeserializer>>() {
                @Override
                public Option<? extends TypeDeserializer> call(TypeDeserializer typeDeserializer) {
                    return option(typeDeserializer.forProperty(property));
                }
            });

    if (contextualValueHandler.equals(valueHandler) && contextualTypeHandler.equals(typeHandler)) {
        return this;
    }

    return new OptionDeserializer(referenceType, contextualTypeHandler, contextualValueHandler);
}