@Override public CoinbaseProCandle deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { ObjectMapper mapper = new ObjectMapper(); TreeNode jo = mapper.readTree(jp); if (!jo.isArray() || jo.size() != 6) { throw new JsonMappingException(jp, "An array of length 6 expected: " + jo.toString()); } for (int i = 0; i < 6; i++) { if (!(jo.get(i) instanceof NumericNode)) { throw new JsonMappingException(jp, "Numeric values expected: " + jo.toString()); } } return new CoinbaseProCandle( new Date(((NumericNode) jo.get(0)).asLong() * 1000), new BigDecimal(((NumericNode) jo.get(3)).asText()), new BigDecimal(((NumericNode) jo.get(2)).asText()), new BigDecimal(((NumericNode) jo.get(1)).asText()), new BigDecimal(((NumericNode) jo.get(4)).asText()), new BigDecimal(((NumericNode) jo.get(5)).asText())); } }
@SuppressWarnings("unchecked") private static int nodeSize(Object node) { return ((TreeNode) node).size(); }
@SuppressWarnings("unchecked") private static int nodeSize(Object node) { return ((TreeNode) node).size(); }
@Override public ContentAndMetadata deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { TreeNode treeNode = jsonParser.getCodec().readTree(jsonParser); Preconditions.checkState(treeNode.isArray() && treeNode.size() >= 1, "The response should be an array with at least one element"); Preconditions.checkState(treeNode.get(0).isObject(), "The element should be a Json object"); ObjectNode node = (ObjectNode) treeNode.get(0); return ContentAndMetadata.from(ImmutableList.copyOf(node.fields()) .stream() .collect(Guavate.toImmutableMap(Entry::getKey, entry -> asListOfString(entry.getValue())))); }
private void hash(TreeNode node) { if (node.isArray()) { md.update((byte)'l'); for (int i = 0; i < node.size(); i++) { hash(node.get(i)); } md.update((byte)'e'); } else if (node.isObject()) { String[] fieldNames = new String[node.size()]; Iterator<String> it = node.fieldNames(); for (int i=0; i< fieldNames.length; i++) { fieldNames[i] = it.next(); } Arrays.sort(fieldNames); md.update((byte)'d'); for (String fName : fieldNames) { hash(fName); hash(node.get(fName)); } md.update((byte)'e'); } else if (node.isValueNode()) { String val = ((JsonNode)node).textValue(); if (val != null) { hash(val); } } else { throw new IllegalArgumentException(node.toString()); } }
public boolean parse() throws IOException, JsonProcessingException { JsonParser parser=factory.createParser(input); boolean done=false; do { TreeNode t=parser.readValueAsTree(); if(t==null) { done=true; } else { if(t instanceof ObjectNode) { if(!documentCompleted((ObjectNode)t)) return false; } else if(t instanceof ArrayNode) { int n=t.size(); for(int i=0;i<n;i++) { TreeNode elem=t.path(i); if(elem!=null) { if(!documentCompleted((ObjectNode)elem)) return false; } } } else { throw new RuntimeException("Ill formed stream"); } } } while(!done); return true; }
@Override public GDAXCandle deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { ObjectMapper mapper = new ObjectMapper(); TreeNode jo = mapper.readTree(jp); if (!jo.isArray() || jo.size() != 6) { throw new JsonMappingException(jp, "An array of length 6 expected: " + jo.toString()); } for (int i = 0; i < 6; i++) { if (!(jo.get(i) instanceof NumericNode)) { throw new JsonMappingException(jp, "Numeric values expected: " + jo.toString()); } } return new GDAXCandle( new Date(((NumericNode) jo.get(0)).asLong() * 1000), new BigDecimal(((NumericNode) jo.get(3)).asText()), new BigDecimal(((NumericNode) jo.get(2)).asText()), new BigDecimal(((NumericNode) jo.get(1)).asText()), new BigDecimal(((NumericNode) jo.get(4)).asText()), new BigDecimal(((NumericNode) jo.get(5)).asText())); } }
/** * @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 TreeNode jsonRootNode = objectMapper.readTree(resourceSpecificationString); for (int i = 0; i < jsonRootNode.size(); i++) { final TreeNode resourceNode = jsonRootNode.get(i); final String type = resourceNode.get("type").traverse().nextTextValue();
final TreeNode jsonRootNode = objectMapper.readTree(resourceSpecificationString); for (int i = 0; i < jsonRootNode.size(); i++) { final TreeNode resourceNode = jsonRootNode.get(i); final String type = resourceNode.get("type").traverse().nextTextValue();
if (root != null) { if (root.isArray()) { for (int i=0; i<root.size(); i++) { transform(root.get(i));
private void treeWalk(IRI parentIRI, IRI parentClass, String path, String predicatePath, String label, Integer index, TreeNode node) throws URISyntaxException { if (node.isArray()) { for (int i = 0; i < node.size(); i++) { treeWalk(parentIRI, parentClass, path + ":" + i, predicatePath, label, i, node.get(i));