Example usage for com.fasterxml.jackson.databind ObjectReader readTree

List of usage examples for com.fasterxml.jackson.databind ObjectReader readTree


In this page you can find the example usage for com.fasterxml.jackson.databind ObjectReader readTree.


public JsonNode readTree(String json) throws IOException, JsonProcessingException 

Source Link


Method that reads content from given JSON input String, using configuration of this reader, and binds it as JSON Tree.


From source file:io.fabric8.kubernetes.api.KubernetesHelper.java

 * Returns the given json data as a DTO such as
 * {@link Pod}, {@link ReplicationController} or
 * {@link io.fabric8.kubernetes.api.model.Service}
 * from the Kubernetes REST API or/*from  www  .  ja  va 2s  .  com*/
 * {@link JsonNode} if it cannot be recognised.
public static Object loadJson(byte[] json) throws IOException {
    if (json != null && json.length > 0) {
        ObjectReader reader = objectMapper.reader();
        JsonNode tree = reader.readTree(new ByteArrayInputStream(json));
        if (tree != null) {
            JsonNode kindNode = tree.get("kind");
            if (kindNode != null) {
                String kind = kindNode.asText();
                return loadEntity(json, kind, tree);
            } else {
                LOG.warn("No JSON type for: " + tree);
            return tree;
    return null;

From source file:org.jboss.aerogear.unifiedpush.rest.util.RequestTransformerTest.java

public void shouldTransformSenderRequest() throws IOException {
    //given/*from   w  w  w . j ava  2  s.c om*/
    ObjectReader reader = JacksonUtils.getReader();
    final String json = IOUtils.toString(getClass().getResourceAsStream("/message-format-100.json"));
    StringBuilder current = new StringBuilder(json);

    final StringBuilder patched = requestTransformer.transform("/rest/sender", "100", current);

    final JsonNode patchedNode = reader.readTree(patched.toString());
    JsonNode newNode = reader.readTree(getClass().getResourceAsStream("/new-message-format.json"));

    assertEquals(newNode, patchedNode);

From source file:com.erudika.para.i18n.OXRCurrencyConverter.java

private Sysprop fetchFxRatesJSON() {
    Map<String, Object> map = new HashMap<String, Object>();
    Sysprop s = new Sysprop();
    ObjectReader reader = ParaObjectUtils.getJsonReader(Map.class);

    try {/*from   ww  w. j  a v a 2 s .c om*/
        CloseableHttpClient http = HttpClients.createDefault();
        HttpGet httpGet = new HttpGet(SERVICE_URL);
        HttpResponse res = http.execute(httpGet);
        HttpEntity entity = res.getEntity();

        if (entity != null && Utils.isJsonType(entity.getContentType().getValue())) {
            JsonNode jsonNode = reader.readTree(entity.getContent());
            if (jsonNode != null) {
                JsonNode rates = jsonNode.get("rates");
                if (rates != null) {
                    map = reader.treeToValue(rates, Map.class);
                    //                  s.addProperty("fetched", Utils.formatDate("dd MM yyyy HH:mm", Locale.UK));
        logger.debug("Fetched rates from OpenExchange for {}.", new Date().toString());
    } catch (Exception e) {
        logger.error("TimerTask failed: {}", e);
    return s;

From source file:org.onosproject.drivers.ciena.waveserver.rest.CienaRestDevice.java

private JsonNode get(String uri) throws IOException {
    InputStream response = controller.get(deviceId, uri, MediaType.valueOf(MediaType.APPLICATION_JSON));
    ObjectMapper om = new ObjectMapper();
    final ObjectReader reader = om.reader();
    // all waveserver responses contain data node, which contains the requested data
    return reader.readTree(response).get(DATA);