Search in sources :

Example 1 with MapType

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;
}
Also used : BlockLocation(org.apache.hadoop.fs.BlockLocation) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) MapType(com.fasterxml.jackson.databind.type.MapType)

Example 2 with MapType

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());
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType) TypeFactory(com.fasterxml.jackson.databind.type.TypeFactory) MapType(com.fasterxml.jackson.databind.type.MapType)

Example 3 with MapType

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"));
}
Also used : ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) MapType(com.fasterxml.jackson.databind.type.MapType) Test(org.junit.Test)

Aggregations

MapType (com.fasterxml.jackson.databind.type.MapType)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 JavaType (com.fasterxml.jackson.databind.JavaType)1 TypeFactory (com.fasterxml.jackson.databind.type.TypeFactory)1 Map (java.util.Map)1 BlockLocation (org.apache.hadoop.fs.BlockLocation)1 Test (org.junit.Test)1