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

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

Introduction

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

Prototype

public JsonNode readTree(URL source) throws IOException, JsonProcessingException 

Source Link

Document

Method to deserialize JSON content as tree expressed using set of JsonNode instances.

Usage

From source file:com.trusolve.ant.filters.SynapseAPISwaggerFilter.java

public static Reader readDocument(Reader in) throws JsonProcessingException, IOException {
    ObjectMapper jsonIn = new ObjectMapper();
    JsonNode jn = jsonIn.readTree(in);

    fixGetPaths(jn);/*  w  w  w  .  java2s  . c om*/

    jsonIn.enable(SerializationFeature.INDENT_OUTPUT);

    return new StringReader(jsonIn.writeValueAsString(jn));
}

From source file:test.LocationCrawler.java

public static String getLocationCoord(String Address) {
    String jsonString = ProcessLocationRequest(Address);
    String LocationCoord = "";

    if (jsonString.length() > 0) {
        try {/*from   ww w .  j a  v a  2 s .  c o m*/
            ObjectMapper m = new ObjectMapper();
            JsonNode rootNode = m.readTree(jsonString);
            for (JsonNode result : rootNode.path("results")) {
                JsonNode LatLongNode = result.path("geometry").path("location");
                LocationCoord = String.format("%s|%s", LatLongNode.path("lat").doubleValue(),
                        LatLongNode.path("lng").doubleValue());
                break;
            }

        } catch (JsonProcessingException jpe) {
            System.out.println(jpe.getMessage());
        } catch (IOException ioe) {
            System.out.println(ioe.getMessage());
        } catch (Exception e) {
            System.out.println(e.getMessage());
        } finally {
            return LocationCoord;
        }
    } else {
        return LocationCoord;
    }
}

From source file:com.amazonaws.services.iot.client.shadow.AwsIotJsonDeserializer.java

public static long deserializeVersion(AbstractAwsIotDevice device, String jsonState) throws IOException {
    ObjectMapper jsonObjectMapper = device.getJsonObjectMapper();

    JsonNode node = jsonObjectMapper.readTree(jsonState);
    if (node == null) {
        throw new IOException("Invalid shadow document received for " + device.getThingName());
    }//  w  ww. j  av  a2  s .  c o m

    JsonNode versionNode = node.get("version");
    if (versionNode == null) {
        throw new IOException("Missing version field from shadow document for " + device.getThingName());
    }

    return versionNode.asLong();
}

From source file:com.ignorelist.kassandra.steam.scraper.JsonApiTagLoader.java

private static Data loadAppData(byte[] data) throws MalformedURLException, IOException {
    ObjectMapper mapper = buildMapper();
    final JsonNode tree = mapper.readTree(data);
    return mapper.treeToValue(tree.findValue("data"), Data.class);
}

From source file:com.ignorelist.kassandra.steam.scraper.JsonApiTagLoader.java

private static Data loadAppData(InputStream data) throws MalformedURLException, IOException {
    ObjectMapper mapper = buildMapper();
    final JsonNode tree = mapper.readTree(data);
    return mapper.treeToValue(tree.findValue("data"), Data.class);
}

From source file:edu.usu.sdl.openstorefront.util.ServiceUtil.java

public static String stripeFieldJSON(String json, Set<String> fieldsToKeep) {
    ObjectMapper mapper = defaultObjectMapper();

    try {/* w  w  w. j  av a  2  s.c om*/
        JsonNode rootNode = mapper.readTree(json);
        processNode(rootNode, fieldsToKeep);

        Object jsonString = mapper.readValue(rootNode.toString(), Object.class);
        return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(jsonString);
    } catch (IOException ex) {
        throw new OpenStorefrontRuntimeException(ex);
    }
}

From source file:com.amazonaws.services.iot.client.shadow.AwsIotJsonDeserializer.java

public static void deserialize(AbstractAwsIotDevice device, String jsonState) throws IOException {
    ObjectMapper jsonObjectMapper = device.getJsonObjectMapper();

    JsonNode node = jsonObjectMapper.readTree(jsonState);
    if (node == null) {
        throw new IOException("Invalid delta update received for " + device.getThingName());
    }//from w ww .ja v a 2  s  . c  om

    for (Iterator<String> it = node.fieldNames(); it.hasNext();) {
        String property = it.next();
        Field field = device.getUpdatableProperties().get(property);
        JsonNode fieldNode = node.get(property);
        if (field == null || fieldNode == null) {
            continue;
        }

        updateDeviceProperty(jsonObjectMapper, fieldNode, device, field);
    }
}

From source file:software.uncharted.util.HTTPUtil.java

public static JsonNode getJSON(String url) throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    String jsonStr = get(url);/*from ww  w.ja  va  2s . c  om*/
    return mapper.readTree(jsonStr);
}

From source file:org.gyt.schema.json.Utils.java

public static JsonNode getJsonNode(String json) throws JsonProcessingException, IOException {

    ObjectMapper mapper = new ObjectMapper();

    JsonNode actualJsonNode = mapper.readTree(json);

    return actualJsonNode;

}

From source file:org.jboss.aerogear.io.netty.handler.codec.sockjs.handler.InfoTest.java

private static JsonNode infoAsJson(final FullHttpResponse response) throws Exception {
    final ObjectMapper om = new ObjectMapper();
    return om.readTree(response.content().toString(CharsetUtil.UTF_8));
}