AbstractExpressionEvaluator implements ExpressionEvaluator { protected Object createAndFillObject(ObjectNode json, Object toReturn, String className, List<String> genericClasses) { Iterator<Map.Entry<String, JsonNode>> fields = json.fields(); while (fields.hasNext()) { Map.Entry<String, JsonNode> element = fields.next(); String key = element.getKey(); JsonNode jsonNode = element.getValue(); if (isSimpleTypeNode(jsonNode)) { Map.Entry<String, List<String>> fieldDescriptor = getFieldClassNameAndGenerics(toReturn, key, className, genericClasses); Object value = internalLiteralEvaluation(getSimpleTypeNodeTextValue(jsonNode), fieldDescriptor.getKey()); setField(toReturn, key, value); return toReturn; } if (jsonNode.isArray()) { List<Object> nestedList = new ArrayList<>(); Map.Entry<String, List<String>> fieldDescriptor = getFieldClassNameAndGenerics(toReturn, key, className, genericClasses); List<Object> returnedList = createAndFillList((ArrayNode) jsonNode, nestedList, fieldDescriptor.getKey(), fieldDescriptor.getValue()); setField(toReturn, key, returnedList); } else if (jsonNode.isObject()) { Map.Entry<String, List<String>> fieldDescriptor = getFieldClassNameAndGenerics(toReturn, key, className, genericClasses); Object nestedObject = createObject(fieldDescriptor.getKey(), fieldDescriptor.getValue()); Object returnedObject = createAndFillObject((ObjectNode) jsonNode, nestedObject, fieldDescriptor.getKey(), fieldDescriptor.getValue()); setField(toReturn, key, returnedObject); } else if (!isEmptyText(jsonNode)) { Map.Entry<String, List<String>> fieldDescriptor = getFieldClassNameAndGenerics(toReturn, key, className, genericClasses); setField(toReturn, key, internalLiteralEvaluation(jsonNode.textValue(), fieldDescriptor.getKey())); } else { } } return toReturn; }  @Override Object evaluateLiteralExpression(String rawExpression, String className, List<String> genericClasses); @Override boolean evaluateUnaryExpression(String rawExpression, Object resultValue, Class<?> resultClass);  }
@SuppressWarnings("unchecked") @Test public void convertObject() { ObjectNode objectNode = new ObjectNode(factory); objectNode.put("age", "1"); Object result = expressionEvaluatorLocal.createAndFillObject(objectNode, new HashMap<>(), Map.class.getCanonicalName(), Collections.singletonList(String.class.getCanonicalName())); assertTrue(result instanceof Map); Map<String, Object> resultMap = (Map<String, Object>) result; assertEquals("1", resultMap.get("age")); objectNode.removeAll(); ObjectNode nestedObject = new ObjectNode(factory); objectNode.set("nested", nestedObject); nestedObject.put("field", "fieldValue"); result = expressionEvaluatorLocal.createAndFillObject(objectNode, new HashMap<>(), String.class.getCanonicalName(), emptyList()); assertTrue(result instanceof Map); resultMap = (Map<String, Object>) result; assertEquals(1, resultMap.size()); Map<String, Object> nested = (Map<String, Object>) resultMap.get("nested"); assertEquals(1, nested.size()); assertEquals("fieldValue", nested.get("field")); objectNode.removeAll(); ArrayNode jsonNodes = new ArrayNode(factory); objectNode.set("listField", jsonNodes); jsonNodes.add(nestedObject); result = expressionEvaluatorLocal.createAndFillObject(objectNode, new HashMap<>(), String.class.getCanonicalName(), emptyList()); assertTrue(result instanceof Map); resultMap = (Map<String, Object>) result; assertEquals(1, resultMap.size()); List<Map<String, Object>> nestedList = (List<Map<String, Object>>) resultMap.get("listField"); assertEquals(1, nestedList.size()); assertEquals("fieldValue", nestedList.get(0).get("field")); }