Java Code Examples for com.fasterxml.jackson.databind.type.TypeFactory#constructMapType()

The following examples show how to use com.fasterxml.jackson.databind.type.TypeFactory#constructMapType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ZebraTest.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
/**
 * Test the property 'type'
 */
@Test
public void typeTest() {
    String zebraJson = "{\"type\":\"mountain\",\"className\":\"zebra\",\"key1\":\"value1\",\"key2\":12321}";

    JSON j = new JSON();
    TypeFactory typeFactory = j.getMapper().getTypeFactory();
    MapType mapType = typeFactory.constructMapType(HashMap.class, String.class, Object.class);
    try {
        HashMap<String, Object> map = j.getMapper().readValue(zebraJson, mapType);
        Assert.assertEquals(map.get("type"), "mountain");

        Map<String,Object> result =
                j.getMapper().readValue(zebraJson, new TypeReference<Map<String,Object>>() {});

        Assert.assertEquals(result.get("type"), "mountain");
    } catch (Exception ex) {
        Assert.assertEquals(true, false); // exception shouldn't be thrown
    }

}
 
Example 2
Source File: JsonValueMap.java    From proarc with GNU General Public License v3.0 6 votes vote down vote up
public static JsonValueMap fromBundle(BundleName bundle, Locale locale) {
    JsonValueMap jvm = new JsonValueMap();
    jvm.setMapId(bundle.getValueMapId());

    URL resource = findResource(bundle.toString(), CONTROL, locale);
    if (resource == null) {
        return jvm;
    }
    ObjectMapper om = JsonUtils.defaultObjectMapper();
    try {
        TypeFactory typeFactory = om.getTypeFactory();
        MapType jsonType = typeFactory.constructMapType(Map.class, String.class, Object.class);
        Map<String, Object> jsonMap = om.readValue(resource, jsonType);
        if (LOG.isLoggable(Level.FINE)) {
            LOG.fine(String.valueOf(jsonMap));
        }
        Object data = jsonMap.get("data");
        jvm.setValues((List<Map<String, Object>>) data);
    } catch (Exception ex) {
        LOG.log(Level.WARNING, "Cannot read resource " + resource, ex);
    }
    return jvm;
}
 
Example 3
Source File: ADLListener.java    From archie with Apache License 2.0 5 votes vote down vote up
public void enterComponent_terminologies_section(AdlParser.Component_terminologies_sectionContext ctx) {
    if(archetype instanceof OperationalTemplate) {
        OperationalTemplate template = (OperationalTemplate) archetype;

        TypeFactory typeFactory = OdinToJsonConverter.getObjectMapper().getTypeFactory();
        MapType mapType = typeFactory.constructMapType(ConcurrentHashMap.class, String.class, ArchetypeTerminology.class);

        template.setComponentTerminologies(OdinObjectParser.convert(ctx.odin_text(), mapType));
    } else {
        throw new IllegalArgumentException("cannot add component terminologies to anything but an operational template");
    }
}
 
Example 4
Source File: ElasticSearchDAOV5.java    From conductor with Apache License 2.0 5 votes vote down vote up
private List<Message> mapGetMessagesResponse(SearchResponse response) throws IOException {
    SearchHit[] hits = response.getHits().getHits();
    TypeFactory factory = TypeFactory.defaultInstance();
    MapType type = factory.constructMapType(HashMap.class, String.class, String.class);
    List<Message> messages = new ArrayList<>(hits.length);
    for (SearchHit hit : hits) {
        String source = hit.getSourceAsString();
        Map<String, String> mapSource = objectMapper.readValue(source, type);
        Message msg = new Message(mapSource.get("messageId"), mapSource.get("payload"), null);
        messages.add(msg);
    }
    return messages;
}
 
Example 5
Source File: ElasticSearchRestDAOV5.java    From conductor with Apache License 2.0 5 votes vote down vote up
private List<Message> mapGetMessagesResponse(SearchResponse response) throws IOException {
    SearchHit[] hits = response.getHits().getHits();
    TypeFactory factory = TypeFactory.defaultInstance();
    MapType type = factory.constructMapType(HashMap.class, String.class, String.class);
    List<Message> messages = new ArrayList<>(hits.length);
    for (SearchHit hit : hits) {
        String source = hit.getSourceAsString();
        Map<String, String> mapSource = objectMapper.readValue(source, type);
        Message msg = new Message(mapSource.get("messageId"), mapSource.get("payload"), null);
        messages.add(msg);
    }
    return messages;
}
 
Example 6
Source File: ElasticSearchRestDAOV6.java    From conductor with Apache License 2.0 5 votes vote down vote up
private List<Message> mapGetMessagesResponse(SearchResponse response) throws IOException {
    SearchHit[] hits = response.getHits().getHits();
    TypeFactory factory = TypeFactory.defaultInstance();
    MapType type = factory.constructMapType(HashMap.class, String.class, String.class);
    List<Message> messages = new ArrayList<>(hits.length);
    for (SearchHit hit : hits) {
        String source = hit.getSourceAsString();
        Map<String, String> mapSource = objectMapper.readValue(source, type);
        Message msg = new Message(mapSource.get("messageId"), mapSource.get("payload"), null);
        messages.add(msg);
    }
    return messages;
}
 
