Java Code Examples for com.fasterxml.jackson.databind.DeserializationContext#findContextualValueDeserializer()

The following examples show how to use com.fasterxml.jackson.databind.DeserializationContext#findContextualValueDeserializer() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TypeDeserializerBase.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
protected final JsonDeserializer<Object> _findDefaultImplDeserializer(DeserializationContext ctxt) throws IOException
{
    /* 06-Feb-2013, tatu: As per [databind#148], consider default implementation value of
     *   {@link java.lang.Void} to mean "serialize as null"; as well as DeserializationFeature
     *   to do swift mapping to null
     */
    if (_defaultImpl == null) {
        if (!ctxt.isEnabled(DeserializationFeature.FAIL_ON_INVALID_SUBTYPE)) {
            return NullifyingDeserializer.instance;
        }
        return null;
    }
    Class<?> raw = _defaultImpl.getRawClass();
    if (ClassUtil.isBogusClass(raw)) {
        return NullifyingDeserializer.instance;
    }
    
    synchronized (_defaultImpl) {
        if (_defaultImplDeserializer == null) {
            _defaultImplDeserializer = ctxt.findContextualValueDeserializer(
                    _defaultImpl, _property);
        }
        return _defaultImplDeserializer;
    }
}
 
Example 2
Source File: RefValueHandler.java    From jackson-datatypes-collections with Apache License 2.0 6 votes vote down vote up
@Override
public RefValueHandler createContextualValue(DeserializationContext ctxt, BeanProperty property)
        throws JsonMappingException {
    JsonDeserializer<?> deser;
    if (_valueDeserializer == null) {
        deser = ctxt.findContextualValueDeserializer(_valueType, property);
    } else {
        deser = _valueDeserializer;
    }
    TypeDeserializer typeDeser = _typeDeserializerForValue == null ?
            ctxt.findTypeDeserializer(_valueType) : _typeDeserializerForValue;
    if (typeDeser != null) {
        typeDeser = typeDeser.forProperty(property);
    }
    //noinspection ObjectEquality
    if (deser == _valueDeserializer && typeDeser == _typeDeserializerForValue) {
        return this;
    }
    return new RefValueHandler(_valueType, deser, typeDeser);
}
 
Example 3
Source File: BaseCollectionDeserializer.java    From jackson-datatypes-collections with Apache License 2.0 6 votes vote down vote up
@Override
public JsonDeserializer<?> createContextual(DeserializationContext ctxt, BeanProperty property)
        throws JsonMappingException {
    JsonDeserializer<?> deser = _valueDeserializer;
    TypeDeserializer typeDeser = _typeDeserializerForValue;
    if (deser == null) {
        deser = ctxt.findContextualValueDeserializer(_elementType, property);
    }
    if (typeDeser != null) {
        typeDeser = typeDeser.forProperty(property);
    }
    if (deser == _valueDeserializer && typeDeser == _typeDeserializerForValue) {
        return this;
    }
    return withResolved(typeDeser, deser);
}
 
Example 4
Source File: ProtobufDeserializer.java    From jackson-datatype-protobuf with Apache License 2.0 6 votes vote down vote up
private JsonDeserializer<Object> getMessageDeserializer(
        Message.Builder builder,
        FieldDescriptor field,
        Message defaultInstance,
        DeserializationContext context
) throws IOException {
  JsonDeserializer<Object> deserializer = deserializerCache.get(field);
  if (deserializer == null) {
    final Class<?> subType;
    if (defaultInstance == null) {
      Message.Builder subBuilder = builder.newBuilderForField(field);
      subType = subBuilder.getDefaultInstanceForType().getClass();
    } else {
      subType = defaultInstance.getClass();
    }

    JavaType type = context.constructType(subType);
    deserializer = context.findContextualValueDeserializer(type, null);
    deserializerCache.put(field, deserializer);
  }

  return deserializer;
}
 
