use of com.fasterxml.jackson.core.TreeNode in project jackson-databind by FasterXML.
the class TestBeanConversions method testNodeConvert.
// [Issue-11]: simple cast, for Tree
public void testNodeConvert() throws Exception {
ObjectNode src = (ObjectNode) MAPPER.readTree("{}");
TreeNode node = src;
ObjectNode result = MAPPER.treeToValue(node, ObjectNode.class);
// should just cast...
assertSame(src, result);
}
use of com.fasterxml.jackson.core.TreeNode in project beam by apache.
the class TestPipeline method convertToArgs.
public static String[] convertToArgs(PipelineOptions options) {
try {
byte[] opts = MAPPER.writeValueAsBytes(options);
JsonParser jsonParser = MAPPER.getFactory().createParser(opts);
TreeNode node = jsonParser.readValueAsTree();
ObjectNode optsNode = (ObjectNode) node.get("options");
ArrayList<String> optArrayList = new ArrayList<>();
Iterator<Entry<String, JsonNode>> entries = optsNode.fields();
while (entries.hasNext()) {
Entry<String, JsonNode> entry = entries.next();
if (entry.getValue().isNull()) {
continue;
} else if (entry.getValue().isTextual()) {
optArrayList.add("--" + entry.getKey() + "=" + entry.getValue().asText());
} else {
optArrayList.add("--" + entry.getKey() + "=" + entry.getValue());
}
}
return optArrayList.toArray(new String[optArrayList.size()]);
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
use of com.fasterxml.jackson.core.TreeNode in project realm-java by realm.
the class RealmListNYTimesMultimediumDeserializer method deserialize.
@Override
public List<NYTimesMultimedium> deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
RealmList<NYTimesMultimedium> list = new RealmList<>();
TreeNode treeNode = jp.getCodec().readTree(jp);
if (!(treeNode instanceof ArrayNode)) {
return list;
}
ArrayNode arrayNode = (ArrayNode) treeNode;
for (JsonNode node : arrayNode) {
NYTimesMultimedium nyTimesMultimedium = objectMapper.treeToValue(node, NYTimesMultimedium.class);
list.add(nyTimesMultimedium);
}
return list;
}
use of com.fasterxml.jackson.core.TreeNode in project Gaffer by gchq.
the class HyperLogLogPlusJsonDeserialiser method deserialize.
// TODO - See 'Can't create HyperLogLogPlus sketches in JSON'
@Override
public HyperLogLogPlus deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
final TreeNode treeNode = jsonParser.getCodec().readTree(jsonParser);
final TreeNode coreHyperLogLogPlusObject = treeNode.get("hyperLogLogPlus");
if (coreHyperLogLogPlusObject != null) {
final TextNode jsonNodes = (TextNode) coreHyperLogLogPlusObject.get(HyperLogLogPlusJsonConstants.HYPER_LOG_LOG_PLUS_SKETCH_BYTES_FIELD);
final byte[] nodeAsString = jsonNodes.binaryValue();
final HyperLogLogPlus hyperLogLogPlus = HyperLogLogPlus.Builder.build(nodeAsString);
return hyperLogLogPlus;
} else {
throw new IllegalArgumentException("Recieved null or empty HyperLogLogPlus sketch");
}
}
use of com.fasterxml.jackson.core.TreeNode in project steve by RWTH-i5-IDSG.
the class Deserializer method handleError.
/**
* Do NOT catch and handle exceptions for incoming RESPONSEs. Let the processing fail.
* There is no mechanism in OCPP to report back such erroneous messages.
*/
private void handleError(CommunicationContext context, String messageId, JsonParser parser) {
FutureResponseContext responseContext = futureResponseContextStore.get(context.getSession(), messageId);
if (responseContext == null) {
throw new SteveException("An error message was received as response to a not-sent call. The message was: %s", context.getIncomingString());
}
ErrorCode code;
String desc;
String details = null;
try {
parser.nextToken();
code = ErrorCode.fromValue(parser.getText());
parser.nextToken();
desc = parser.getText();
// ErrorDescription - Should be filled in if possible, otherwise a clear empty string "".
if ("".equals(desc)) {
desc = null;
}
// From spec:
// ErrorDetails - This JSON object describes error details in an undefined way.
// If there are no error details you should fill in an empty object {}, missing or null is not allowed
parser.nextToken();
TreeNode detailsNode = parser.readValueAsTree();
if (detailsNode != null && detailsNode.size() != 0) {
details = mapper.writeValueAsString(detailsNode);
}
} catch (IOException e) {
throw new SteveException("Deserialization of incoming error message failed", e);
}
OcppJsonError error = new OcppJsonError();
error.setMessageId(messageId);
error.setErrorCode(code);
error.setErrorDescription(desc);
error.setErrorDetails(details);
context.setIncomingMessage(error);
context.createErrorHandler(responseContext.getTask());
}
Aggregations