Search in sources :

Example 31 with JavaType

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JavaType in project jackson-databind by FasterXML.

the class TestJavaType method testEnumType.

public void testEnumType() {
    TypeFactory tf = TypeFactory.defaultInstance();
    JavaType enumT = tf.constructType(MyEnum.class);
    assertTrue(enumT.isEnumType());
    assertFalse(enumT.hasHandlers());
    assertTrue(enumT.isTypeOrSubTypeOf(MyEnum.class));
    assertTrue(enumT.isTypeOrSubTypeOf(Object.class));
    assertNull(enumT.containedType(3));
    assertTrue(enumT.containedTypeOrUnknown(3).isJavaLangObject());
    assertEquals("Lcom/fasterxml/jackson/databind/type/TestJavaType$MyEnum;", enumT.getGenericSignature());
    assertEquals("Lcom/fasterxml/jackson/databind/type/TestJavaType$MyEnum;", enumT.getErasedSignature());
    assertTrue(tf.constructType(MyEnum2.class).isEnumType());
    assertTrue(tf.constructType(MyEnum.A.getClass()).isEnumType());
    assertTrue(tf.constructType(MyEnum2.A.getClass()).isEnumType());
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType)

Example 32 with JavaType

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JavaType in project jackson-databind by FasterXML.

the class TestJavaType method testGenericSignature1194.

// [databind#1194]
public void testGenericSignature1194() throws Exception {
    TypeFactory tf = TypeFactory.defaultInstance();
    Method m;
    JavaType t;
    m = Generic1194.class.getMethod("getList");
    t = tf.constructType(m.getGenericReturnType());
    assertEquals("Ljava/util/List<Ljava/lang/String;>;", t.getGenericSignature());
    assertEquals("Ljava/util/List;", t.getErasedSignature());
    m = Generic1194.class.getMethod("getMap");
    t = tf.constructType(m.getGenericReturnType());
    assertEquals("Ljava/util/Map<Ljava/lang/String;Ljava/lang/String;>;", t.getGenericSignature());
    m = Generic1194.class.getMethod("getGeneric");
    t = tf.constructType(m.getGenericReturnType());
    assertEquals("Ljava/util/concurrent/atomic/AtomicReference<Ljava/lang/String;>;", t.getGenericSignature());
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType) Method(java.lang.reflect.Method)

Example 33 with JavaType

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JavaType in project jackson-databind by FasterXML.

the class TestJavaType method testArrayType.

public void testArrayType() {
    TypeFactory tf = TypeFactory.defaultInstance();
    JavaType arrayT = ArrayType.construct(tf.constructType(String.class), null);
    assertNotNull(arrayT);
    assertTrue(arrayT.isContainerType());
    assertFalse(arrayT.isReferenceType());
    assertTrue(arrayT.hasContentType());
    assertNotNull(arrayT.toString());
    assertNotNull(arrayT.getContentType());
    assertNull(arrayT.getKeyType());
    assertTrue(arrayT.equals(arrayT));
    assertFalse(arrayT.equals(null));
    assertFalse(arrayT.equals("xyz"));
    assertTrue(arrayT.equals(ArrayType.construct(tf.constructType(String.class), null)));
    assertFalse(arrayT.equals(ArrayType.construct(tf.constructType(Integer.class), null)));
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType)

Example 34 with JavaType

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JavaType in project jackson-databind by FasterXML.

the class TestJavaType method testJavaTypeAsJLRType.

// [databind#116]
public void testJavaTypeAsJLRType() {
    TypeFactory tf = TypeFactory.defaultInstance();
    JavaType t1 = tf.constructType(getClass());
    // should just get it back as-is:
    JavaType t2 = tf.constructType(t1);
    assertSame(t1, t2);
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType)

Example 35 with JavaType

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JavaType in project beam by apache.

the class ProxyInvocationHandler method getValueFromJson.

/**
   * Uses a Jackson {@link ObjectMapper} to attempt type conversion.
   *
   * @param method The method whose return type you would like to return.
   * @param propertyName The name of the property that is being returned.
   * @return An object matching the return type of the method passed in.
   */
private Object getValueFromJson(String propertyName, Method method) {
    try {
        JavaType type = PipelineOptionsFactory.MAPPER.getTypeFactory().constructType(method.getGenericReturnType());
        JsonNode jsonNode = jsonOptions.get(propertyName);
        return PipelineOptionsFactory.MAPPER.readValue(jsonNode.toString(), type);
    } catch (IOException e) {
        throw new RuntimeException("Unable to parse representation", e);
    }
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException)

Aggregations

JavaType (com.fasterxml.jackson.databind.JavaType)322 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)36 Test (org.junit.Test)29 BeanDescription (com.fasterxml.jackson.databind.BeanDescription)25 IOException (java.io.IOException)25 BeanPropertyDefinition (com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition)22 ArrayList (java.util.ArrayList)21 TypeFactory (com.fasterxml.jackson.databind.type.TypeFactory)17 Property (io.swagger.models.properties.Property)16 List (java.util.List)16 Map (java.util.Map)14 ModelImpl (io.swagger.models.ModelImpl)13 StringProperty (io.swagger.models.properties.StringProperty)13 Annotation (java.lang.annotation.Annotation)12 Method (java.lang.reflect.Method)11 Type (java.lang.reflect.Type)11 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)10 BodyParameter (io.swagger.models.parameters.BodyParameter)10 MapProperty (io.swagger.models.properties.MapProperty)10 JsonDeserializer (com.fasterxml.jackson.databind.JsonDeserializer)9