Example usage for com.fasterxml.jackson.core.type TypeReference TypeReference

List of usage examples for com.fasterxml.jackson.core.type TypeReference TypeReference

Introduction

In this page you can find the example usage for com.fasterxml.jackson.core.type TypeReference TypeReference.

Prototype

protected TypeReference() 

Source Link

Usage

From source file:co.agileventure.jwtauth.web.controller.helper.JsonHelper.java

public Map<String, Object> getResponseEntity(final Response response)
        throws JsonParseException, JsonMappingException, IOException {
    return MAPPER.readValue(response.readEntity(String.class), new TypeReference<Map<String, Object>>() {
    });/*from www.  j  av a2 s  .com*/
}

From source file:com.pangdata.sdk.util.JsonUtils.java

public static String getValueInJsonStr(String key, String jsonStr) {
    Map<String, String> map;
    try {//from w ww .ja  v  a  2s.  c o m
        map = om.readValue(jsonStr, new TypeReference<HashMap<String, String>>() {
        });
    } catch (Exception e) {
        throw new IllegalArgumentException(e);
    }

    if (map != null) {
        return map.get(key);
    } else {
        return null;
    }
}

From source file:org.mayocat.configuration.internal.AbstractConfigurationTest.java

protected Map<String, Serializable> loadConfiguration(String uri) throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    return mapper.readValue(loadJSON(uri), new TypeReference<Map<String, Object>>() {
    });/*from w w w . j  ava 2  s  . com*/
}

From source file:com.amazonaws.services.dynamodbv2.online.index.AttributeValueConverter.java

public static AttributeValue parseFromWithAttributeTypeString(String value) throws IllegalArgumentException {
    try {//from  www  .j av a2  s . c  om
        Map<String, String> valueMap = mapper.readValue(value, new TypeReference<Map<String, String>>() {
        });
        AttributeValue attributeValue = new AttributeValue();
        if (null != valueMap.get("N")) {
            attributeValue.withN(valueMap.get("N"));
        } else if (null != valueMap.get("S")) {
            attributeValue.withS(valueMap.get("S"));
        } else if (null != valueMap.get("B")) {
            attributeValue.withB(encoder.encode(CharBuffer.wrap(valueMap.get("B"))));
        } else if (null != valueMap.get("NS")) {
            List<String> numberSet = mapper.readValue(valueMap.get("NS"), new TypeReference<List<String>>() {
            });
            attributeValue.withNS(numberSet);
        } else if (null != valueMap.get("SS")) {
            List<String> stringSet = mapper.readValue(valueMap.get("SS"), new TypeReference<List<String>>() {
            });
            attributeValue.withSS(stringSet);
        } else if (null != valueMap.get("BS")) {
            List<String> binaryStringSet = mapper.readValue(valueMap.get("BS"),
                    new TypeReference<List<String>>() {
                    });
            List<ByteBuffer> bianrySet = new ArrayList<ByteBuffer>();
            for (String bss : binaryStringSet) {
                bianrySet.add(encoder.encode(CharBuffer.wrap(bss)));
            }
            attributeValue.withBS(bianrySet);
        } else {
            throw new IllegalArgumentException("Error: Invalid Attribute Value Type. ");
        }
        return attributeValue;
    } catch (CharacterCodingException cce) {
        throw new IllegalArgumentException("Error: Failed to encode binary into string.");
    } catch (IOException e) {
        throw new IllegalArgumentException("Error: Failed to parse set from string.");
    }
}

From source file:com.netflix.edda.JsonHelper.java

public static <T> T decode(Class<T> c, InputStream input) throws IOException {
    try {/*from   ww w. j  a  v  a  2  s. c o  m*/
        TypeReference<T> ref = new TypeReference<T>() {
        };
        return createParser(input).readValueAs(ref);
    } finally {
        input.close();
    }
}

From source file:Main.java

/**
 * JSON Deserialization of the given json string.
 * @param   json   The json string to deserialize
 * @return   The deserialized json as a Map */
public static LinkedHashMap<String, Object> deserialize(String json) throws IOException {
    if (isNullOrWhiteSpace(json))
        return null;

    TypeReference<LinkedHashMap<String, Object>> typeRef = new TypeReference<LinkedHashMap<String, Object>>() {
    };//from  www  .  ja va  2  s. c om
    return deserialize(json, typeRef);
}

From source file:es.us.isa.aml.parsers.agreements.yaml.ParserYAMLUtil.java

public static String convertToYaml(String jsonContent) {
    Map<String, String> propertyMap = new HashMap<String, String>();
    ObjectMapper mapper = new ObjectMapper();
    try {//from  w w w. j a va2s  . c  o  m
        propertyMap = mapper.readValue(jsonContent, new TypeReference<HashMap<String, Object>>() {
        });
    } catch (IOException ex) {
        Logger.getLogger(ParserYAMLUtil.class.getName()).log(Level.SEVERE, null, ex);
    }
    Yaml yaml = new Yaml();
    String output = yaml.dump(propertyMap);
    return output;
}

From source file:com.github.nmorel.gwtjackson.guava.jackson.FluentIterableJacksonTest.java

@Test
public void testSerialization() {
    FluentIterableTester.INSTANCE.testSerialization(createWriter(new TypeReference<FluentIterable<Integer>>() {
    }));
}

From source file:net.landora.justintv.JustinTVAPI.java

public static List<JustinArchive> readArchives(String channelName, int offset, int maxNumber) throws Exception {

    String url = String.format("http://api.justin.tv/api/channel/archives/%s.json?offest=%d&limit=%d",
            channelName, offset, Math.min(100, maxNumber));

    InputStream stream = openURL(url);

    ObjectMapper mapper = new ObjectMapper();

    List<JustinArchive> readValue = mapper.readValue(stream, new TypeReference<List<JustinArchive>>() {
    });/*from ww w . ja va2  s. co  m*/

    return readValue;
}

From source file:com.dgtlrepublic.model.test.DataTest.java

@Test
public void validateParsingResults() throws Exception {
    List<Map> testCases = new ObjectMapper().readValue(
            new File(DataTest.class.getResource("/test-cases.json").getPath()), new TypeReference<List<Map>>() {
            });//  w  w w. j a  v  a  2  s  .  com
    System.out.println(String.format("Loaded %s test cases.", testCases.size()));
    long start = System.nanoTime();
    for (Map testCase : testCases) {
        verify(testCase);
    }
    System.out.println(
            String.format("Tests took: %s(ms)", TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start)));
}