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:com.vmware.photon.controller.api.client.resource.ResourceTicketRestApi.java

/**
 * Get details about the specified resource ticket.
 *
 * @param resourceTicketId//w w  w . ja v a  2s .c o  m
 * @return Resource ticket details
 * @throws IOException
 */
@Override
public ResourceTicket getResourceTicket(String resourceTicketId) throws IOException {
    String path = String.format("%s/%s", getBasePath(), resourceTicketId);

    HttpResponse httpResponse = this.restClient.perform(RestClient.Method.GET, path, null);
    this.restClient.checkResponse(httpResponse, HttpStatus.SC_OK);

    return this.restClient.parseHttpResponse(httpResponse, new TypeReference<ResourceTicket>() {
    });
}

From source file:com.chalmers.feedlr.parser.FacebookJSONParser.java

public List<FacebookItem> parseFeed(String json) {
    long time = System.currentTimeMillis();

    if (itemReader == null) {
        itemReader = mapper.reader(new TypeReference<List<FacebookItem>>() {
        });//from w ww. j  a  v  a2 s .c  o  m
    }

    List<FacebookItem> list = null;

    if (json.contains("statuses")) {
        String data = json.substring(json.indexOf("statuses") + 18);
        try {
            list = itemReader.readValue(data);
            Log.i(FacebookJSONParser.class.getName(), "Parsed " + list.size() + " Facebook items in "
                    + (System.currentTimeMillis() - time) + " millis.");
        } catch (JsonParseException e) {
            Log.e(getClass().getName(), e.getMessage());
        } catch (JsonMappingException e) {
            Log.e(getClass().getName(), e.getMessage());
        } catch (IOException e) {
            Log.e(getClass().getName(), e.getMessage());
        }
    }

    return list;
}

From source file:com.amazon.kinesis.streaming.agent.config.Configuration.java

/**
 * Build a configuration from an input stream containing JSON.
 *
 * @param is/*ww w.ja  va 2s.com*/
 * @return
 * @throws IOException
 */
@SuppressWarnings("unchecked")
public static Configuration get(InputStream is) throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    mapper.configure(Feature.ALLOW_COMMENTS, true);
    return new Configuration(
            (Map<String, Object>) mapper.readValue(is, new TypeReference<HashMap<String, Object>>() {
            }));
}

From source file:com.xeiam.xchange.rest.JSONUtils.java

/**
 * Get a generic map holding the raw data from the JSON string to allow manual type differentiation
 * /*from  www  .  j  ava2  s . c  o m*/
 * @param jsonString The JSON string
 * @param objectMapper The object mapper
 * @return The map
 */
public static Map<String, Object> getJsonGenericMap(String jsonString, ObjectMapper objectMapper) {

    Assert.notNull(jsonString, "jsonString cannot be null");
    Assert.notNull(objectMapper, "objectMapper cannot be null");
    try {
        return objectMapper.readValue(jsonString, new TypeReference<Map<String, Object>>() {
        });
    } catch (IOException e) {
        // Rethrow as runtime exception
        throw new ExchangeException("Problem getting JSON generic map", e);
    }
}

From source file:org.jvalue.ods.adapter.PegelOnlineAdapter.java

/**
 * Gets the stations.//from  w ww.j  ava 2 s.  com
 * 
 * @return the stations
 * @throws JsonParseException
 *             the json parse exception
 * @throws JsonMappingException
 *             the json mapping exception
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 */
public List<Station> getStationData() throws JsonParseException, JsonMappingException, IOException {
    HttpJsonAdapter httpAdapter = new HttpJsonAdapter(
            "http://www.pegelonline.wsv.de/webservices/rest-api/v2/stations.json?includeTimeseries=true&includeCurrentMeasurement=true");
    String json = httpAdapter.getJSON("UTF-8");

    ObjectMapper mapper = new ObjectMapper();
    List<Station> stationData = mapper.readValue(json, new TypeReference<List<Station>>() {
    });
    return stationData;
}

From source file:org.apache.calcite.adapter.elasticsearch.ElasticsearchSchemaFactory.java

@Override
public Schema create(SchemaPlus parentSchema, String name, Map<String, Object> operand) {

    final Map map = (Map) operand;

    final ObjectMapper mapper = new ObjectMapper();
    mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);

    try {//from w  w  w .  j  av a  2s .c  o  m
        final Map<String, Integer> coordinates = mapper.readValue((String) map.get("coordinates"),
                new TypeReference<Map<String, Integer>>() {
                });

        final RestClient client = connect(coordinates);

        final Map<String, String> userConfig = mapper.readValue((String) map.get("userConfig"),
                new TypeReference<Map<String, String>>() {
                });

        final String index = (String) map.get("index");
        Preconditions.checkArgument(index != null, "index is missing in configuration");
        return new ElasticsearchSchema(client, new ObjectMapper(), index);
    } catch (IOException e) {
        throw new RuntimeException("Cannot parse values from json", e);
    }
}

