com.fasterxml.jackson.databind.type.ReferenceType Java Examples

The following examples show how to use com.fasterxml.jackson.databind.type.ReferenceType. 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: BeanSerializerFactory.java    From bistoury with GNU General Public License v3.0 6 votes vote down vote up
/**
 * @since 2.7
 */
public JsonSerializer<?> findReferenceSerializer(SerializerProvider prov, ReferenceType refType,
                                                 BeanDescription beanDesc, boolean staticTyping)
        throws JsonMappingException
{
    JavaType contentType = refType.getContentType();
    TypeSerializer contentTypeSerializer = contentType.getTypeHandler();
    final SerializationConfig config = prov.getConfig();
    if (contentTypeSerializer == null) {
        contentTypeSerializer = createTypeSerializer(config, contentType);
    }
    JsonSerializer<Object> contentSerializer = contentType.getValueHandler();
    for (Serializers serializers : customSerializers()) {
        JsonSerializer<?> ser = serializers.findReferenceSerializer(config, refType, beanDesc,
                contentTypeSerializer, contentSerializer);
        if (ser != null) {
            return ser;
        }
    }
    if (refType.isTypeOrSubTypeOf(AtomicReference.class)) {
        return new AtomicReferenceSerializer(refType, staticTyping,
                contentTypeSerializer, contentSerializer);
    }
    return null;
}
 
Example #2
Source File: UnknownPluginHandler.java    From milkman with MIT License 6 votes vote down vote up
@Override
public JavaType handleUnknownTypeId(DeserializationContext ctxt, JavaType baseType, String subTypeId,
		TypeIdResolver idResolver, String failureMsg) throws IOException {
	if (baseType.hasRawClass(RequestAspect.class)) {
		log.error("Unknown AspectType found: " + subTypeId + ".");
		return ReferenceType.construct(UnknownRequestAspect.class);
	}
	if (baseType.hasRawClass(OptionsObject.class)) {
		log.error("Unknown OptionsObject found: " + subTypeId + ".");
		return ReferenceType.construct(UnknownOptionsObject.class);
	}
	if (baseType.hasRawClass(RequestContainer.class)) {
		log.error("Unknown RequestContainer found: " + subTypeId + ".");
		return ReferenceType.construct(UnknownRequestContainer.class);
	}
	return null;
}
 
Example #3
Source File: VavrDeserializers.java    From vavr-jackson with Apache License 2.0 5 votes vote down vote up
@Override
public JsonDeserializer<?> findReferenceDeserializer(ReferenceType type,
                                                     DeserializationConfig config, BeanDescription beanDesc,
                                                     TypeDeserializer contentTypeDeserializer, JsonDeserializer<?> contentDeserializer)
        throws JsonMappingException {
    Class<?> raw = type.getRawClass();
    if (raw == Lazy.class) {
        return new LazyDeserializer(type, type.getContentType(), contentTypeDeserializer, contentDeserializer);
    }
    if (raw == Option.class) {
        return new OptionDeserializer(type, type.getContentType(), contentTypeDeserializer, contentDeserializer, settings.useOptionInPlainFormat());
    }
    return super.findReferenceDeserializer(type, config, beanDesc, contentTypeDeserializer, contentDeserializer);
}
 
Example #4
Source File: VavrSerializers.java    From vavr-jackson with Apache License 2.0 5 votes vote down vote up
@Override
public JsonSerializer<?> findReferenceSerializer(SerializationConfig config,
                                                 ReferenceType type, BeanDescription beanDesc,
                                                 TypeSerializer contentTypeSerializer, JsonSerializer<Object> contentValueSerializer) {
    Class<?> raw = type.getRawClass();
    if (Lazy.class.isAssignableFrom(raw)) {
        return new LazySerializer(type, type.getContentType(), contentTypeSerializer, contentValueSerializer);
    }
    if (Option.class.isAssignableFrom(raw)) {
        return new OptionSerializer(type, type.getContentType(), contentTypeSerializer, contentValueSerializer, settings.useOptionInPlainFormat());
    }
    return super.findReferenceSerializer(config, type, beanDesc, contentTypeSerializer, contentValueSerializer);
}
 
