com.fasterxml.jackson.databind.deser.Deserializers Java Examples

The following examples show how to use com.fasterxml.jackson.databind.deser.Deserializers. 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: ProtobufMessageObjectMapperTest.java    From titus-control-plane with Apache License 2.0 6 votes vote down vote up
private ObjectMapper getObjectMapper() {
    ObjectMapper mapper = new ObjectMapper();

    // Serialization
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);

    // Deserialization
    mapper.disable(SerializationFeature.INDENT_OUTPUT);

    SimpleDeserializers simpleDeserializers = new SimpleDeserializers();
    simpleDeserializers.addDeserializer(String.class, new TrimmingStringDeserializer());

    List<Deserializers> deserializersList = Arrays.asList(
            new AssignableFromDeserializers(Message.class, new ProtobufMessageDeserializer()),
            simpleDeserializers
    );
    CompositeDeserializers compositeDeserializers = new CompositeDeserializers(deserializersList);
    CustomDeserializerSimpleModule module = new CustomDeserializerSimpleModule(compositeDeserializers);
    module.addSerializer(Message.class, new ProtobufMessageSerializer());
    mapper.registerModule(module);

    return mapper;
}
 
Example #2
Source File: CommonObjectMappers.java    From titus-control-plane with Apache License 2.0 6 votes vote down vote up
private static ObjectMapper createProtobufMapper() {
    ObjectMapper mapper = new ObjectMapper();

    // Serialization
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);

    // Deserialization
    mapper.disable(SerializationFeature.INDENT_OUTPUT);

    SimpleDeserializers simpleDeserializers = new SimpleDeserializers();
    simpleDeserializers.addDeserializer(String.class, new TrimmingStringDeserializer());

    List<Deserializers> deserializersList = Arrays.asList(
            new AssignableFromDeserializers(Message.class, new ProtobufMessageDeserializer()),
            simpleDeserializers
    );
    CompositeDeserializers compositeDeserializers = new CompositeDeserializers(deserializersList);
    CustomDeserializerSimpleModule module = new CustomDeserializerSimpleModule(compositeDeserializers);
    module.addSerializer(Message.class, new ProtobufMessageSerializer());
    mapper.registerModule(module);

    return mapper;
}
 
Example #3
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 #4
Source File: Jackson2ObjectMapperBuilderTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void deserializerByType() throws JsonMappingException {
	JsonDeserializer<Date> deserializer = new DateDeserializers.DateDeserializer();
	ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json()
			.modules(new ArrayList<>())  // Disable well-known modules detection
			.deserializerByType(Date.class, deserializer).build();
	assertTrue(getDeserializerFactoryConfig(objectMapper).hasDeserializers());
	Deserializers deserializers = getDeserializerFactoryConfig(objectMapper).deserializers().iterator().next();
	assertSame(deserializer, deserializers.findBeanDeserializer(SimpleType.construct(Date.class), null, null));
}
 
Example #5
Source File: CompositeDeserializers.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
@Override
public JsonDeserializer<?> findMapLikeDeserializer(MapLikeType type, DeserializationConfig config, BeanDescription beanDesc,
                                                   KeyDeserializer keyDeserializer, TypeDeserializer elementTypeDeserializer,
                                                   JsonDeserializer<?> elementDeserializer) throws JsonMappingException {
    for (Deserializers deserializers : deserializersList) {
        JsonDeserializer<?> deserializer = deserializers.findMapLikeDeserializer(type, config, beanDesc, keyDeserializer, elementTypeDeserializer, elementDeserializer);
        if (deserializer != null) {
            return deserializer;
        }
    }
    return null;
}
 
Example #6
Source File: CompositeDeserializers.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
@Override
public JsonDeserializer<?> findMapDeserializer(MapType type, DeserializationConfig config, BeanDescription beanDesc,
                                               KeyDeserializer keyDeserializer, TypeDeserializer elementTypeDeserializer,
                                               JsonDeserializer<?> elementDeserializer) throws JsonMappingException {
    for (Deserializers deserializers : deserializersList) {
        JsonDeserializer<?> deserializer = deserializers.findMapDeserializer(type, config, beanDesc, keyDeserializer, elementTypeDeserializer, elementDeserializer);
        if (deserializer != null) {
            return deserializer;
        }
    }
    return null;
}
 
Example #7
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 #8
Source File: CompositeDeserializers.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
@Override
public JsonDeserializer<?> findCollectionDeserializer(CollectionType type, DeserializationConfig config, BeanDescription beanDesc,
                                                      TypeDeserializer elementTypeDeserializer, JsonDeserializer<?> elementDeserializer)
        throws JsonMappingException {
    for (Deserializers deserializers : deserializersList) {
        JsonDeserializer<?> deserializer = deserializers.findCollectionDeserializer(type, config, beanDesc, elementTypeDeserializer, elementDeserializer);
        if (deserializer != null) {
            return deserializer;
        }
    }
    return null;
}
 