From source file:gov.nist.healthcare.ttt.webapp.common.controller.GetCCDADocumentsController.java

@RequestMapping(method = RequestMethod.GET, produces = "application/json")
public @ResponseBody HashMap<String, Object> getDocuments() throws Exception {
    // Result map
    HashMap<String, Object> resultMap = new HashMap<>();

    // CCDA cache File path
    String ccdaFilePath = ccdaFileDirectory + File.separator + "ccda_objectives.txt";
    File ccdaObjectivesFile = new File(ccdaFilePath);

    if (ccdaObjectivesFile.exists() && !ccdaObjectivesFile.isDirectory()) {
        JsonFactory factory = new JsonFactory();
        ObjectMapper mapper = new ObjectMapper(factory);
        TypeReference<HashMap<String, Object>> typeRef = new TypeReference<HashMap<String, Object>>() {
        };/*from   w w w  .  j  a v a 2  s.c  o m*/

        resultMap = mapper.readValue(ccdaObjectivesFile, typeRef);
    } else {
        String sha = getHTML(
                "https://api.github.com/repos/siteadmin/2015-Certification-C-CDA-Test-Data/branches/master")
                        .getJSONObject("commit").get("sha").toString();
        JSONArray filesArray = getHTML(
                "https://api.github.com/repos/siteadmin/2015-Certification-C-CDA-Test-Data/git/trees/" + sha
                        + "?recursive=1").getJSONArray("tree");

        for (int i = 0; i < filesArray.length(); i++) {
            JSONObject file = filesArray.getJSONObject(i);
            if (!files2ignore.contains(file.get("path"))) {
                // Get path array
                String[] path = file.get("path").toString().split("/");
                buildJson(resultMap, path);
            }

        }
        // Write the cache file
        try {
            JSONObject cacheFile = new JSONObject(resultMap);
            FileUtils.writeStringToFile(ccdaObjectivesFile, cacheFile.toString(2));
        } catch (Exception e) {
            logger.error("Could not create ccda cache file: " + e.getMessage());
            e.printStackTrace();
        }
    }
    return resultMap;
}

From source file:com.github.nmorel.gwtjackson.jackson.advanced.GenericsJacksonTest.java

@Test
public void testSerializeIntegerString() {
    GenericsTester.INSTANCE//from ww  w.j av  a2 s  . co  m
            .testSerializeIntegerString(createWriter(new TypeReference<GenericTwoType<Integer, String>>() {
            }));
}

From source file:uk.co.sdev.async.http.ning.Sequential3CompletableFutureClientTest.java

@Override
protected CompletableFuture<Optional<Review>> getReview(String ref) throws IOException {
    return completableFutureClient
            .get("http://localhost:9101/review/" + ref, new TypeReference<Optional<Review>>() {
            }).handle(withFallback(Optional.<Review>empty()));
}

From source file:cherry.foundation.testtool.stub.StubConfigurer.java

public void configure() throws IOException {
    for (Resource r : resources) {
        if (!r.exists()) {
            continue;
        }/*from  www  . j av  a2 s  .c o m*/
        try (InputStream in = r.getInputStream()) {
            Map<Class<?>, Map<String, Object>> map = objectMapper.readValue(in,
                    new TypeReference<LinkedHashMap<Class<?>, Map<String, Object>>>() {
                    });
            for (Map.Entry<Class<?>, Map<String, Object>> entry : map.entrySet()) {
                Multimap<String, Method> methodMap = createMethodMap(entry.getKey().getDeclaredMethods());
                for (Map.Entry<String, Object> ent : entry.getValue().entrySet()) {
                    if (!methodMap.containsKey(ent.getKey())) {
                        continue;
                    }
                    for (Method method : methodMap.get(ent.getKey())) {
                        JavaType type = objectMapper.getTypeFactory()
                                .constructType(method.getGenericReturnType());
                        List<Config> cfglist = parseConfig(ent.getValue());
                        for (Config cfg : cfglist) {
                            Object v = parseValue(cfg, type);
                            if (cfglist.size() == 1) {
                                repository.get(method).alwaysReturn(v);
                            } else {
                                repository.get(method).thenReturn(v);
                            }
                        }
                    }
                }
            }
        }
    }
}