Example #5
Source File: CyclopsSerializers.java    From cyclops with Apache License 2.0 5 votes vote down vote up
@Override
public JsonSerializer<?> findReferenceSerializer(SerializationConfig config, ReferenceType type, BeanDescription beanDesc, TypeSerializer contentTypeSerializer, JsonSerializer<Object> contentValueSerializer) {
  if (Option.class.isAssignableFrom(type.getRawClass())) {
    return new OptionSerializer(type,true,contentTypeSerializer,contentValueSerializer);
  }
  if (Eval.class.isAssignableFrom(type.getRawClass())) {
    return new EvalSerializer(type,true,contentTypeSerializer,contentValueSerializer);
  }
  if (Trampoline.class.isAssignableFrom(type.getRawClass())) {
    return new TrampolineSerializer(type,true,contentTypeSerializer,contentValueSerializer);
  }
  if (Ior.class.isAssignableFrom(type.getRawClass())) {
    return new IorSerializer();
  }
  if (Sealed2.class.isAssignableFrom(type.getRawClass())) {
    return new Sealed2Serializer();
  }
  if (Sealed3.class.isAssignableFrom(type.getRawClass())) {
    return new Sealed3Serializer();
  }
  if (Sealed4.class.isAssignableFrom(type.getRawClass())) {
    return new Sealed4Serializer();
  }
  if (Sealed5.class.isAssignableFrom(type.getRawClass())) {
    return new Sealed5Serializer();
  }
  if (Value.class.isAssignableFrom(type.getRawClass())) {
    return new ValueSerializer(type,true,contentTypeSerializer,contentValueSerializer);
  }

  return super.findReferenceSerializer(config, type, beanDesc, contentTypeSerializer, contentValueSerializer);
}
 
Example #6
Source File: CyclopsTypeModifier.java    From cyclops with Apache License 2.0 5 votes vote down vote up
@Override
public JavaType modifyType(JavaType type, Type jdkType, TypeBindings bindings, TypeFactory typeFactory) {

    if (type.isReferenceType() || type.isContainerType()) {
        return type;
    }
    final Class<?> raw = type.getRawClass();
    if (raw == Option.class)
        return ReferenceType.upgradeFrom(type, type.containedTypeOrUnknown(0));

    if (raw == Eval.class)
        return ReferenceType.upgradeFrom(type, type.containedTypeOrUnknown(0));
    if (raw == Trampoline.class)
        return ReferenceType.upgradeFrom(type, type.containedTypeOrUnknown(0));
    if (raw == Either.class)
        return ReferenceType.upgradeFrom(type, type.containedTypeOrUnknown(0));

    if (raw == Value.class)
        return ReferenceType.upgradeFrom(type, type.containedTypeOrUnknown(0));

    for(Class c : collectionLikeTypes){
        if (c.isAssignableFrom(raw)) {
            //   return CollectionType.upgradeFrom(type, type.containedTypeOrUnknown(0));
            return CollectionLikeType.upgradeFrom(type, type.containedTypeOrUnknown(0));
        }
    }



    return type;
}
 
Example #7
Source File: CyclopsDeserializers.java    From cyclops with Apache License 2.0 5 votes vote down vote up
@Override
public JsonDeserializer<?> findReferenceDeserializer(ReferenceType type,
                                                     DeserializationConfig config, BeanDescription bean,
                                                     TypeDeserializer typeDeserializer, JsonDeserializer<?> jsonDeserializer) throws JsonMappingException {

  return super.findReferenceDeserializer(type, config, bean, typeDeserializer, jsonDeserializer);
}
 
