/** * Convenience method for traversing over given {@link TreeNode} by exposing * contents as a {@link JsonParser}. *<p> * NOTE! Returned parser has not been advanced to the first token; caller has to * do this. */ default JsonParser treeAsTokens(TreeNode n) { return n.traverse(this); }
protected Object _deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { final TreeNode treeNode = p.readValueAsTree(); final TreeNode typeNode = treeNode.path("type"); if (!typeNode.isObject()) { ctxt.reportWrongTokenException(typeNode.traverse(), JsonToken.START_OBJECT, "expected START_OBJECT before the type information and deserialized value"); } final TreeNode valueNode = typeNode.path("@value"); if (!valueNode.isValueNode()) { ctxt.reportWrongTokenException(typeNode.traverse(), JsonToken.VALUE_STRING, "expected VALUE_STRING as type information and deserialized value"); } final JsonParser jsonParser = valueNode.traverse(); final String typeId = jsonParser.nextTextValue(); final JsonDeserializer<Object> deser = _findDeserializer(ctxt, typeId); final JsonParser newParser = treeNode.traverse(); if (newParser.nextToken() != JsonToken.START_OBJECT) { ctxt.reportWrongTokenException(newParser, JsonToken.START_OBJECT, "expected START_OBJECT"); } return deser.deserialize(newParser, ctxt); } }
public static <T> T readJSON(TreeNode t, Class<T> klass) throws IOException { return JSON_MAPPER.readValue(t.traverse(), klass); }
/** * @param jsonString serialized bandwidth specification. * @return the bandwidth specification. */ static BandwidthSpecification fromJsonString(final String jsonString) { final BandwidthSpecification specification = new BandwidthSpecification(); try { final ObjectMapper objectMapper = new ObjectMapper(); final TreeNode jsonRootNode = objectMapper.readTree(jsonString); for (int i = 0; i < jsonRootNode.size(); i++) { final TreeNode locationNode = jsonRootNode.get(i); final String name = locationNode.get("name").traverse().nextTextValue(); final int up = locationNode.get("up").traverse().getIntValue(); final int down = locationNode.get("down").traverse().getIntValue(); specification.nodeNames.add(name); specification.uplinkBandwidth.put(name, up); specification.downlinkBandwidth.put(name, down); } } catch (final IOException e) { throw new RuntimeException(e); } return specification; }
/** * @param jsonString serialized bandwidth specification. * @return the bandwidth specification. */ static BandwidthSpecification fromJsonString(final String jsonString) { final BandwidthSpecification specification = new BandwidthSpecification(); try { final ObjectMapper objectMapper = new ObjectMapper(); final TreeNode jsonRootNode = objectMapper.readTree(jsonString); for (int i = 0; i < jsonRootNode.size(); i++) { final TreeNode locationNode = jsonRootNode.get(i); final String name = locationNode.get("name").traverse().nextTextValue(); final int up = locationNode.get("up").traverse().getIntValue(); final int down = locationNode.get("down").traverse().getIntValue(); specification.nodeNames.add(name); specification.uplinkBandwidth.put(name, up); specification.downlinkBandwidth.put(name, down); } } catch (final IOException e) { throw new RuntimeException(e); } return specification; }
final String type = resourceNode.get("type").traverse().nextTextValue(); final int memory = resourceNode.get("memory_mb").traverse().getIntValue(); final int capacity = resourceNode.get("capacity").traverse().getIntValue(); final int executorNum = resourceNode.path("num").traverse().nextIntValue(1); final int poisonSec = resourceNode.path("poison_sec").traverse().nextIntValue(-1); resourceRequestCount.getAndAdd(executorNum); containerManager.requestContainer(executorNum, new ResourceSpecification(type, capacity, memory, poisonSec));
final String type = resourceNode.get("type").traverse().nextTextValue(); final int memory = resourceNode.get("memory_mb").traverse().getIntValue(); final int capacity = resourceNode.get("capacity").traverse().getIntValue(); final int executorNum = resourceNode.path("num").traverse().nextIntValue(1); final int poisonSec = resourceNode.path("poison_sec").traverse().nextIntValue(-1); resourceRequestCount.getAndAdd(executorNum); containerManager.requestContainer(executorNum, new ResourceSpecification(type, capacity, memory, poisonSec));
if (!key.equals(typesNodeName)) { final TreeNode fieldNode = readTree.get(key); final JsonParser fieldValueParser = fieldNode.traverse(); fieldValueParser.setCodec(jp.getCodec());