@Override public void marshallJson(ObjectNode node, String fieldName, T payload) throws Exception { if ( payload == null ) { //noinspection unchecked payload = (T)payloadType.getRawType().newInstance(); } node.putPOJO(fieldName, payload); }
public ObjectNode toJSONObject() { ObjectNode o = mapper.createObjectNode(); for (Map.Entry<String, Object> header : headers.entrySet()) { o.putPOJO(header.getKey(), header.getValue()); } return o; }
private JsonNode toJSON(NativeObject object) { if (object == null) return null; ObjectNode result = JsonUtils.getObjectMapper().createObjectNode(); for (Map.Entry<Object, Object> entry : object.entrySet()) { if (entry.getValue().getClass().equals(NativeObject.class)) { result.put((String) entry.getKey(), toJSON((NativeObject) entry.getValue())); } else if (entry.getValue().getClass().equals(NativeArray.class)) { result.put((String) entry.getKey(), toJSON((NativeArray) entry.getValue())); } else { result.putPOJO((String) entry.getKey(), entry.getValue()); } } return result; }
public JsonNode toJSONObject() { ObjectNode o = mapper.createObjectNode(); for (Map.Entry<String, Object> claim : claims.entrySet()) { if (CLAIM_AUDIENCE.equals(claim.getKey())) { // Serialize single audience list and string List<String> audList = getAudience(); if (audList != null && !audList.isEmpty()) { if (audList.size() == 1) { o.put(CLAIM_AUDIENCE, audList.get(0)); } else { ArrayNode audArray = mapper.createArrayNode(); for (String aud : audList) { audArray.add(aud); } o.put(CLAIM_AUDIENCE, audArray); } } } else if (claim.getValue() != null) { o.putPOJO(claim.getKey(), claim.getValue()); } } return o; }
public static JsonNode entityToJson(Entity entity) throws LeanException { ObjectNode json = getObjectMapper().createObjectNode(); json.put("_id", entity.getKey().getId()); json.putPOJO("_kind", entity.getKind()); json.putPOJO("_account", entity.getProperty("_account")); Map<String, Object> props = entity.getProperties(); for (Map.Entry<String, Object> prop : props.entrySet()) { addTypedNode(json, prop.getKey(), prop.getValue()); } return json; }