List of usage examples for com.fasterxml.jackson.databind JsonNode toString
public abstract String toString();
From source file:org.jboss.aerogear.unifiedpush.rest.util.RequestTransformer.java
private StringBuilder convertToStringBuilder(JsonNode dynamicTransformedNode) { return new StringBuilder(dynamicTransformedNode.toString()); }
From source file:org.jasig.portlet.survey.service.dto.ResponseAnswerDtoDeserializer.java
@Override public ResponseAnswerDTO deserialize(JsonParser parser, DeserializationContext context) throws IOException, JsonProcessingException { log.debug("deserializing responseAnswer JSON"); JsonNode node = parser.getCodec().readTree(parser); ResponseAnswerDTO dto = new ResponseAnswerDTO(); JsonNode questionNode = node.get("question"); log.debug(questionNode.toString()); if (questionNode != null && questionNode.canConvertToLong()) { Long questionId = questionNode.asLong(); dto.setQuestion(questionId);/* www . j a v a 2 s. co m*/ } else { throw new IllegalArgumentException("ResponseAnswer Json missing/bad question field"); } JsonNode answerNode = node.get("answer"); if (answerNode == null) { throw new IllegalArgumentException("ResponseAnswer Json missing answer field"); } if (answerNode.canConvertToLong()) { dto.addAnswerId(answerNode.asLong()); } else if (answerNode.isObject()) { for (Iterator<Entry<String, JsonNode>> fields = answerNode.fields(); fields.hasNext();) { Entry<String, JsonNode> field = fields.next(); Long answerId = Long.parseLong(field.getKey()); assert (field.getValue().isBoolean()); boolean answerSelected = field.getValue().asBoolean(false); if (answerSelected) { dto.addAnswerId(answerId); } } } else { throw new IllegalArgumentException("ResponseAnswer Json bad answer argument field"); } return dto; }
From source file:com.baidubce.services.moladb.model.transform.AttributeValueMapUnmarshaller.java
@Override public Map<String, AttributeValue> unmarshall(JsonNode jsonObj) throws Exception { if (!jsonObj.isObject()) { throw new BceClientException("input json:" + jsonObj.toString() + " is invalid"); }//w w w. ja v a 2 s .c o m Map<String, AttributeValue> ret = new HashMap<String, AttributeValue>(); Iterator<String> attrs = jsonObj.fieldNames(); while (attrs.hasNext()) { String attrName = attrs.next(); AttributeValueUnmarshaller attrUnmarshaller = new AttributeValueUnmarshaller(); AttributeValue value = attrUnmarshaller.unmarshall(jsonObj.get(attrName)); ret.put(attrName, value); } return ret; }
From source file:com.github.fge.jsonpatch.mergepatch.SerializationTest.java
@Test(dataProvider = "getNonObjectInputs") public void nonObjectSerDeserWorksCorrectly(final JsonNode input) throws IOException { final String in = input.toString(); final JsonMergePatch deserialized = mapper.readValue(in, JsonMergePatch.class); assertNotNull(deserialized);//www .j a va 2 s . co m assertSame(deserialized.getClass(), NonObjectMergePatch.class); final String out = mapper.writeValueAsString(deserialized); final JsonNode serialized = JacksonUtils.getReader().readTree(out); assertTrue(EQUIVALENCE.equivalent(input, serialized)); }
From source file:com.github.fge.jsonpatch.mergepatch.SerializationTest.java
@Test(dataProvider = "getObjectInputs") public void objectSerDeserWorksCorrectly(final JsonNode input) throws IOException { final String in = input.toString(); final JsonMergePatch deserialized = mapper.readValue(in, JsonMergePatch.class); assertNotNull(deserialized);//from w w w .ja va 2 s .c o m assertSame(deserialized.getClass(), ObjectMergePatch.class); final String out = mapper.writeValueAsString(deserialized); final JsonNode serialized = JacksonUtils.getReader().readTree(out); assertTrue(EQUIVALENCE.equivalent(input, serialized)); }
From source file:io.gravitee.definition.jackson.datatype.api.deser.PolicyDeserializer.java
@Override public Policy deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { JsonNode node = jp.getCodec().readTree(jp); Policy policy = new Policy(); node.fieldNames().forEachRemaining(field -> { JsonNode subNode = node.findValue(field); policy.setName(field);// w w w . j a va 2 s.co m policy.setConfiguration(subNode.toString()); System.out.println(field); }); /* policy.setName(node.get("policy").asText()); policy.setConfiguration(node.getget("configuration").toString()); */ return policy; }
From source file:com.turn.shapeshifter.UnmappableValueException.java
/** * @param jsonNode the value node that triggered the error * @param acceptedTokenTypes the set of node types that are considered valid *///www . ja v a2 s . c o m public UnmappableValueException(JsonNode jsonNode, EnumSet<JsonToken> acceptedTokenTypes) { super(COMMA_JOINER.appendTo(new StringBuilder("JSON node with value: '").append(jsonNode.toString()) .append("' cannot be parsed as one of "), acceptedTokenTypes.iterator()).toString()); }
From source file:org.jhk.pulsing.web.serialization.JsonAvroDeserializer.java
@Override public T deserialize(JsonParser parser, DeserializationContext context) throws IOException, JsonProcessingException { JsonNode node = _mapper.readTree(parser); _LOGGER.info("JsonAvroDeserializer.deserialize: " + (node != null ? node.toString() : "")); return SerializationHelper.deserializeFromJSONStringToAvro(_type, _schema, node.toString()); }
From source file:com.ikanow.aleph2.data_model.utils.UuidUtils.java
/** Generates a UUID based on the JSON (warnings: 1) slow, 2) sensitive to field order) * @param binary/* ww w . ja v a 2s. c o m*/ * @return a string representation of the type 3 UUID */ @Override public <T> String getContentBasedUuid(final JsonNode json) { return getContentBasedUuid(json.toString().getBytes()); }
From source file:org.pac4j.oauth.profile.JsonObject.java
/** * Build an object from JSON (String or JsonNode). * // w w w . jav a 2 s.co m * @param json json */ public final void buildFrom(final Object json) { if (json != null) { if (json instanceof String) { final String s = (String) json; buildFromJson(JsonHelper.getFirstNode(s)); } else if (json instanceof JsonNode) { final JsonNode jsonNode = (JsonNode) json; if (keepRawData && isRootObject()) { this.data = jsonNode.toString(); } buildFromJson(jsonNode); } else { throw new TechnicalException(json.getClass() + " not supported"); } } }