Example #8
Source File: GuavaDeserializers.java    From jackson-datatypes-collections with Apache License 2.0 5 votes vote down vote up
@Override // since 2.7
    public JsonDeserializer<?> findReferenceDeserializer(ReferenceType refType,
            DeserializationConfig config, BeanDescription beanDesc,
            TypeDeserializer contentTypeDeserializer, JsonDeserializer<?> contentDeserializer)
    {
        // 28-Oct-2016, tatu: Should try to support subtypes too, with ValueInstantiators, but
        //   not 100% clear how this could work at this point
//        if (refType.isTypeOrSubTypeOf(Optional.class)) {
        if (refType.hasRawClass(Optional.class)) {
            return new GuavaOptionalDeserializer(refType, null, contentTypeDeserializer, contentDeserializer);
        }
        return null;
    }
 
Example #9
Source File: GuavaSerializers.java    From jackson-datatypes-collections with Apache License 2.0 5 votes vote down vote up
@Override
public JsonSerializer<?> findReferenceSerializer(SerializationConfig config, 
        ReferenceType refType, BeanDescription beanDesc, JsonFormat.Value formatOverrides,
        TypeSerializer contentTypeSerializer, JsonSerializer<Object> contentValueSerializer)
{
    final Class<?> raw = refType.getRawClass();
    if (Optional.class.isAssignableFrom(raw)) {
        boolean staticTyping = (contentTypeSerializer == null)
                && config.isEnabled(MapperFeature.USE_STATIC_TYPING);
        return new GuavaOptionalSerializer(refType, staticTyping,
                contentTypeSerializer, contentValueSerializer);
    }
    return null;
}
 
Example #10
Source File: CompositeDeserializers.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
@Override
public JsonDeserializer<?> findReferenceDeserializer(ReferenceType refType, DeserializationConfig config,
                                                     BeanDescription beanDesc, TypeDeserializer contentTypeDeserializer,
                                                     JsonDeserializer<?> contentDeserializer) throws JsonMappingException {
    for (Deserializers deserializers : deserializersList) {
        JsonDeserializer<?> deserializer = deserializers.findReferenceDeserializer(refType, config, beanDesc, contentTypeDeserializer, contentDeserializer);
        if (deserializer != null) {
            return deserializer;
        }
    }
    return null;
}
 
Example #11
Source File: ReferenceTypeSerializer.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public ReferenceTypeSerializer(ReferenceType fullType, boolean staticTyping,
        TypeSerializer vts, JsonSerializer<Object> ser)
{
    super(fullType);
    _referredType = fullType.getReferencedType();
    _property = null;
    _valueTypeSerializer = vts;
    _valueSerializer = ser;
    _unwrapper = null;
    _suppressableValue = null;
    _suppressNulls = false;
    _dynamicSerializers = PropertySerializerMap.emptyForProperties();
}
 
Example #12
Source File: GuavaOptionalSerializer.java    From jackson-datatypes-collections with Apache License 2.0 4 votes vote down vote up
public GuavaOptionalSerializer(ReferenceType fullType, boolean staticTyping,
        TypeSerializer vts, JsonSerializer<Object> ser)
{
    super(fullType, staticTyping, vts, ser);
}
 
Example #13
Source File: AssignableFromDeserializers.java    From titus-control-plane with Apache License 2.0 4 votes vote down vote up
@Override
public JsonDeserializer<?> findReferenceDeserializer(ReferenceType refType, DeserializationConfig config, BeanDescription beanDesc,
                                                     TypeDeserializer contentTypeDeserializer, JsonDeserializer<?> contentDeserializer)
        throws JsonMappingException {
    return getDeserializer(refType.getRawClass());
}
 
Example #14
Source File: ConvertingDeserializers.java    From graphql-spqr with Apache License 2.0 4 votes vote down vote up
@Override
public JsonDeserializer<?> findReferenceDeserializer(ReferenceType refType, DeserializationConfig config, BeanDescription beanDesc, TypeDeserializer contentTypeDeserializer, JsonDeserializer<?> contentDeserializer) {
    return forJavaType(refType);
}
 
