use of com.fasterxml.jackson.databind.type.MapType in project hadoop by apache.
the class TestWebHDFS method toBlockLocationArray.
private BlockLocation[] toBlockLocationArray(String json) throws IOException {
ObjectMapper mapper = new ObjectMapper();
MapType subType = mapper.getTypeFactory().constructMapType(Map.class, String.class, BlockLocation[].class);
MapType rootType = mapper.getTypeFactory().constructMapType(Map.class, mapper.constructType(String.class), mapper.constructType(subType));
Map<String, Map<String, BlockLocation[]>> jsonMap = mapper.readValue(json, rootType);
Map<String, BlockLocation[]> locationMap = jsonMap.get("BlockLocations");
BlockLocation[] locationArray = locationMap.get(BlockLocation.class.getSimpleName());
return locationArray;
}
use of com.fasterxml.jackson.databind.type.MapType in project jackson-databind by FasterXML.
the class TestTypeResolution method testMaps.
/*
/**********************************************************
/* Test methods
/**********************************************************
*/
public void testMaps() {
TypeFactory tf = TypeFactory.defaultInstance();
JavaType t = tf.constructType(new TypeReference<LongValuedMap<String>>() {
});
MapType type = (MapType) t;
assertSame(LongValuedMap.class, type.getRawClass());
assertEquals(tf.constructType(String.class), type.getKeyType());
assertEquals(tf.constructType(Long.class), type.getContentType());
}
use of com.fasterxml.jackson.databind.type.MapType in project graylog2-server by Graylog2.
the class MessageSummaryTest method testJSONSerialization.
@Test
public void testJSONSerialization() throws Exception {
final ObjectMapper mapper = new ObjectMapper();
final MapType valueType = mapper.getTypeFactory().constructMapType(HashMap.class, String.class, Object.class);
final Map<String, Object> map = mapper.readValue(mapper.writeValueAsBytes(messageSummary), valueType);
assertEquals(map.keySet(), Sets.newHashSet("id", "timestamp", "message", "index", "source", "streamIds", "fields"));
}
Aggregations