List of usage examples for com.fasterxml.jackson.databind.type CollectionType construct
public static CollectionType construct(Class<?> paramClass, JavaType paramJavaType)
From source file:javaslang.jackson.datatype.serialize.ArraySerializer.java
@Override
JavaType emulatedJavaType(JavaType type) {
return CollectionType.construct(ArrayList.class, type.containedType(0));
}
From source file:org.springframework.amqp.support.converter.DefaultJackson2JavaTypeMapper.java
public JavaType toJavaType(MessageProperties properties) { JavaType classType = getClassIdType(retrieveHeader(properties, getClassIdFieldName())); if (!classType.isContainerType() || classType.isArrayType()) { return classType; }/* w w w. j a v a 2s .c o m*/ JavaType contentClassType = getClassIdType(retrieveHeader(properties, getContentClassIdFieldName())); if (classType.getKeyType() == null) { return CollectionType.construct(classType.getRawClass(), contentClassType); } JavaType keyClassType = getClassIdType(retrieveHeader(properties, getKeyClassIdFieldName())); return MapType.construct(classType.getRawClass(), keyClassType, contentClassType); }
From source file:javaslang.jackson.datatype.serialize.MultimapSerializer.java
@Override JavaType emulatedJavaType(JavaType type) { return MapType.construct(LinkedHashMap.class, type.containedType(0), CollectionType.construct(ArrayList.class, type.containedType(1))); }
From source file:javaslang.jackson.datatype.deserialize.MultimapDeserializer.java
@Override public void resolve(DeserializationContext ctxt) throws JsonMappingException { super.resolve(ctxt); JavaType containerType = CollectionType.construct(ArrayList.class, mapLikeType.getContentType()); containerDeserializer = ctxt.findContextualValueDeserializer(containerType, null); }
From source file:ch.rasc.wampspring.method.MethodParameterConverter.java
public Object convert(MethodParameter parameter, Object argument) { if (argument == null) { if (parameter.getParameterType().getName().equals("java.util.Optional")) { return OptionalUnwrapper.empty(); }// w w w .ja va2s .com return null; } Class<?> sourceClass = argument.getClass(); Class<?> targetClass = parameter.getParameterType(); TypeDescriptor td = new TypeDescriptor(parameter); if (targetClass.isAssignableFrom(sourceClass)) { return convertListElements(td, argument); } if (this.conversionService.canConvert(sourceClass, targetClass)) { try { return convertListElements(td, this.conversionService.convert(argument, targetClass)); } catch (Exception e) { TypeFactory typeFactory = this.objectMapper.getTypeFactory(); if (td.isCollection()) { JavaType type = CollectionType.construct(td.getType(), typeFactory.constructType(td.getElementTypeDescriptor().getType())); return this.objectMapper.convertValue(argument, type); } else if (td.isArray()) { JavaType type = typeFactory.constructArrayType(td.getElementTypeDescriptor().getType()); return this.objectMapper.convertValue(argument, type); } throw e; } } return this.objectMapper.convertValue(argument, targetClass); }
From source file:com.nebhale.jsonpath.JsonPathTest.java
@Test public void stringInputJavaTypeOutput() { assertEquals("Sayings of the Century", JsonPath.read("$.store.book[0].title", STRING_VALID, SimpleType.construct(String.class))); assertEquals(Sets.asSet("Sayings of the Century", "Sword of Honour"), JsonPath.read("$.store.book[0,1].title", STRING_VALID, CollectionType.construct(Set.class, SimpleType.construct(String.class)))); assertEquals("Sayings of the Century", JsonPath.read("$['store']['book'][0]['title']", STRING_VALID, SimpleType.construct(String.class))); assertEquals(Arrays.asList("red", "blue"), JsonPath.read("$.store.bicycle.color", STRING_VALID, CollectionType.construct(List.class, SimpleType.construct(String.class)))); assertEquals(Arrays.asList("city", "hybrid", "downhill", "freeride"), JsonPath.read("$.store.bicycle.style", STRING_VALID, CollectionType.construct(List.class, SimpleType.construct(String.class)))); assertEquals(Arrays.asList("city", "hybrid", "downhill", "freeride"), JsonPath.read("$.store..style", STRING_VALID, CollectionType.construct(List.class, SimpleType.construct(String.class)))); }
From source file:org.ocelotds.core.services.ArgumentConvertor.java
private JavaType getJavaType(Type type) { Class clazz;// w w w . java 2s . c om logger.debug("Computing type of {} - {}", type.getClass(), type.toString()); if (type instanceof ParameterizedType) { clazz = (Class) ((ParameterizedType) type).getRawType(); } else { clazz = (Class) type; } JavaType javaType; Type actualType; if (Collection.class.isAssignableFrom(clazz)) { ParameterizedType pt = (ParameterizedType) type; actualType = pt.getActualTypeArguments()[0]; JavaType t1 = getJavaType(actualType); javaType = CollectionType.construct(Collection.class, t1); } else if (clazz.isArray()) { Class t = clazz.getComponentType(); JavaType t1 = getJavaType(t); javaType = ArrayType.construct(t1, null, null); } else if (Map.class.isAssignableFrom(clazz)) { ParameterizedType pt = (ParameterizedType) type; actualType = pt.getActualTypeArguments()[0]; JavaType t1 = getJavaType(actualType); actualType = pt.getActualTypeArguments()[1]; JavaType t2 = getJavaType(actualType); javaType = MapType.construct(Map.class, t1, t2); } else { javaType = SimpleType.construct(clazz); } return javaType; }
From source file:com.nebhale.jsonpath.JsonPathTest.java
@Test public void jsonNodeInputJavaTypeOutput() { assertEquals("Sayings of the Century", JsonPath.read("$.store.book[0].title", NODE, SimpleType.construct(String.class))); assertEquals(Sets.asSet("Sayings of the Century", "Sword of Honour"), JsonPath.read("$.store.book[0,1].title", NODE, CollectionType.construct(Set.class, SimpleType.construct(String.class)))); assertEquals("Sayings of the Century", JsonPath.read("$['store']['book'][0]['title']", NODE, SimpleType.construct(String.class))); assertEquals(Arrays.asList("red", "blue"), JsonPath.read("$.store.bicycle.color", NODE, CollectionType.construct(List.class, SimpleType.construct(String.class)))); assertEquals(Arrays.asList("city", "hybrid", "downhill", "freeride"), JsonPath.read("$.store.bicycle.style", NODE, CollectionType.construct(List.class, SimpleType.construct(String.class)))); assertEquals(Arrays.asList("city", "hybrid", "downhill", "freeride"), JsonPath.read("$.store..style", NODE, CollectionType.construct(List.class, SimpleType.construct(String.class)))); }
From source file:org.apache.alert.coordinator.SchedulerTest.java
public static <T> List<T> loadEntities(String path, Class<T> tClz) throws Exception { System.out.println(FileUtils.readFileToString(new File(SchedulerTest.class.getResource(path).getPath()))); JavaType type = CollectionType.construct(List.class, SimpleType.construct(tClz)); List<T> l = mapper.readValue(SchedulerTest.class.getResourceAsStream(path), type); return l;// w ww . ja v a 2 s .co m }