List of usage examples for com.fasterxml.jackson.databind.type TypeFactory defaultInstance
public static TypeFactory defaultInstance()
From source file:com.github.yongchristophertang.engine.java.handler.JsonTransformer.java
/** * Transform the json result to a list with T as its member class. * * @param clazz the type class of transformed list member object *//*from w w w. j a va 2 s . c o m*/ public <T> List<T> list(String expression, Class<T> clazz) throws IOException { ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); return expression == null ? mapper.readValue(context, TypeFactory.defaultInstance().constructCollectionType(List.class, clazz)) : mapper.readValue(JsonPath.compile(expression).read(context).toString(), TypeFactory.defaultInstance().constructCollectionType(List.class, clazz)); }
From source file:org.springframework.amqp.support.converter.DefaultJackson2JavaTypeMapper.java
public void fromClass(Class<?> clazz, MessageProperties properties) { fromJavaType(TypeFactory.defaultInstance().constructType(clazz), properties); }
From source file:org.springframework.cloud.lattice.connector.AbstractServiceInfoCreatorTests.java
@SneakyThrows protected <T> List<T> read(Class<T> aClass, String s) { CollectionType type = TypeFactory.defaultInstance().constructCollectionType(List.class, aClass); return mapper.readValue(s, type); }
From source file:hr.ws4is.JsonDecoder.java
/** * Does actual conversion from JSON string to Java class instance * @param type// w w w . ja va 2 s .co m * @param json * @throws IOException */ private void parse(final Class<T> type, final String json) throws IOException { final JsonFactory factory = new JsonFactory(); final JsonParser jp = factory.createParser(json); final JsonNode jn = OBJECT_MAPPER.readTree(jp); if (jn.isArray()) { final TypeFactory tf = TypeFactory.defaultInstance(); final JavaType jt = tf.constructCollectionType(ArrayList.class, type); objectList = OBJECT_MAPPER.readValues(jp, jt); } else { object = OBJECT_MAPPER.treeToValue(jn, type); } }
From source file:org.bremersee.common.spring.autoconfigure.WebMvcExceptionResolver.java
public WebMvcExceptionResolver() { defaultExceptionMapper = new ThrowableToThrowableDtoMapper(); Jaxb2Marshaller m = new Jaxb2Marshaller(); m.setContextPath(ThrowableDto.class.getPackage().getName()); marshaller = m;//from w w w. j a v a 2 s .c o m objectMapper = new ObjectMapper(); // see http://wiki.fasterxml.com/JacksonJAXBAnnotations AnnotationIntrospector primary = new JacksonAnnotationIntrospector(); AnnotationIntrospector secondary = new JaxbAnnotationIntrospector(TypeFactory.defaultInstance()); AnnotationIntrospectorPair pair = new AnnotationIntrospectorPair(primary, secondary); objectMapper.setAnnotationIntrospector(pair); }
From source file:org.springframework.amqp.support.converter.DefaultJackson2JavaTypeMapperTest.java
@Test public void fromJavaTypeShouldPopulateWithJavaTypeNameByDefault() { javaTypeMapper.fromJavaType(TypeFactory.defaultInstance().constructType(SimpleTrade.class), properties); String className = (String) properties.getHeaders().get(javaTypeMapper.getClassIdFieldName()); assertThat(className, equalTo(SimpleTrade.class.getName())); }
From source file:org.broadleafcommerce.core.web.api.jaxrs.JaxrsObjectMapperProvider.java
@Override public void afterPropertiesSet() throws Exception { mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true); // serializing to singleelement arrays is enabled by default but just in case they change this in the future... mapper.configure(SerializationFeature.WRITE_SINGLE_ELEM_ARRAYS_UNWRAPPED, false); // Register the JAXB annotation module JaxbAnnotationModule jaxbModule = new JaxbAnnotationModule(); // Make sure that JAXB is the primary serializer (technically the default behavior but let's be explicit) jaxbModule.setPriority(Priority.PRIMARY); mapper.registerModule(new JaxbAnnotationModule()); mapper.setTypeFactory(TypeFactory.defaultInstance().withModifier(typeModifier)); }
From source file:org.pentaho.metaverse.impl.model.kettle.json.TransMetaJsonSerializerTest.java
@Test public void testConstructors() { serializer = new TransMetaJsonSerializer(TransMeta.class); serializer = new TransMetaJsonSerializer(TransMeta.class, true); serializer = new TransMetaJsonSerializer( TypeFactory.defaultInstance().uncheckedSimpleType(TransMeta.class)); }
From source file:it.uniroma2.sag.kelp.data.representation.structure.similarity.StructureElementSimilarityTypeResolver.java
public JavaType typeFromId(String arg0) { Class<? extends StructureElementSimilarityI> clazz = idToClassMapping.get(arg0); if (clazz != null) { JavaType type = TypeFactory.defaultInstance().constructSpecializedType(mBaseType, clazz); return type; }//from w w w. j a v a2s . c o m throw new IllegalStateException("cannot find mapping for '" + arg0 + "'"); }
From source file:sys.core.jackson.MappingJacksonHttpMessageConverter.java
protected JavaType getJavaType(Class<?> clase) { return TypeFactory.defaultInstance().constructType(clase); }