Search in sources :

Example 51 with JavaType

use of com.fasterxml.jackson.databind.JavaType in project Gaffer by gchq.

the class CloseableIterableDeserializer method createContextual.

@Override
public JsonDeserializer<?> createContextual(final DeserializationContext deserializationContext, final BeanProperty property) throws JsonMappingException {
    final JavaType valueType = deserializationContext.getContextualType().containedType(0);
    final CloseableIterableDeserializer deserializer = new CloseableIterableDeserializer();
    deserializer.valueType = valueType;
    return deserializer;
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType)

Example 52 with JavaType

use of com.fasterxml.jackson.databind.JavaType in project Fast-Android-Networking by amitshekhariitbhu.

the class JacksonParserFactory method responseBodyParser.

@Override
public Parser<ResponseBody, ?> responseBodyParser(Type type) {
    JavaType javaType = mapper.getTypeFactory().constructType(type);
    ObjectReader reader = mapper.readerFor(javaType);
    return new JacksonResponseBodyParser<>(reader);
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType) ObjectReader(com.fasterxml.jackson.databind.ObjectReader)

Example 53 with JavaType

use of com.fasterxml.jackson.databind.JavaType in project Fast-Android-Networking by amitshekhariitbhu.

the class JacksonParserFactory method getObject.

@Override
public Object getObject(String string, Type type) {
    try {
        JavaType javaType = mapper.getTypeFactory().constructType(type);
        ObjectReader objectReader = mapper.readerFor(javaType);
        return objectReader.readValue(string);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType) ObjectReader(com.fasterxml.jackson.databind.ObjectReader)

Example 54 with JavaType

use of com.fasterxml.jackson.databind.JavaType in project spring-framework by spring-projects.

the class AbstractJackson2HttpMessageConverter method canRead.

@Override
public boolean canRead(Type type, Class<?> contextClass, MediaType mediaType) {
    if (!canRead(mediaType)) {
        return false;
    }
    JavaType javaType = getJavaType(type, contextClass);
    if (!logger.isWarnEnabled()) {
        return this.objectMapper.canDeserialize(javaType);
    }
    AtomicReference<Throwable> causeRef = new AtomicReference<>();
    if (this.objectMapper.canDeserialize(javaType, causeRef)) {
        return true;
    }
    logWarningIfNecessary(javaType, causeRef.get());
    return false;
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType) AtomicReference(java.util.concurrent.atomic.AtomicReference)

Example 55 with JavaType

use of com.fasterxml.jackson.databind.JavaType in project jackson-databind by FasterXML.

the class UntypedObjectDeserializer method resolve.

/*
    /**********************************************************
    /* Initialization
    /**********************************************************
     */
/**
     * We need to implement this method to properly find things to delegate
     * to: it can not be done earlier since delegated deserializers almost
     * certainly require access to this instance (at least "List" and "Map" ones)
     */
@SuppressWarnings("unchecked")
@Override
public void resolve(DeserializationContext ctxt) throws JsonMappingException {
    JavaType obType = ctxt.constructType(Object.class);
    JavaType stringType = ctxt.constructType(String.class);
    TypeFactory tf = ctxt.getTypeFactory();
    // So: first find possible custom instances
    if (_listType == null) {
        _listDeserializer = _clearIfStdImpl(_findCustomDeser(ctxt, tf.constructCollectionType(List.class, obType)));
    } else {
        // NOTE: if non-default List type, always consider to be non-standard deser
        _listDeserializer = _findCustomDeser(ctxt, _listType);
    }
    if (_mapType == null) {
        _mapDeserializer = _clearIfStdImpl(_findCustomDeser(ctxt, tf.constructMapType(Map.class, stringType, obType)));
    } else {
        // NOTE: if non-default Map type, always consider to be non-standard deser
        _mapDeserializer = _findCustomDeser(ctxt, _mapType);
    }
    _stringDeserializer = _clearIfStdImpl(_findCustomDeser(ctxt, stringType));
    _numberDeserializer = _clearIfStdImpl(_findCustomDeser(ctxt, tf.constructType(Number.class)));
    // and then do bogus contextualization, in case custom ones need to resolve dependencies of
    // their own
    JavaType unknown = TypeFactory.unknownType();
    _mapDeserializer = (JsonDeserializer<Object>) ctxt.handleSecondaryContextualization(_mapDeserializer, null, unknown);
    _listDeserializer = (JsonDeserializer<Object>) ctxt.handleSecondaryContextualization(_listDeserializer, null, unknown);
    _stringDeserializer = (JsonDeserializer<Object>) ctxt.handleSecondaryContextualization(_stringDeserializer, null, unknown);
    _numberDeserializer = (JsonDeserializer<Object>) ctxt.handleSecondaryContextualization(_numberDeserializer, null, unknown);
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType) TypeFactory(com.fasterxml.jackson.databind.type.TypeFactory)

Aggregations

JavaType (com.fasterxml.jackson.databind.JavaType)110 TypeFactory (com.fasterxml.jackson.databind.type.TypeFactory)10 IOException (java.io.IOException)10 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)7 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)7 ArrayList (java.util.ArrayList)7 BeanDescription (com.fasterxml.jackson.databind.BeanDescription)6 Property (io.swagger.models.properties.Property)6 Test (org.junit.Test)6 ObjectReader (com.fasterxml.jackson.databind.ObjectReader)5 Method (java.lang.reflect.Method)5 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)4 StringProperty (io.swagger.models.properties.StringProperty)4 List (java.util.List)4 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)3 NamedType (com.fasterxml.jackson.databind.jsontype.NamedType)3 CollectionType (com.fasterxml.jackson.databind.type.CollectionType)3 MapType (com.fasterxml.jackson.databind.type.MapType)3 ClassConfig (io.servicecomb.common.javassist.ClassConfig)3 ModelImpl (io.swagger.models.ModelImpl)3