TailArraySchema extends AbstractSchema { @Override public IJsonNode recordToJson(final PactRecord record, IJsonNode target) { if (this.getTailSize() + 1 != record.getNumFields()) throw new IllegalStateException("Schema does not match to record!"); if (target == null) target = new ArrayNode(); else ((IArrayNode) target).clear(); JsonNodeWrapper recordElement; ((IArrayNode) target).addAll((IArrayNode) SopremoUtil.unwrap(record.getField(0, JsonNodeWrapper.class))); for (int i = 1; i <= this.getTailSize(); i++) { recordElement = record.getField(i, JsonNodeWrapper.class); if (recordElement != null) ((IArrayNode) target).add(SopremoUtil.unwrap(recordElement)); } return target; } TailArraySchema(final int tailSize); int getTailSize(); @Override IntSet indicesOf(final EvaluationExpression expression); @Override PactRecord jsonToRecord(final IJsonNode value, PactRecord target, final EvaluationContext context); @Override IJsonNode recordToJson(final PactRecord record, IJsonNode target);  }
@Test public void shouldConvertFromRecordToJson() { final PactRecord record = new PactRecord(); final TailArraySchema schema = new TailArraySchema(4); record.setField(0, SopremoUtil.wrap(new ArrayNode(IntNode.valueOf(0)))); record.setField(1, SopremoUtil.wrap(IntNode.valueOf(1))); record.setField(2, SopremoUtil.wrap(IntNode.valueOf(2))); record.setField(3, SopremoUtil.wrap(IntNode.valueOf(3))); record.setField(4, SopremoUtil.wrap(IntNode.valueOf(4))); final IArrayNode expected = new ArrayNode(IntNode.valueOf(0), IntNode.valueOf(1), IntNode.valueOf(2), IntNode.valueOf(3), IntNode.valueOf(4)); final IJsonNode result = schema.recordToJson(record, null); Assert.assertEquals(expected, result); }