JsonUtils { public static JsonNode createRestrictedEntity(JsonApiIdentifiable entity, List<String> properties) { ObjectNode originalNode = objectMapper.valueToTree(entity); ObjectNode restrictedNode = objectMapper.createObjectNode(); properties.forEach(propertyName -> restrictedNode.set(propertyName, originalNode.get(propertyName))); return restrictedNode; } private  JsonUtils(); static JsonNode createRestrictedEntity(JsonApiIdentifiable entity, List<String> properties); static JsonNode createRestrictedEntity(JsonApiIdentifiable entity, String property);  }
@Test public void testCreateRestrictedEntity() { JsonNode result = JsonUtils.createRestrictedEntity(dummyObj, "nestedDummy"); Assert.assertEquals(1, result.size()); Assert.assertTrue(result.has("nestedDummy")); Assert.assertEquals(2, result.get("nestedDummy").size()); }