ObjectMapper mapper = new ObjectMapper(); ArrayNode arrayNode = mapper.createArrayNode(); Object obj = new Object(); arrayNode.addPOJO(obj); arrayNode.add(mapper.createObjectNode().put("field1", "Hello Stack!"));
public static ArrayNode createV1ArrayNode(Collection<?> array) { ArrayNode ret = mapper.createArrayNode(); for (Object elem : array) { ret.addPOJO(elem); } return ret; }
public static ArrayNode createV1ArrayNode(Collection<?> array) { ArrayNode ret = mapper.createArrayNode(); for (Object elem : array) { ret.addPOJO(elem); } return ret; }
/** * Builds an ArrayNode from all positional arguments in a WAMP message.<br> * If there are no positional arguments then null will be returned, as * WAMP requires no empty arguments list to be transmitted. * @param args All positional arguments * @return An ArrayNode containing positional arguments or null */ public static ArrayNode buildArgumentsArray(ObjectMapper objectMapper, Object... args) { if (args.length == 0) return null; // Build the arguments array and serialize the arguments final ArrayNode argArray = objectMapper.createArrayNode(); for (Object arg : args) { argArray.addPOJO(arg); } return argArray; } }
/** * Builds an ArrayNode from all positional arguments in a WAMP message.<br> * If there are no positional arguments then null will be returned, as * WAMP requires no empty arguments list to be transmitted. * @param args All positional arguments * @return An ArrayNode containing positional arguments or null */ public static ArrayNode buildArgumentsArray(ObjectMapper objectMapper, Object... args) { if (args.length == 0) return null; // Build the arguments array and serialize the arguments final ArrayNode argArray = objectMapper.createArrayNode(); for (Object arg : args) { argArray.addPOJO(arg); } return argArray; } }
/** * Builds an ArrayNode from all positional arguments in a WAMP message.<br> * If there are no positional arguments then null will be returned, as * WAMP requires no empty arguments list to be transmitted. * @param args All positional arguments * @return An ArrayNode containing positional arguments or null */ public static ArrayNode buildArgumentsArray(ObjectMapper objectMapper, Object... args) { if (args.length == 0) return null; // Build the arguments array and serialize the arguments final ArrayNode argArray = objectMapper.createArrayNode(); for (Object arg : args) { argArray.addPOJO(arg); } return argArray; } }
ObjectMapper mapper = new ObjectMapper(); ArrayNode arrayNode = mapper.createArrayNode(); Object obj = new Object(); arrayNode.add(mapper.createObjectNode().put("version", "Hello Stack!")); arrayNode.addPOJO(obj); arrayNode.get(0).get("version");
public String toJson(ObjectMapper mapper) { ObjectNode rootNode = mapper.createObjectNode(); ArrayNode keysNode = rootNode.putArray("keys"); for (Object key : keys) { keysNode.addPOJO(key); } try { return mapper.writeValueAsString(rootNode); } catch (Exception e) { throw Exceptions.propagate(e); } } }
@JsonValue public JsonNode toJson() { ArrayNode key = mapper.createArrayNode(); for (Object component : components) { if (component == EMPTY_OBJECT) { key.addObject(); } else { key.addPOJO(component); } } return key; } }
OhlcItem ohlcBean = (OhlcItem) bean; ArrayNode jsonArray = JsonNodeFactory.instance.arrayNode(); jsonArray.addPOJO(ohlcBean.getX()); jsonArray.addPOJO(ohlcBean.getOpen()); jsonArray.addPOJO(ohlcBean.getHigh()); jsonArray.addPOJO(ohlcBean.getLow()); jsonArray.addPOJO(ohlcBean.getClose()); jgen.writeTree(jsonArray); if (x != null) { ArrayNode jsonArray = JsonNodeFactory.instance.arrayNode(); jsonArray.addPOJO(x); if (y != null) { jsonArray.addPOJO(y); } else if (bean.getLow() != null) { jsonArray.addPOJO(bean.getLow()); jsonArray.addPOJO(bean.getHigh()); } else { jsonArray.addNull(); } else { ArrayNode jsonArray = JsonNodeFactory.instance.arrayNode(); jsonArray.addPOJO(bean.getLow()); jsonArray.addPOJO(bean.getHigh()); jgen.writeTree(jsonArray);
private HttpResponse handleVisit(RestUri restUri, HttpRequest request) throws RestApiException { String documentSelection; OperationHandler.VisitOptions options; try { documentSelection = documentSelectionFromRequest(restUri, request); options = visitOptionsFromRequest(request); } catch (BadRequestParameterException e) { return createInvalidParameterResponse(e.getParameter(), e.getMessage()); } final OperationHandler.VisitResult visit = operationHandler.visit(restUri, documentSelection, options); final ObjectNode resultNode = mapper.createObjectNode(); visit.token.ifPresent(t -> resultNode.put(CONTINUATION, t)); resultNode.putArray(DOCUMENTS).addPOJO(visit.documentsAsJsonList); resultNode.put(PATH_NAME, restUri.getRawPath()); HttpResponse httpResponse = new HttpResponse(200) { @Override public String getContentType() { return APPLICATION_JSON; } @Override public void render(OutputStream outputStream) throws IOException { try { outputStream.write(resultNode.toString().getBytes(StandardCharsets.UTF_8)); } catch (Exception e) { throw new RuntimeException(e); } } }; return httpResponse; } }
activitiesJSON.addPOJO(aid);
private boolean resolveAssociation(Association association) { ObjectNode objectNode = association.getFirstResource().getObjectNode(); String fieldName = association.getJsonField().getFirstValue(); Object fieldValue = association.getJsonField().getSecondValue(); AssociationType associationType = association.getAssociationType(); JsonNode jsonNode = objectNode.get(fieldName); switch(associationType) { case OneToMany: case ManyToMany: //add to json associations if(jsonNode != null && jsonNode instanceof ArrayNode) { ArrayNode arrayNode = (ArrayNode)jsonNode; arrayNode.addPOJO(fieldValue); } else { objectNode.putArray(fieldName).addPOJO(fieldValue); } association.markAsResolved(); return true; case ManyToOne: //add to json association objectNode.putPOJO(fieldName, fieldValue); association.markAsResolved(); return true; case OneToOne: throw new RestlerException("Unsupported association oneToOne."); } return false; }