Search in sources :

Example 71 with JavaType

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

the class TestTypeResolution method testGeneric.

public void testGeneric() {
    TypeFactory tf = TypeFactory.defaultInstance();
    // First, via simple sub-class
    JavaType t = tf.constructType(DoubleRange.class);
    JavaType rangeParams = t.findSuperType(Range.class);
    assertEquals(1, rangeParams.containedTypeCount());
    assertEquals(Double.class, rangeParams.containedType(0).getRawClass());
    // then using TypeRef
    t = tf.constructType(new TypeReference<DoubleRange>() {
    });
    rangeParams = t.findSuperType(Range.class);
    assertEquals(1, rangeParams.containedTypeCount());
    assertEquals(Double.class, rangeParams.containedType(0).getRawClass());
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType) TypeReference(com.fasterxml.jackson.core.type.TypeReference) TypeFactory(com.fasterxml.jackson.databind.type.TypeFactory)

Example 72 with JavaType

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

the class TestJavaType method testSimpleClass.

public void testSimpleClass() {
    TypeFactory tf = TypeFactory.defaultInstance();
    JavaType baseType = tf.constructType(BaseType.class);
    assertSame(BaseType.class, baseType.getRawClass());
    assertTrue(baseType.hasRawClass(BaseType.class));
    assertFalse(baseType.isTypeOrSubTypeOf(SubType.class));
    assertFalse(baseType.isArrayType());
    assertFalse(baseType.isContainerType());
    assertFalse(baseType.isEnumType());
    assertFalse(baseType.isInterface());
    assertFalse(baseType.isPrimitive());
    assertFalse(baseType.isReferenceType());
    assertFalse(baseType.hasContentType());
    assertNull(baseType.getContentType());
    assertNull(baseType.getKeyType());
    assertNull(baseType.getValueHandler());
    assertEquals("Lcom/fasterxml/jackson/databind/type/TestJavaType$BaseType;", baseType.getGenericSignature());
    assertEquals("Lcom/fasterxml/jackson/databind/type/TestJavaType$BaseType;", baseType.getErasedSignature());
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType)

Example 73 with JavaType

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

the class TestJavaType method testDeprecated.

@SuppressWarnings("deprecation")
public void testDeprecated() {
    TypeFactory tf = TypeFactory.defaultInstance();
    JavaType baseType = tf.constructType(BaseType.class);
    assertTrue(baseType.hasRawClass(BaseType.class));
    assertNull(baseType.getParameterSource());
    assertNull(baseType.getContentTypeHandler());
    assertNull(baseType.getContentValueHandler());
    assertFalse(baseType.hasValueHandler());
    assertFalse(baseType.hasHandlers());
    assertSame(baseType, baseType.forcedNarrowBy(BaseType.class));
    JavaType sub = baseType.forcedNarrowBy(SubType.class);
    assertTrue(sub.hasRawClass(SubType.class));
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType)

Example 74 with JavaType

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

the class TestJavaType method testMapType.

public void testMapType() {
    TypeFactory tf = TypeFactory.defaultInstance();
    JavaType mapT = tf.constructType(HashMap.class);
    assertTrue(mapT.isContainerType());
    assertFalse(mapT.isReferenceType());
    assertTrue(mapT.hasContentType());
    assertNotNull(mapT.toString());
    assertNotNull(mapT.getContentType());
    assertNotNull(mapT.getKeyType());
    assertEquals("Ljava/util/HashMap<Ljava/lang/Object;Ljava/lang/Object;>;", mapT.getGenericSignature());
    assertEquals("Ljava/util/HashMap;", mapT.getErasedSignature());
    assertTrue(mapT.equals(mapT));
    assertFalse(mapT.equals(null));
    assertFalse(mapT.equals("xyz"));
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType)

Example 75 with JavaType

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

the class TestJavaType method testAnchorTypeForRefTypes.

public void testAnchorTypeForRefTypes() throws Exception {
    TypeFactory tf = TypeFactory.defaultInstance();
    JavaType t = tf.constructType(AtomicStringReference.class);
    assertTrue(t.isReferenceType());
    assertTrue(t.hasContentType());
    ReferenceType rt = (ReferenceType) t;
    assertFalse(rt.isAnchorType());
    assertEquals(AtomicReference.class, rt.getAnchorType().getRawClass());
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType)

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