public static ObjectNode createResourceNode(String id) { ObjectNode resourceNode = objectMapper.createObjectNode(); resourceNode.put(EDITOR_SHAPE_ID, id); return resourceNode; }
public static ObjectNode createChildShape(String id, String type, double lowerRightX, double lowerRightY, double upperLeftX, double upperLeftY) { ObjectNode shapeNode = objectMapper.createObjectNode(); shapeNode.set(EDITOR_BOUNDS, createBoundsNode(lowerRightX, lowerRightY, upperLeftX, upperLeftY)); shapeNode.put(EDITOR_SHAPE_ID, id); ArrayNode shapesArrayNode = objectMapper.createArrayNode(); shapeNode.set(EDITOR_CHILD_SHAPES, shapesArrayNode); ObjectNode stencilNode = objectMapper.createObjectNode(); stencilNode.put(EDITOR_STENCIL_ID, type); shapeNode.set(EDITOR_STENCIL, stencilNode); return shapeNode; }
private ObjectNode objectSchema(JsonNode exampleObject) { ObjectNode schema = this.objectMapper.createObjectNode(); schema.put("type", "object"); ObjectNode properties = this.objectMapper.createObjectNode(); for (Iterator<String> iter = exampleObject.fieldNames(); iter.hasNext();) { String property = iter.next(); properties.set(property, schemaFromExample(exampleObject.get(property))); } schema.set("properties", properties); return schema; }
@Override public ObjectNode encode(TenantId tenantId, CodecContext context) { checkNotNull(tenantId, NULL_TENANT_MSG); ObjectNode result = context.mapper().createObjectNode() .put(TENANT_ID, tenantId.id()); return result; }
@BeforeEach void setup() { objectNode = new ObjectMapper().createObjectNode(); objectNode.put("kid", "key-id"); objectNode.put("alg", "key-alg"); objectNode.put("enc", "key-encoding"); objectNode.put("iv", "key-init-vector"); objectNode.put("typ", "JWT"); }
@Override public ObjectNode toJSON() { ObjectMapper om = new ObjectMapper(); ObjectNode json = om.createObjectNode(); ObjectNode duration = om.createObjectNode(); duration.put("milliseconds", chrononInMillisecond); json.set("ADuration", duration); return json; }
@Override public ObjectNode encode(RoleInfo roleInfo, CodecContext context) { checkNotNull(roleInfo, "RoleInfo cannot be null"); ObjectNode result = context.mapper().createObjectNode(); if (roleInfo.master() != null) { result.put(MASTER, roleInfo.master().id()); } ArrayNode backups = context.mapper().createArrayNode(); roleInfo.backups().forEach(backup -> backups.add(backup.id())); if (!roleInfo.backups().isEmpty()) { result.set(BACKUPS, backups); } return result; }
/** * Example to writeJson using TreeModel */ private static void writeJson() throws IOException { OutputStream outputStream = new ByteArrayOutputStream(); ObjectMapper mapper = new ObjectMapper(); ObjectNode rootNode = mapper.createObjectNode(); rootNode.put("message", "Hi"); ObjectNode childNode = rootNode.putObject("place"); childNode.put("name", "World!"); mapper.writeValue(outputStream, childNode); System.out.println(outputStream.toString()); // print "{"message":"Hi","place":{"name":"World!"}}" } }
ObjectMapper mapper = new ObjectMapper(); ObjectNode dataTable = mapper.createObjectNode(); ArrayNode aa = dataTable.putArray("aaData");
SimpleModule module = new SimpleModule(); module.addSerializer(new ResultSetSerializer()); ObjectMapper objectMapper = new ObjectMapper(); objectMapper.registerModule(module); [ . . . do the query . . . ] ResultSet resultset = statement.executeQuery(query); // Use the DataBind Api here ObjectNode objectNode = objectMapper.createObjectNode(); // put the resultset in a containing structure objectNode.putPOJO("results", resultset); // generate all objectMapper.writeValue(stringWriter, objectNode);
@BeforeEach void setup() { objectNode = new ObjectMapper().createObjectNode(); }
public static ObjectNode createBoundsNode(double lowerRightX, double lowerRightY, double upperLeftX, double upperLeftY) { ObjectNode boundsNode = objectMapper.createObjectNode(); boundsNode.set(EDITOR_BOUNDS_LOWER_RIGHT, createPositionNode(lowerRightX, lowerRightY)); boundsNode.set(EDITOR_BOUNDS_UPPER_LEFT, createPositionNode(upperLeftX, upperLeftY)); return boundsNode; }
@Override public ObjectNode encode(PiActionModel action, CodecContext context) { ObjectNode result = context.mapper().createObjectNode(); result.put(NAME, action.id().toString()); ArrayNode params = result.putArray(PARAMS); action.params().forEach(param -> { ObjectNode paramData = context.encode(param, PiActionParamModel.class); params.add(paramData); }); return result; } }
/** * Encodes a latency constraint. * * @return JSON ObjectNode representing the constraint */ private ObjectNode encodeLatencyConstraint() { checkNotNull(constraint, "Duration constraint cannot be null"); final LatencyConstraint latencyConstraint = (LatencyConstraint) constraint; return context.mapper().createObjectNode() .put("latencyMillis", latencyConstraint.latency().toMillis()); }
modelData.setCategory(processDefinition.getDeploymentId()); ObjectNode modelObjectNode = new ObjectMapper().createObjectNode(); modelObjectNode.put(ModelDataJsonConstants.MODEL_NAME, processDefinition.getName()); modelObjectNode.put(ModelDataJsonConstants.MODEL_REVISION, 1); modelObjectNode.put(ModelDataJsonConstants.MODEL_DESCRIPTION, processDefinition.getDescription()); modelData.setMetaInfo(modelObjectNode.toString());
public static void convertMessagesToJson(Collection<Message> messages, ObjectNode propertiesNode) { String propertyName = "messages"; ArrayNode messagesNode = objectMapper.createArrayNode(); for (Message message : messages) { ObjectNode propertyItemNode = objectMapper.createObjectNode(); propertyItemNode.put(PROPERTY_MESSAGE_ID, message.getId()); propertyItemNode.put(PROPERTY_MESSAGE_NAME, message.getName()); propertyItemNode.put(PROPERTY_MESSAGE_ITEM_REF, message.getItemRef()); messagesNode.add(propertyItemNode); } propertiesNode.set(propertyName, messagesNode); }
@Override public ObjectNode toJSON() { ObjectMapper om = new ObjectMapper(); ObjectNode json = om.createObjectNode(); ObjectNode point = om.createObjectNode(); point.put("x", x); point.put("y", y); point.put("z", z); json.set("APoint3D", point); return json; } }
private ObjectNode arraySchema(JsonNode exampleArray) { ObjectNode schema = this.objectMapper.createObjectNode(); schema.put("type", "array"); if (exampleArray.size() > 0) { JsonNode exampleItem = exampleArray.get(0).isObject() ? mergeArrayItems(exampleArray) : exampleArray.get(0); schema.set("items", schemaFromExample(exampleItem)); } return schema; }
public static ObjectNode createPositionNode(double x, double y) { ObjectNode positionNode = objectMapper.createObjectNode(); positionNode.put(EDITOR_BOUNDS_X, x); positionNode.put(EDITOR_BOUNDS_Y, y); return positionNode; }
private JsonNode execute(JsonNode source, JsonNode replacement) throws IOException { Set<String> fieldNames = new HashSet<String>(); fieldNames.addAll(collectIteratorToSet(source.fieldNames())); fieldNames.addAll(collectIteratorToSet(replacement.fieldNames())); ObjectNode result = mapper.createObjectNode(); for (String fieldName : fieldNames) { Merger merger = this.merger.get(fieldName); if (merger == null) { merger = defaultMerger; } try { result.set(fieldName, merger.merge(source, replacement, fieldName)); } catch (JsonParseException e) { throw e; } } return result; } }