Example #15
Source File: BeanDeserializerModifier.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @since 2.7
 */
public JsonDeserializer<?> modifyReferenceDeserializer(DeserializationConfig config,
        ReferenceType type, BeanDescription beanDesc, JsonDeserializer<?> deserializer) {
    return deserializer;
}
 
Example #16
Source File: BeanSerializerFactory.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
protected JsonSerializer<?> _createSerializer2(SerializerProvider prov,
        JavaType type, BeanDescription beanDesc, boolean staticTyping)
    throws JsonMappingException
{
    JsonSerializer<?> ser = null;
    final SerializationConfig config = prov.getConfig();
    
    // Container types differ from non-container types
    // (note: called method checks for module-provided serializers)
    if (type.isContainerType()) {
        if (!staticTyping) {
            staticTyping = usesStaticTyping(config, beanDesc, null);
        }
        // 03-Aug-2012, tatu: As per [databind#40], may require POJO serializer...
        ser =  buildContainerSerializer(prov, type, beanDesc, staticTyping);
        // Will return right away, since called method does post-processing:
        if (ser != null) {
            return ser;
        }
    } else {
        if (type.isReferenceType()) {
            ser = findReferenceSerializer(prov, (ReferenceType) type, beanDesc, staticTyping);
        } else {
            // Modules may provide serializers of POJO types:
            for (Serializers serializers : customSerializers()) {
                ser = serializers.findSerializer(config, type, beanDesc);
                if (ser != null) {
                    break;
                }
            }
        }
        // 25-Jun-2015, tatu: Then JsonSerializable, @JsonValue etc. NOTE! Prior to 2.6,
        //    this call was BEFORE custom serializer lookup, which was wrong.
        if (ser == null) {
            ser = findSerializerByAnnotations(prov, type, beanDesc);
        }
    }
    
    if (ser == null) {
        // Otherwise, we will check "primary types"; both marker types that
        // indicate specific handling (JsonSerializable), or main types that have
        // precedence over container types
        ser = findSerializerByLookup(type, config, beanDesc, staticTyping);
        if (ser == null) {
            ser = findSerializerByPrimaryType(prov, type, beanDesc, staticTyping);
            if (ser == null) {
                // And this is where this class comes in: if type is not a
                // known "primary JDK type", perhaps it's a bean? We can still
                // get a null, if we can't find a single suitable bean property.
                ser = findBeanSerializer(prov, type, beanDesc);
                // Finally: maybe we can still deal with it as an implementation of some basic JDK interface?
                if (ser == null) {
                    ser = findSerializerByAddonType(config, type, beanDesc, staticTyping);
                    // 18-Sep-2014, tatu: Actually, as per [jackson-databind#539], need to get
                    //   'unknown' serializer assigned earlier, here, so that it gets properly
                    //   post-processed
                    if (ser == null) {
                        ser = prov.getUnknownTypeSerializer(beanDesc.getBeanClass());
                    }
                }
            }
        }
    }
    if (ser != null) {
        // [databind#120]: Allow post-processing
        if (_factoryConfig.hasSerializerModifiers()) {
            for (BeanSerializerModifier mod : _factoryConfig.serializerModifiers()) {
                ser = mod.modifySerializer(config, beanDesc, ser);
            }
        }
    }
    return ser;
}
 
Example #17
Source File: OptionSerializer.java    From cyclops with Apache License 2.0 4 votes vote down vote up
protected OptionSerializer(ReferenceType fullType, boolean staticTyping,
                             TypeSerializer vts, JsonSerializer<Object> ser)
{
  super(fullType, staticTyping, vts, ser);
}
 
Example #18
Source File: TrampolineSerializer.java    From cyclops with Apache License 2.0 4 votes vote down vote up
protected TrampolineSerializer(ReferenceType fullType, boolean staticTyping,
                               TypeSerializer vts, JsonSerializer<Object> ser)
{
  super(fullType, staticTyping, vts, ser);
}
 