Example 7
Source File: ElasticSearchDAOV6.java    From conductor with Apache License 2.0 5 votes vote down vote up
private List<Message> mapGetMessagesResponse(SearchResponse response) throws IOException {
    SearchHit[] hits = response.getHits().getHits();
    TypeFactory factory = TypeFactory.defaultInstance();
    MapType type = factory.constructMapType(HashMap.class, String.class, String.class);
    List<Message> messages = new ArrayList<>(hits.length);
    for (SearchHit hit : hits) {
        String source = hit.getSourceAsString();
        Map<String, String> mapSource = objectMapper.readValue(source, type);
        Message msg = new Message(mapSource.get("messageId"), mapSource.get("payload"), null);
        messages.add(msg);
    }
    return messages;
}
 
Example 8
Source File: TableSerializer.java    From jackson-datatypes-collections with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings( "unchecked" )
protected TableSerializer(final TableSerializer src,
        final BeanProperty property,
        final TypeFactory typeFactory,
        final JsonSerializer<?> rowKeySerializer,
        final JsonSerializer<?> columnKeySerializer,
        final TypeSerializer valueTypeSerializer,
        final JsonSerializer<?> valueSerializer)
{
    super(src, property);
    _type = src._type;
    _rowSerializer = (JsonSerializer<Object>) rowKeySerializer;
    _columnSerializer = (JsonSerializer<Object>) columnKeySerializer;
    _valueTypeSerializer = valueTypeSerializer;
    _valueSerializer = (JsonSerializer<Object>) valueSerializer;
    
    final MapType columnAndValueType = typeFactory.constructMapType(Map.class,
            _type.containedTypeOrUnknown(1), _type.containedTypeOrUnknown(2));

    JsonSerializer<?> columnAndValueSerializer = 
            MapSerializer.construct((Set<String>) null,
                                    columnAndValueType,
                                    false,
                                    _valueTypeSerializer,
                                    _columnSerializer,
                                    _valueSerializer,
                                    null);

    final MapType rowMapType = typeFactory.constructMapType(Map.class,
            _type.containedTypeOrUnknown(0), columnAndValueType);
    _rowMapSerializer =
            MapSerializer.construct((Set<String>) null,
                                    rowMapType,
                                    false,
                                    null,
                                    _rowSerializer,
                                    (JsonSerializer<Object>) columnAndValueSerializer,
                                    null);
}
 
Example 9
Source File: MultimapSerializer.java    From vavr-jackson with Apache License 2.0 4 votes vote down vote up
@Override
JavaType emulatedJavaType(TypeFactory typeFactory) {
    JavaType containerType = typeFactory.constructCollectionType(ArrayList.class, mapType.getContentType());
    return typeFactory.constructMapType(LinkedHashMap.class, mapType.getKeyType(), containerType);
}
 
Example 10
Source File: MapSerializer.java    From vavr-jackson with Apache License 2.0 4 votes vote down vote up
@Override
JavaType emulatedJavaType(TypeFactory typeFactory) {
    return typeFactory.constructMapType(LinkedHashMap.class, mapType.getKeyType(), mapType.getContentType());
}
 
Example 11
Source File: JacksonObjectMapper.java    From bonita-ui-designer with GNU General Public License v2.0 4 votes vote down vote up
public Map<String, String> fromJsonToMap(byte[] bytes) throws IOException {
    TypeFactory factory = TypeFactory.defaultInstance();
    MapType mapType = factory.constructMapType(HashMap.class, String.class, String.class);
    return objectMapper.readValue(bytes, mapType);
}
 
Example 12
Source File: JtModule.java    From haven-platform with Apache License 2.0 4 votes vote down vote up
private MapType constructMapType(Ctx pc, TypeFactory typeFactory) {
    return typeFactory.constructMapType(LinkedHashMap.class, typeFactory.constructType(String.class), pc.getType().getContentType());
}
 
Example 13
Source File: Converters.java    From sailfish-core with Apache License 2.0 4 votes vote down vote up
@Override
public JavaType getOutputType(TypeFactory typeFactory) {
    return typeFactory.constructMapType(HashMap.class, String.class, JsonMessage.class);
}
 
Example 14
Source File: Converters.java    From sailfish-core with Apache License 2.0 4 votes vote down vote up
@Override
public JavaType getOutputType(TypeFactory typeFactory) {
    return typeFactory.constructMapType(HashMap.class, String.class, JsonField.class);
}
 
Example 15
Source File: Converters.java    From sailfish-core with Apache License 2.0 4 votes vote down vote up
@Override
public JavaType getOutputType(TypeFactory typeFactory) {
    return typeFactory.constructMapType(HashMap.class, String.class, JsonAttribute.class);
}
 
Example 16
Source File: Converters.java    From sailfish-core with Apache License 2.0 4 votes vote down vote up
@Override
public JavaType getInputType(TypeFactory typeFactory) {
    return typeFactory.constructMapType(SingleKeyHashMap.class, String.class, JsonMessage.class);
}
 
Example 17
Source File: Converters.java    From sailfish-core with Apache License 2.0 4 votes vote down vote up
@Override
public JavaType getInputType(TypeFactory typeFactory) {
    return typeFactory.constructMapType(SingleKeyHashMap.class, String.class, JsonField.class);
}
 
Example 18
Source File: Converters.java    From sailfish-core with Apache License 2.0 4 votes vote down vote up
@Override
public JavaType getInputType(TypeFactory typeFactory) {
    return typeFactory.constructMapType(SingleKeyHashMap.class, String.class, JsonAttribute.class);
}