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

The following examples show how to use com.fasterxml.jackson.databind.type.CollectionLikeType. 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: VavrDeserializers.java    From vavr-jackson with Apache License 2.0 6 votes vote down vote up
@Override
public JsonDeserializer<?> findCollectionLikeDeserializer(CollectionLikeType collectionType,
                                                          DeserializationConfig config, BeanDescription beanDesc,
                                                          TypeDeserializer elementTypeDeserializer, JsonDeserializer<?> elementDeserializer)
        throws JsonMappingException
{
    Class<?> raw = collectionType.getRawClass();
    if (raw == CharSeq.class) {
        return new CharSeqDeserializer(collectionType);
    }
    if (Seq.class.isAssignableFrom(raw)) {
        return new SeqDeserializer(collectionType, collectionType.getContentType(), elementTypeDeserializer,
                elementDeserializer, settings.deserializeNullAsEmptyCollection());
    }
    if (Set.class.isAssignableFrom(raw)) {
        return new SetDeserializer(collectionType, collectionType.getContentType(), elementTypeDeserializer,
                elementDeserializer, settings.deserializeNullAsEmptyCollection());
    }
    if (PriorityQueue.class.isAssignableFrom(raw)) {
        return new PriorityQueueDeserializer(collectionType, collectionType.getContentType(),
                elementTypeDeserializer, elementDeserializer, settings.deserializeNullAsEmptyCollection());
    }
    return super.findCollectionLikeDeserializer(collectionType, config, beanDesc, elementTypeDeserializer, elementDeserializer);
}
 
Example #2
Source File: VavrSerializers.java    From vavr-jackson with Apache License 2.0 6 votes vote down vote up
@Override
public JsonSerializer<?> findCollectionLikeSerializer(SerializationConfig config,
                                                      CollectionLikeType collectionType, BeanDescription beanDesc,
                                                      TypeSerializer elementTypeSerializer, JsonSerializer<Object> elementValueSerializer) {
    Class<?> raw = collectionType.getRawClass();
    if (raw == CharSeq.class) {
        return new CharSeqSerializer(collectionType);
    }
    if (Seq.class.isAssignableFrom(raw)) {
        return new ArraySerializer<>(collectionType);
    }
    if (Set.class.isAssignableFrom(raw)) {
        return new ArraySerializer<>(collectionType);
    }
    if (PriorityQueue.class.isAssignableFrom(raw)) {
        return new ArraySerializer<>(collectionType);
    }
    return super.findCollectionLikeSerializer(config, collectionType, beanDesc, elementTypeSerializer, elementValueSerializer);
}
 
Example #3
Source File: CompositeDeserializers.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
@Override
public JsonDeserializer<?> findCollectionLikeDeserializer(CollectionLikeType type, DeserializationConfig config,
                                                          BeanDescription beanDesc, TypeDeserializer elementTypeDeserializer,
                                                          JsonDeserializer<?> elementDeserializer) throws JsonMappingException {
    for (Deserializers deserializers : deserializersList) {
        JsonDeserializer<?> deserializer = deserializers.findCollectionLikeDeserializer(type, config, beanDesc, elementTypeDeserializer, elementDeserializer);
        if (deserializer != null) {
            return deserializer;
        }
    }
    return null;
}
 
Example #4
Source File: JaxRsRoundTripSerializationTest.java    From reladomo with Apache License 2.0 5 votes vote down vote up
protected Serialized fromSerializedString(String json) throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    mapper.registerModule(new JacksonReladomoModule());
    mapper.enable(SerializationFeature.INDENT_OUTPUT);
    CollectionLikeType customClassCollection = mapper.getTypeFactory().constructCollectionLikeType(Serialized.class, Order.class);
    return (Serialized)mapper.readValue(json, customClassCollection);
}
 
Example #5
Source File: HppcSerializers.java    From jackson-datatypes-collections with Apache License 2.0 5 votes vote down vote up
@Override
public JsonSerializer<?> findCollectionLikeSerializer(SerializationConfig config,
        CollectionLikeType containerType, BeanDescription beanDesc, JsonFormat.Value formatOverrides,
        TypeSerializer elementTypeSerializer, JsonSerializer<Object> elementValueSerializer)
{
    if (ObjectContainer.class.isAssignableFrom(containerType.getRawClass())) {
        // hmmh. not sure if we can find 'forceStaticTyping' anywhere...
        boolean staticTyping = config.isEnabled(MapperFeature.USE_STATIC_TYPING);
        ObjectArraySerializer ser = new ObjectArraySerializer(containerType.getContentType(),
                staticTyping, elementTypeSerializer, elementValueSerializer);
        return new ObjectContainerSerializer(containerType, ser);
    }
    return null;
}
 
