@Test public void superimposeEncryptedDataOnOriginalNodeTest() throws IOException { JsonNode originalNode = mapper.readTree("{\"RequestInfo\":{\"api_id\":\"1\",\"ver\":\"1\",\"ts\":null," + "\"action\":\"create\",\"did\":\"\",\"key\":\"\",\"msg_id\":\"\",\"requester_id\":\"\"," + "\"auth_token\":null},\"User\":{\"userName\":\"ajay\",\"name\":\"ajay\",\"gender\":\"male\"," + "\"mobileNumber\":\"12312312\",\"active\":true,\"type\":\"CITIZEN\",\"password\":\"password\"}}"); JsonNode encryptedNode = mapper.readTree("{\"User\":{\"userName\":\"123|jkafsdhkjhalfsj\",\"name\":\"123|" + "jkafsdhkjhalfsj\",\"mobileNumber\":\"123|hdskjahkjfk\"}}"); JsonNode outputNode = JacksonUtils.merge(encryptedNode, originalNode); JsonNode expectedNode = mapper.readTree("{\"RequestInfo\":{\"api_id\":\"1\",\"ver\":\"1\",\"ts\":null," + "\"action\":\"create\",\"did\":\"\",\"key\":\"\",\"msg_id\":\"\",\"requester_id\":\"\"," + "\"auth_token\":null},\"User\":{\"userName\":\"123|jkafsdhkjhalfsj\"," + "\"name\":\"123|jkafsdhkjhalfsj\",\"gender\":\"male\",\"mobileNumber\":\"123|hdskjahkjfk\"," + "\"active\":true,\"type\":\"CITIZEN\",\"password\":\"password\"}}"); assertEquals(expectedNode, outputNode); }
public static JsonNode merge(JsonNode newNode, JsonNode originalNode) { if(newNode == null || newNode.isNull()) return originalNode; else if(originalNode == null || originalNode.isNull()) return newNode; if(newNode.isObject()) newNode = mergeObjectNodes( (ObjectNode) newNode, (ObjectNode) originalNode); else if(newNode.isArray()) newNode = mergeArrayNode( (ArrayNode) newNode, (ArrayNode) originalNode); return newNode; }
JacksonUtils { public static JsonNode merge(JsonNode newNode, JsonNode originalNode) { if(newNode == null || newNode.isNull()) return originalNode; else if(originalNode == null || originalNode.isNull()) return newNode; if(newNode.isObject()) newNode = mergeObjectNodes( (ObjectNode) newNode, (ObjectNode) originalNode); else if(newNode.isArray()) newNode = mergeArrayNode( (ArrayNode) newNode, (ArrayNode) originalNode); return newNode; } }
JacksonUtils { public static JsonNode merge(JsonNode newNode, JsonNode originalNode) { if(newNode == null || newNode.isNull()) return originalNode; else if(originalNode == null || originalNode.isNull()) return newNode; if(newNode.isObject()) newNode = mergeObjectNodes( (ObjectNode) newNode, (ObjectNode) originalNode); else if(newNode.isArray()) newNode = mergeArrayNode( (ArrayNode) newNode, (ArrayNode) originalNode); return newNode; }  }
JacksonUtils { public static JsonNode merge(JsonNode newNode, JsonNode originalNode) { if(newNode == null || newNode.isNull()) return originalNode; else if(originalNode == null || originalNode.isNull()) return newNode; if(newNode.isObject()) newNode = mergeObjectNodes( (ObjectNode) newNode, (ObjectNode) originalNode); else if(newNode.isArray()) newNode = mergeArrayNode( (ArrayNode) newNode, (ArrayNode) originalNode); return newNode; }  static JsonNode merge(JsonNode newNode, JsonNode originalNode); static JsonNode filterJsonNodeForPaths(JsonNode jsonNode, List<String> filterPaths); static JsonNode filterJsonNodeWithFields(JsonNode jsonNode, List<String> filterFields); }
JacksonUtils { public static JsonNode merge(JsonNode newNode, JsonNode originalNode) { if(newNode == null || newNode.isNull()) return originalNode; else if(originalNode == null || originalNode.isNull()) return newNode; if(newNode.isObject()) newNode = mergeObjectNodes( (ObjectNode) newNode, (ObjectNode) originalNode); else if(newNode.isArray()) newNode = mergeArrayNode( (ArrayNode) newNode, (ArrayNode) originalNode); return newNode; }  static JsonNode merge(JsonNode newNode, JsonNode originalNode); static JsonNode filterJsonNodeForPaths(JsonNode jsonNode, List<String> filterPaths); static JsonNode filterJsonNodeWithFields(JsonNode jsonNode, List<String> filterFields);  }