ObjectCreation extends EvaluationExpression { @Override public IJsonNode evaluate(final IJsonNode node) { this.result.clear(); for (final Mapping<?> mapping : this.mappings) mapping.evaluate(node, this.result); return this.result; } ObjectCreation();  ObjectCreation(final Mapping<?>... mappings);  ObjectCreation(final List<Mapping<?>> mappings); ObjectCreation addMapping(final Mapping<?> mapping); ObjectCreation addMapping(final PathSegmentExpression target, final EvaluationExpression expression); ObjectCreation addMapping(final String target, final EvaluationExpression expression); @Override void appendAsString(final Appendable appendable); @Override boolean equals(final Object obj); @Override IJsonNode evaluate(final IJsonNode node); Mapping<?> getMapping(final int index); List<Mapping<?>> getMappings(); int getMappingSize(); @Override int hashCode(); @Override ChildIterator iterator(); static final ObjectCreation CONCATENATION; }
@Test public void shouldCreateObjectAsIntended() { final IJsonNode result = new ObjectCreation(new ObjectCreation.FieldAssignment("name", new ConstantExpression( TextNode.valueOf("testperson"))), new ObjectCreation.FieldAssignment("age", new ConstantExpression( IntNode.valueOf(30)))).evaluate(IntNode.valueOf(0)); Assert.assertEquals(createObjectNode("name", "testperson", "age", 30), result); }
@Test public void shouldEvaluateMappings() { final ObjectCreation.FieldAssignment mapping = new ObjectCreation.FieldAssignment("testname", new InputSelection(0)); final ObjectNode result = createObjectNode("fieldname", "test"); mapping.evaluate(createArrayNode("1", "2"), result); mapping.evaluate(createArrayNode("3", "4"), result); Assert.assertEquals(createObjectNode("fieldname", "test", "testname", "3"), result); }
@Test public void shouldReuseTargetIfCorrectType() { final ObjectCreation object = new ObjectCreation(new ObjectCreation.FieldAssignment("name", new ConstantExpression( TextNode.valueOf("testperson"))), new ObjectCreation.FieldAssignment("age", new ConstantExpression( IntNode.valueOf(30)))); final IJsonNode result1 = object.evaluate(IntNode.valueOf(0)); final IJsonNode result2 = object.evaluate(IntNode.valueOf(1)); Assert.assertSame(result1, result2); }