Example usage for com.fasterxml.jackson.databind.type TypeFactory defaultInstance

List of usage examples for com.fasterxml.jackson.databind.type TypeFactory defaultInstance

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind.type TypeFactory defaultInstance.

Prototype

public static TypeFactory defaultInstance() 

Source Link

Usage

From source file:minium.web.internal.expression.JsonCoercer.java

@Override
public Object coerce(Object obj, Type type) {
    try {/*  w  ww  .j  a  v  a 2s. co m*/
        JavaType javaType = TypeFactory.defaultInstance().constructType(type);
        return mapper.readValue(obj.toString(), javaType);
    } catch (JsonParseException e) {
        throw new CannotCoerceException(e);
    } catch (JsonMappingException e) {
        throw new CannotCoerceException(e);
    } catch (IOException e) {
        throw new CannotCoerceException(e);
    }
}

From source file:com.simple.toadiot.rtinfosdk.util.ParserUtil.java

public static <T> List<T> toConnectedObjects(String body, Class<T> clazz)
        throws JsonParseException, JsonMappingException, IOException {

    List<T> objs;/*from  ww w  . j a  v  a 2  s .c  om*/
    CollectionType collectionType = TypeFactory.defaultInstance().constructCollectionType(ArrayList.class,
            clazz);
    try {
        objs = getObjectMapper().readValue(body, collectionType);
    } catch (IOException e) {
        throw new ParseToObjectException(String.format("? [%s] to %s.", body, clazz), e);
    }

    return objs;
}

From source file:com.palantir.typescript.services.classifier.Classifier.java

public List<ClassificationResult> getClassificationsForLines(List<String> lines, EndOfLineState lexState) {
    checkNotNull(lines);// w  ww.  ja v a 2 s . co  m
    checkNotNull(lexState);

    Request request = new Request("classifier", "getClassificationsForLines", lines, lexState.ordinal());
    CollectionType resultType = TypeFactory.defaultInstance().constructCollectionType(List.class,
            ClassificationResult.class);

    return this.bridge.call(request, resultType);
}

From source file:tv.arte.resteventapi.core.presentation.serialization.TransientStringSerializer.java

@Override
public void serialize(Object value, JsonGenerator jgen, SerializerProvider provider)
        throws IOException, JsonProcessingException {
    //Serialize everything else but TransientString
    if (!(value instanceof TransientString)) {
        StdKeySerializers/*from   w  ww .j  a va2 s  .  c o  m*/
                .getStdKeySerializer(TypeFactory.defaultInstance()
                        .constructFromCanonical(value.getClass().getCanonicalName()))
                .serialize(value, jgen, provider);
    }
}

From source file:com.infinities.keystone4j.utils.jackson.JacksonProvider.java

public JacksonProvider() {
    AnnotationIntrospector introspector = new JaxbAnnotationIntrospector(TypeFactory.defaultInstance());
    // if using BOTH JAXB annotations AND Jackson annotations:
    AnnotationIntrospector secondary = new JacksonAnnotationIntrospector();

    ObjectMapper mapper = new ObjectMapper().registerModule(new Hibernate4Module())
            .setSerializationInclusion(Include.NON_NULL)
            .configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false)
            .enable(SerializationFeature.INDENT_OUTPUT)
            .setAnnotationIntrospector(new AnnotationIntrospectorPair(introspector, secondary));
    // mapper = mapper.setSerializationInclusion(Include)
    setMapper(mapper);//from   w  w w . ja va  2 s  .  co  m
}

From source file:io.fabric8.cxf.endpoint.BeanValidationAnnotationIntrospector.java

public BeanValidationAnnotationIntrospector(TypeFactory typeFactory) {
    this.typeFactory = (typeFactory == null) ? TypeFactory.defaultInstance() : typeFactory;
}

From source file:com.github.jasonruckman.sidney.core.type.Types.java

public static TypeBindings binding(Field field, TypeBindings parentBindings) {
    Type t = field.getGenericType();
    if (t == null) {
        t = field.getType();//from ww  w .  j  a v  a 2  s .  co  m
    }
    JavaType javaType = TypeFactory.defaultInstance().constructType(t, parentBindings);
    return new TypeBindings(TypeFactory.defaultInstance(), javaType);
}

From source file:com.infinities.nova.util.jackson.JacksonProvider.java

public JacksonProvider() {
    AnnotationIntrospector introspector = new JaxbAnnotationIntrospector(TypeFactory.defaultInstance());
    // if using BOTH JAXB annotations AND Jackson annotations:
    AnnotationIntrospector secondary = new JacksonAnnotationIntrospector();

    ObjectMapper mapper = new ObjectMapper().registerModule(new Hibernate4Module())
            .configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false)
            .setDateFormat(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"))
            .enable(SerializationFeature.INDENT_OUTPUT)
            .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
            .setAnnotationIntrospector(new AnnotationIntrospectorPair(introspector, secondary));
    NullStringSerializer serializer = new NullStringSerializer();

    SimpleModule module = new SimpleModule("NullToNoneDeserializer");
    module.addSerializer(String.class, serializer);
    mapper.registerModule(module);/*w  ww  .  j a v a 2  s  . c o m*/
    // mapper = mapper.setSerializationInclusion(Include)
    setMapper(mapper);
}

From source file:io.swagger.jaxrs.ParameterExtractor.java

public static List<Parameter> getParameters(Swagger swagger, Class cls, Method method) {
    List<Parameter> parameters = new ArrayList<>();
    Type[] genericParameterTypes = method.getGenericParameterTypes();
    Annotation[][] paramAnnotations = method.getParameterAnnotations();
    for (int i = 0; i < genericParameterTypes.length; i++) {
        Type type = null;//from   ww  w .  j  a  v  a2  s .  co  m
        if (SynapseEndpointServiceMarker.class.isAssignableFrom(cls)) {
            //an RPC style endpoint (implements SynapseEndpointServiceMarker)
            type = TypeFactory.defaultInstance().constructType(ParameterWrapper.class, cls);
        } else if (cls.getAnnotation(Service.class) != null) {
            //an endpoint with @Service annotation
            if (genericParameterTypes[i] instanceof ParameterizedType && Request.class
                    .isAssignableFrom((Class<?>) ((ParameterizedType) genericParameterTypes[i]).getRawType())) {
                //if Request or Event Object
                type = TypeFactory.defaultInstance().constructType(
                        ((ParameterizedType) genericParameterTypes[i]).getActualTypeArguments()[0], cls);
            } else {
                type = TypeFactory.defaultInstance().constructType(genericParameterTypes[i], cls);
            }

        }

        extractParameters(swagger, parameters, type, Arrays.asList(paramAnnotations[i]));
    }
    return parameters;
}

From source file:com.google.code.ssm.json.ClassAliasIdResolverTest.java

@Before
public void setUp() {
    baseType = Mockito.mock(JavaType.class);
    typeFactory = TypeFactory.defaultInstance();

    resolver = new ClassAliasIdResolver(baseType, typeFactory, new HashMap<String, Class<?>>(),
            new HashMap<Class<?>, String>());
}