Example #19
Source File: ValueSerializer.java    From cyclops with Apache License 2.0 4 votes vote down vote up
protected ValueSerializer(ReferenceType fullType, boolean staticTyping,
                          TypeSerializer vts, JsonSerializer<Object> ser)
{
  super(fullType, staticTyping, vts, ser);
}
 
Example #20
Source File: EvalSerializer.java    From cyclops with Apache License 2.0 4 votes vote down vote up
protected EvalSerializer(ReferenceType fullType, boolean staticTyping,
                         TypeSerializer vts, JsonSerializer<Object> ser)
{
  super(fullType, staticTyping, vts, ser);
}
 
Example #21
Source File: AtomicReferenceSerializer.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public AtomicReferenceSerializer(ReferenceType fullType, boolean staticTyping,
        TypeSerializer vts, JsonSerializer<Object> ser)
{
    super(fullType, staticTyping, vts, ser);
}
 
Example #22
Source File: BeanSerializerFactory.java    From bistoury with GNU General Public License v3.0 4 votes vote down vote up
protected JsonSerializer<?> _createSerializer2(SerializerProvider prov,
                                               JavaType type, BeanDescription beanDesc, boolean staticTyping)
        throws JsonMappingException
{
    JsonSerializer<?> ser = null;
    final SerializationConfig config = prov.getConfig();

    // Container types differ from non-container types
    // (note: called method checks for module-provided serializers)
    if (type.isContainerType()) {
        if (!staticTyping) {
            staticTyping = usesStaticTyping(config, beanDesc, null);
        }
        // 03-Aug-2012, tatu: As per [databind#40], may require POJO serializer...
        ser =  buildContainerSerializer(prov, type, beanDesc, staticTyping);
        // Will return right away, since called method does post-processing:
        if (ser != null) {
            return ser;
        }
    } else {
        if (type.isReferenceType()) {
            ser = findReferenceSerializer(prov, (ReferenceType) type, beanDesc, staticTyping);
        } else {
            // Modules may provide serializers of POJO types:
            for (Serializers serializers : customSerializers()) {
                ser = serializers.findSerializer(config, type, beanDesc);
                if (ser != null) {
                    break;
                }
            }
        }
        // 25-Jun-2015, tatu: Then JsonSerializable, @JsonValue etc. NOTE! Prior to 2.6,
        //    this call was BEFORE custom serializer lookup, which was wrong.
        if (ser == null) {
            ser = findSerializerByAnnotations(prov, type, beanDesc);
        }
    }

    if (ser == null) {
        // Otherwise, we will check "primary types"; both marker types that
        // indicate specific handling (JsonSerializable), or main types that have
        // precedence over container types
        ser = findSerializerByLookup(type, config, beanDesc, staticTyping);
        if (ser == null) {
            ser = findSerializerByPrimaryType(prov, type, beanDesc, staticTyping);
            if (ser == null) {
                // And this is where this class comes in: if type is not a
                // known "primary JDK type", perhaps it's a bean? We can still
                // get a null, if we can't find a single suitable bean property.
                ser = findBeanSerializer(prov, type, beanDesc);
                // Finally: maybe we can still deal with it as an implementation of some basic JDK interface?
                if (ser == null) {
                    ser = findSerializerByAddonType(config, type, beanDesc, staticTyping);
                    // 18-Sep-2014, tatu: Actually, as per [jackson-databind#539], need to get
                    //   'unknown' serializer assigned earlier, here, so that it gets properly
                    //   post-processed
                    if (ser == null) {
                        ser = prov.getUnknownTypeSerializer(beanDesc.getBeanClass());
                    }
                }
            }
        }
    }
    if (ser != null) {
        // [databind#120]: Allow post-processing
        if (_factoryConfig.hasSerializerModifiers()) {
            for (BeanSerializerModifier mod : _factoryConfig.serializerModifiers()) {
                ser = mod.modifySerializer(config, beanDesc, ser);
            }
        }
    }
    return ser;
}