Search in sources :

Example 26 with JavaType

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

the class TypeFactory method _mapType.

/*
    /**********************************************************
    /* Low-level factory methods
    /**********************************************************
     */
private JavaType _mapType(Class<?> rawClass, TypeBindings bindings, JavaType superClass, JavaType[] superInterfaces) {
    JavaType kt, vt;
    // 28-May-2015, tatu: Properties are special, as per [databind#810]; fake "correct" parameter sig
    if (rawClass == Properties.class) {
        kt = vt = CORE_TYPE_STRING;
    } else {
        List<JavaType> typeParams = bindings.getTypeParameters();
        // ok to have no types ("raw")
        switch(typeParams.size()) {
            case // acceptable?
            0:
                kt = vt = _unknownType();
                break;
            case 2:
                kt = typeParams.get(0);
                vt = typeParams.get(1);
                break;
            default:
                throw new IllegalArgumentException("Strange Map type " + rawClass.getName() + ": can not determine type parameters");
        }
    }
    return MapType.construct(rawClass, bindings, superClass, superInterfaces, kt, vt);
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType)

Example 27 with JavaType

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

the class JsonLocationInstantiator method getFromObjectArguments.

@Override
public SettableBeanProperty[] getFromObjectArguments(DeserializationConfig config) {
    JavaType intType = config.constructType(Integer.TYPE);
    JavaType longType = config.constructType(Long.TYPE);
    return new SettableBeanProperty[] { creatorProp("sourceRef", config.constructType(Object.class), 0), creatorProp("byteOffset", longType, 1), creatorProp("charOffset", longType, 2), creatorProp("lineNr", intType, 3), creatorProp("columnNr", intType, 4) };
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType) SettableBeanProperty(com.fasterxml.jackson.databind.deser.SettableBeanProperty)

Example 28 with JavaType

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

the class AnnotatedClass method _findFields.

/*
    /**********************************************************
    /* Helper methods for populating field information
    /**********************************************************
     */
protected Map<String, AnnotatedField> _findFields(JavaType type, TypeResolutionContext typeContext, Map<String, AnnotatedField> fields) {
    /* First, a quick test: we only care for regular classes (not
         * interfaces, primitive types etc), except for Object.class.
         * A simple check to rule out other cases is to see if there
         * is a super class or not.
         */
    JavaType parent = type.getSuperClass();
    if (parent != null) {
        final Class<?> cls = type.getRawClass();
        // Let's add super-class' fields first, then ours.
        /* 21-Feb-2010, tatu: Need to handle masking: as per [JACKSON-226]
             *    we otherwise get into trouble...
             */
        fields = _findFields(parent, new TypeResolutionContext.Basic(_typeFactory, parent.getBindings()), fields);
        for (Field f : ClassUtil.getDeclaredFields(cls)) {
            // static fields not included (transients are at this point, filtered out later)
            if (!_isIncludableField(f)) {
                continue;
            }
            /* Ok now: we can (and need) not filter out ignorable fields
                 * at this point; partly because mix-ins haven't been
                 * added, and partly because logic can be done when
                 * determining get/settability of the field.
                 */
            if (fields == null) {
                fields = new LinkedHashMap<String, AnnotatedField>();
            }
            fields.put(f.getName(), _constructField(f, typeContext));
        }
        // And then... any mix-in overrides?
        if (_mixInResolver != null) {
            Class<?> mixin = _mixInResolver.findMixInClassFor(cls);
            if (mixin != null) {
                _addFieldMixIns(mixin, cls, fields);
            }
        }
    }
    return fields;
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType)

Example 29 with JavaType

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

the class TestJavaType method testObjectToReferenceSpecialization.

// for [databind#1290]
public void testObjectToReferenceSpecialization() throws Exception {
    TypeFactory tf = TypeFactory.defaultInstance();
    JavaType base = tf.constructType(Object.class);
    assertTrue(base.isJavaLangObject());
    JavaType sub = tf.constructSpecializedType(base, AtomicReference.class);
    assertEquals(AtomicReference.class, sub.getRawClass());
    assertTrue(sub.isReferenceType());
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType)

Example 30 with JavaType

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

the class TestJavaType method testLocalType728.

/*
    /**********************************************************
    /* Test methods
    /**********************************************************
     */
public void testLocalType728() throws Exception {
    TypeFactory tf = TypeFactory.defaultInstance();
    Method m = Issue728.class.getMethod("method", CharSequence.class);
    assertNotNull(m);
    // Start with return type
    // first type-erased
    JavaType t = tf.constructType(m.getReturnType());
    assertEquals(CharSequence.class, t.getRawClass());
    // then generic
    t = tf.constructType(m.getGenericReturnType());
    assertEquals(CharSequence.class, t.getRawClass());
    // then parameter type
    t = tf.constructType(m.getParameterTypes()[0]);
    assertEquals(CharSequence.class, t.getRawClass());
    t = tf.constructType(m.getGenericParameterTypes()[0]);
    assertEquals(CharSequence.class, t.getRawClass());
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType) Method(java.lang.reflect.Method)

Aggregations

JavaType (com.fasterxml.jackson.databind.JavaType)264 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)31 Test (org.junit.Test)27 IOException (java.io.IOException)21 BeanDescription (com.fasterxml.jackson.databind.BeanDescription)20 BeanPropertyDefinition (com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition)17 ArrayList (java.util.ArrayList)17 TypeFactory (com.fasterxml.jackson.databind.type.TypeFactory)15 Property (io.swagger.models.properties.Property)15 List (java.util.List)15 Map (java.util.Map)13 StringProperty (io.swagger.models.properties.StringProperty)12 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)10 ModelImpl (io.swagger.models.ModelImpl)10 MapProperty (io.swagger.models.properties.MapProperty)10 Method (java.lang.reflect.Method)10 Type (java.lang.reflect.Type)10 JsonDeserializer (com.fasterxml.jackson.databind.JsonDeserializer)9 ArrayProperty (io.swagger.models.properties.ArrayProperty)9 IntegerProperty (io.swagger.models.properties.IntegerProperty)9