Example usage for com.fasterxml.jackson.databind JsonNode toString

List of usage examples for com.fasterxml.jackson.databind JsonNode toString

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind JsonNode toString.

Prototype

public abstract String toString();

Source Link

Usage

From source file:bz.tsung.jsonapi4j.serialization.DataDeserializer.java

@Override
public Data<Resource> deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
        throws IOException {
    JsonNode node = jsonParser.getCodec().readTree(jsonParser);
    ObjectMapper mapper = new MappingJsonFactory().getCodec();
    if (node.isArray()) {
        List<Resource> resources = new ArrayList<Resource>();
        for (JsonNode n : node) {
            Resource r = mapper.readValue(n.toString(), Resource.class);
            resources.add(r);/*from ww  w .jav  a  2s  . c  o m*/
        }
        return new Data<Resource>(resources);
    }
    Resource resource = mapper.readValue(node.toString(), Resource.class);
    return new Data<Resource>(resource);
}

From source file:com.github.pires.example.dal.entities.JSONObjectDeserializer.java

@Override
public JSONObject deserialize(JsonParser jp, DeserializationContext ctxt)
        throws IOException, JsonProcessingException {
    ObjectCodec oc = jp.getCodec();//  w ww . j  a  v a 2 s.  c  o  m
    JsonNode node = oc.readTree(jp);

    JSONObject result = new JSONObject(node.toString());

    return result;
}

From source file:com.redhat.lightblue.query.QueryExpression.java

/**
 * Parses a query expression from the given json node
 *//* w ww  .  j  a  v a2  s.  co m*/
public static QueryExpression fromJson(JsonNode node) {
    if (node instanceof ObjectNode) {
        ObjectNode onode = (ObjectNode) node;
        // If there is only one field, then that field must be a
        // logical operator
        String firstField = onode.fieldNames().next();
        if (UnaryLogicalOperator.fromString(firstField) != null) {
            return UnaryLogicalExpression.fromJson(onode);
        } else if (NaryLogicalOperator.fromString(firstField) != null) {
            return NaryLogicalExpression.fromJson(onode);
        } else {
            return ComparisonExpression.fromJson(onode);
        }
    } else {
        throw Error.get(QueryConstants.ERR_INVALID_QUERY, node.toString());
    }
}

From source file:com.logsniffer.model.support.JsonLogPointer.java

/**
 * @param json// ww w.  j a v  a 2 s.  c  o  m
 *            the json to set
 */
public void setJson(final JsonNode node) {
    this.json = node.toString();
}

From source file:com.frank.search.solr.core.schema.MappingJacksonRequestContentParser.java

@Override
public StringStream parse(Object content) {

    JsonNode node = mapper.convertValue(content, JsonNode.class);
    return new StringStream(node.toString());
}

From source file:es.bsc.amon.controller.QueriesDBMapper.java

/**
 * Uses the MongoDB Json query language//ww w .j a  v  a2  s  . c  om
 * @param query
 * @return
 */
public ArrayNode aggregate(JsonNode query) {
    Object raw = JSON.parse(query.toString());
    ArrayNode ret = new ArrayNode(JsonNodeFactory.instance);

    if (raw instanceof BasicDBObject) {
        ret = (ArrayNode) Json.parse(EventsDBMapper.getInstance().aggregate((BasicDBObject) raw).toString());
    } else if (raw instanceof BasicDBList) {
        ret = (ArrayNode) Json.parse(EventsDBMapper.getInstance().aggregate((BasicDBList) raw).toString());
    }

    return ret;
}

From source file:org.switchyard.quickstarts.transform.datamapper.FileBindingsTest.java

private String jsonUnprettyPrint(String jsonString) throws JsonProcessingException, IOException {
    ObjectMapper mapper = new ObjectMapper();
    mapper.configure(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS, true);
    JsonNode node = mapper.readTree(jsonString);
    return node.toString();
}

From source file:com.evrythng.java.wrapper.mapping.ActionsDeserializer.java

@Override
public Actions deserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException {

    ObjectMapper mapper = JSONUtils.OBJECT_MAPPER;
    JsonNode node = mapper.readTree(jp);
    if (node.isArray()) {
        return mapper.readValue(node.toString(), ActionsImpl.class);
    } else {/*from  ww w  .jav a 2  s .  com*/
        ArrayNode array = mapper.createArrayNode();
        array.add(node);
        return mapper.readValue(array.toString(), ActionsImpl.class);
    }
}

From source file:TreeTest.java

@Test
public void parseUnparseTest() {
    String src = "{\"a\":\"b\",\"c\":3.0001,\"d\":[1,2,3,\"txt\"]"
            + ",\"f\":{\"a\":3,\"b\":\"other text\",\"c\":[\"a\",\"b\",1,{\"a\":\"b\"}]}}";
    TreeNode tn = TreeNodeFactory.fromJson(src);
    JsonNode jn2 = TreeNodeFactory.toJson(tn);
    assertThat(src).isEqualTo(jn2.toString());

}

From source file:org.createnet.raptor.models.data.ActionStatusTest.java

@Test
public void testParseActionStatus() throws IOException {

    JsonNode json = loadData("actionStatus");

    ActionStatus status = ActionStatus.parseJSON(json.toString());

    String statusPublic = status.toJSON();
    JsonNode statusPublicJson = ServiceObject.getMapper().readTree(statusPublic);

    assertTrue(statusPublicJson.has("actionId"));

}