Example #9
Source File: CompositeDeserializers.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
@Override
public JsonDeserializer<?> findArrayDeserializer(ArrayType type, DeserializationConfig config, BeanDescription beanDesc,
                                                 TypeDeserializer elementTypeDeserializer, JsonDeserializer<?> elementDeserializer)
        throws JsonMappingException {
    for (Deserializers deserializers : deserializersList) {
        JsonDeserializer<?> deserializer = deserializers.findArrayDeserializer(type, config, beanDesc, elementTypeDeserializer, elementDeserializer);
        if (deserializer != null) {
            return deserializer;
        }
    }
    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<?> findBeanDeserializer(JavaType type, DeserializationConfig config, BeanDescription beanDesc)
        throws JsonMappingException {
    for (Deserializers deserializers : deserializersList) {
        JsonDeserializer<?> deserializer = deserializers.findBeanDeserializer(type, config, beanDesc);
        if (deserializer != null) {
            return deserializer;
        }
    }
    return null;
}
 
Example #11
Source File: ObjectMapperFactoryV2.java    From aws-athena-query-federation with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public JsonDeserializer<Object> createBeanDeserializer(DeserializationContext ctxt, JavaType type, BeanDescription beanDesc)
        throws JsonMappingException
{
    for (Deserializers d  : _factoryConfig.deserializers()) {
        JsonDeserializer<?> deser = d.findBeanDeserializer(type, ctxt.getConfig(), beanDesc);
        if (deser != null) {
            return (JsonDeserializer<Object>) deser;
        }
    }
    throw new IllegalArgumentException("No explicitly configured deserializer for " + type);
}
 
Example #12
Source File: CompositeDeserializers.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
@Override
public JsonDeserializer<?> findTreeNodeDeserializer(Class<? extends JsonNode> nodeType, DeserializationConfig config,
                                                    BeanDescription beanDesc) throws JsonMappingException {
    for (Deserializers deserializers : deserializersList) {
        JsonDeserializer<?> deserializer = deserializers.findTreeNodeDeserializer(nodeType, config, beanDesc);
        if (deserializer != null) {
            return deserializer;
        }
    }
    return null;
}
 
Example #13
Source File: CompositeDeserializers.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
@Override
public JsonDeserializer<?> findEnumDeserializer(Class<?> type, DeserializationConfig config, BeanDescription beanDesc)
        throws JsonMappingException {
    for (Deserializers deserializers : deserializersList) {
        JsonDeserializer<?> deserializer = deserializers.findEnumDeserializer(type, config, beanDesc);
        if (deserializer != null) {
            return deserializer;
        }
    }
    return null;
}
 
Example #14
Source File: OptionalHandlerFactory.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public JsonDeserializer<?> findDeserializer(JavaType type, DeserializationConfig config,
        BeanDescription beanDesc)
    throws JsonMappingException
{
    final Class<?> rawType = type.getRawClass();

    if (_jdk7Helper != null) {
        JsonDeserializer<?> deser = _jdk7Helper.getDeserializerForJavaNioFilePath(rawType);
        if (deser != null) {
            return deser;
        }
    }
    if ((CLASS_DOM_NODE != null) && CLASS_DOM_NODE.isAssignableFrom(rawType)) {
        return (JsonDeserializer<?>) instantiate(DESERIALIZER_FOR_DOM_NODE);
    }
    if ((CLASS_DOM_DOCUMENT != null) && CLASS_DOM_DOCUMENT.isAssignableFrom(rawType)) {
        return (JsonDeserializer<?>) instantiate(DESERIALIZER_FOR_DOM_DOCUMENT);
    }
    String className = rawType.getName();
    String factoryName;
    if (className.startsWith(PACKAGE_PREFIX_JAVAX_XML)
            || hasSuperClassStartingWith(rawType, PACKAGE_PREFIX_JAVAX_XML)) {
        factoryName = DESERIALIZERS_FOR_JAVAX_XML;
    } else {
        return null;
    }
    Object ob = instantiate(factoryName);
    if (ob == null) { // could warn, if we had logging system (j.u.l?)
        return null;
    }
    return ((Deserializers) ob).findBeanDeserializer(type, config, beanDesc);
}
 
Example #15
Source File: Jackson2ObjectMapperBuilderTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void deserializerByType() throws JsonMappingException {
	JsonDeserializer<Date> deserializer = new DateDeserializers.DateDeserializer();
	ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json()
			.modules(new ArrayList<>())  // Disable well-known modules detection
			.deserializerByType(Date.class, deserializer)
			.build();
	assertTrue(getDeserializerFactoryConfig(objectMapper).hasDeserializers());
	Deserializers deserializers = getDeserializerFactoryConfig(objectMapper).deserializers().iterator().next();
	assertSame(deserializer, deserializers.findBeanDeserializer(SimpleType.construct(Date.class), null, null));
}
 
Example #16
Source File: Jackson2ObjectMapperBuilderTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void deserializerByType() throws JsonMappingException {
	JsonDeserializer<Date> deserializer = new DateDeserializers.DateDeserializer();
	ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json()
			.modules(new ArrayList<>())  // Disable well-known modules detection
			.deserializerByType(Date.class, deserializer)
			.build();
	assertTrue(getDeserializerFactoryConfig(objectMapper).hasDeserializers());
	Deserializers deserializers = getDeserializerFactoryConfig(objectMapper).deserializers().iterator().next();
	assertSame(deserializer, deserializers.findBeanDeserializer(SimpleType.construct(Date.class), null, null));
}
 
Example #17
Source File: CompositeDeserializers.java    From titus-control-plane with Apache License 2.0 4 votes vote down vote up
public CompositeDeserializers(List<Deserializers> deserializers) {
    this.deserializersList = deserializers;
}
 
Example #18
Source File: CustomDeserializerSimpleModule.java    From titus-control-plane with Apache License 2.0 4 votes vote down vote up
public CustomDeserializerSimpleModule(Deserializers deserializers) {
    this.deserializers = deserializers;
}
 
Example #19
Source File: Module.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Method that module can use to register additional deserializers to use for
 * handling types.
 * 
 * @param d Object that can be called to find deserializer for types supported
 *   by module (null returned for non-supported types)
 */
public void addDeserializers(Deserializers d);