Example #6
Source File: CyclopsSerializers.java    From cyclops with Apache License 2.0 5 votes vote down vote up
@Override
public JsonSerializer<?> findCollectionLikeSerializer(SerializationConfig config, CollectionLikeType type, BeanDescription beanDesc, TypeSerializer elementTypeSerializer, JsonSerializer<Object> elementValueSerializer) {
    if (!Collection.class.isAssignableFrom(type.getRawClass()) && IterableX.class.isAssignableFrom(type.getRawClass())) {
        return new IterableXSerializer();
    }
  return super.findCollectionLikeSerializer(config, type, beanDesc, elementTypeSerializer, elementValueSerializer);
}
 
Example #7
Source File: CyclopsDeserializers.java    From cyclops with Apache License 2.0 5 votes vote down vote up
@Override
public JsonDeserializer<?> findCollectionLikeDeserializer(CollectionLikeType type, DeserializationConfig config, BeanDescription beanDesc, TypeDeserializer elementTypeDeserializer, JsonDeserializer<?> elementDeserializer) throws JsonMappingException {
    Class<?> raw = type.getRawClass();
    if (IterableX.class.isAssignableFrom(type.getRawClass())) {
        return new IterableXDeserializer(raw,type.containedTypeOrUnknown(0).getRawClass(),elementTypeDeserializer,elementDeserializer, type);
    }
  return super.findCollectionLikeDeserializer(type, config, beanDesc, elementTypeDeserializer, elementDeserializer);
}
 
Example #8
Source File: IterableXDeserializer.java    From cyclops with Apache License 2.0 5 votes vote down vote up
public IterableXDeserializer(Class<?> vc, Class<?> elementType,TypeDeserializer typeDeserializerForValue, JsonDeserializer<?> valueDeserializer,CollectionLikeType type) {
  super(vc);
  this.itX = vc;
  this.elementType = elementType;
  this.valueDeserializer = valueDeserializer;
  this.typeDeserializerForValue = typeDeserializerForValue;
  this.type = type;
}
 
Example #9
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 #10
Source File: ConvertingDeserializers.java    From graphql-spqr with Apache License 2.0 4 votes vote down vote up
@Override
public JsonDeserializer<?> findCollectionLikeDeserializer(CollectionLikeType type, DeserializationConfig config, BeanDescription beanDesc, TypeDeserializer elementTypeDeserializer, JsonDeserializer<?> elementDeserializer) {
    return forJavaType(type);
}
 
Example #11
Source File: ArraySerializer.java    From vavr-jackson with Apache License 2.0 4 votes vote down vote up
ArraySerializer(CollectionLikeType collectionType) {
    this(collectionType, null);
}
 
Example #12
Source File: ArraySerializer.java    From vavr-jackson with Apache License 2.0 4 votes vote down vote up
ArraySerializer(CollectionLikeType collectionType, BeanProperty property) {
    super(collectionType, property);
    this.collectionType = collectionType;
}
 
Example #13
Source File: AssignableFromDeserializers.java    From titus-control-plane with Apache License 2.0 4 votes vote down vote up
@Override
public JsonDeserializer<?> findCollectionLikeDeserializer(CollectionLikeType type, DeserializationConfig config, BeanDescription beanDesc,
                                                          TypeDeserializer elementTypeDeserializer, JsonDeserializer<?> elementDeserializer)
        throws JsonMappingException {
    return getDeserializer(type.getRawClass());
}
 
Example #14
Source File: BeanDeserializerModifier.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @since 2.2
 */
public JsonDeserializer<?> modifyCollectionLikeDeserializer(DeserializationConfig config,
        CollectionLikeType type, BeanDescription beanDesc, JsonDeserializer<?> deserializer) {
    return deserializer;
}
 
Example #15
Source File: SimpleSerializers.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public JsonSerializer<?> findCollectionLikeSerializer(SerializationConfig config,
        CollectionLikeType type, BeanDescription beanDesc,
        TypeSerializer elementTypeSerializer, JsonSerializer<Object> elementValueSerializer) {
    return findSerializer(config, type, beanDesc);
}
 
Example #16
Source File: JsonUtil.java    From mica with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * 封装 map type
 *
 * @param elementClass 集合值类型
 * @return CollectionLikeType
 */
public static CollectionLikeType getListType(Class<?> elementClass) {
	return getInstance().getTypeFactory().constructCollectionLikeType(List.class, elementClass);
}
 
Example #17
Source File: ResponseSpec.java    From mica with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * jackson json path 语法读取节点
 *
 * @param jsonPtrExpr json path 表达式
 * @param valueType   value value type
 * @return List
 */
default <T> List<T> atJsonPathList(String jsonPtrExpr, Class<T> valueType) {
	CollectionLikeType collectionLikeType = JsonUtil.getListType(valueType);
	return JsonUtil.convertValue(atJsonPath(jsonPtrExpr), collectionLikeType);
}