Example 5
Source File: IterableXDeserializer.java    From cyclops with Apache License 2.0 5 votes vote down vote up
@Override
public JsonDeserializer<?> createContextual(DeserializationContext ctxt,
                                            BeanProperty property) throws JsonMappingException
{
    JsonDeserializer<?> deser = this.valueDeserializer;
    TypeDeserializer typeDeser = this.typeDeserializerForValue;
    if (deser == null) {
        deser = ctxt.findContextualValueDeserializer(type.getContentType(), property);
    }
    if (typeDeser != null) {
        typeDeser = typeDeser.forProperty(property);
    }

    return new IterableXDeserializer(elementType,itX,typeDeser, deser,type);
}
 
Example 6
Source File: TypeDeserializerBase.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
protected final JsonDeserializer<Object> _findDeserializer(DeserializationContext ctxt,
        String typeId) throws IOException
{
    JsonDeserializer<Object> deser = _deserializers.get(typeId);
    if (deser == null) {
        /* As per [databind#305], need to provide contextual info. But for
         * backwards compatibility, let's start by only supporting this
         * for base class, not via interface. Later on we can add this
         * to the interface, assuming deprecation at base class helps.
         */
        JavaType type = _idResolver.typeFromId(ctxt, typeId);
        if (type == null) {
            // use the default impl if no type id available:
            deser = _findDefaultImplDeserializer(ctxt);
            if (deser == null) {
                // 10-May-2016, tatu: We may get some help...
                JavaType actual = _handleUnknownTypeId(ctxt, typeId);
                if (actual == null) { // what should this be taken to mean?
                    // TODO: try to figure out something better
                    return null;
                }
                // ... would this actually work?
                deser = ctxt.findContextualValueDeserializer(actual, _property);
            }
        } else {
            /* 16-Dec-2010, tatu: Since nominal type we get here has no (generic) type parameters,
             *   we actually now need to explicitly narrow from base type (which may have parameterization)
             *   using raw type.
             *
             *   One complication, though; cannot change 'type class' (simple type to container); otherwise
             *   we may try to narrow a SimpleType (Object.class) into MapType (Map.class), losing actual
             *   type in process (getting SimpleType of Map.class which will not work as expected)
             */
            if ((_baseType != null)
                    && _baseType.getClass() == type.getClass()) {
                /* 09-Aug-2015, tatu: Not sure if the second part of the check makes sense;
                 *   but it appears to check that JavaType impl class is the same which is
                 *   important for some reason?
                 *   Disabling the check will break 2 Enum-related tests.
                 */
                // 19-Jun-2016, tatu: As per [databind#1270] we may actually get full
                //   generic type with custom type resolvers. If so, should try to retain them.
                //  Whether this is sufficient to avoid problems remains to be seen, but for
                //  now it should improve things.
                if (!type.hasGenericTypes()) {
                    type = ctxt.getTypeFactory().constructSpecializedType(_baseType, type.getRawClass());
                }
            }
            deser = ctxt.findContextualValueDeserializer(type, _property);
        }
        _deserializers.put(typeId, deser);
    }
    return deser;
}
 
Example 7
Source File: ArrayToStringDeserializer.java    From clickhouse-jdbc with Apache License 2.0 4 votes vote down vote up
@Override
public JsonDeserializer<Object> load(DeserializationContext ctxt) throws Exception {
    return  ctxt.findContextualValueDeserializer(TypeFactory.defaultInstance()
            .constructType(new TypeReference<List<Object>>() {
            }), null);
}
 
Example 8
Source File: EitherDeserializer.java    From vavr-jackson with Apache License 2.0 4 votes vote down vote up
@Override
public void resolve(DeserializationContext ctxt) throws JsonMappingException {
    super.resolve(ctxt);
    stringDeserializer = ctxt.findContextualValueDeserializer(ctxt.constructType(String.class), null);
}
 
Example 9
Source File: CharSeqDeserializer.java    From vavr-jackson with Apache License 2.0 4 votes vote down vote up
@Override
public void resolve(DeserializationContext ctxt) throws JsonMappingException {
    deserializer = ctxt.findContextualValueDeserializer(TypeFactory.unknownType(), null);
}