EscEvents implements ToJsonCapable { public final List<EscEvent> getList() { return Collections.unmodifiableList(list); } protected  EscEvents();  EscEvents(@NotNull final EscEvent... events);  EscEvents(@NotNull final List<EscEvent> events); final List<EscEvent> getList(); @Override final JsonArray toJson(); static EscEvents create(final JsonArray jsonArray); static final TypeName TYPE; static final SerializedDataType SER_TYPE; }
@Test public final void testMarshalUnmarshalJaxb() throws Exception { final String expectedXml = IOUtils.toString(this.getClass().getResourceAsStream("/esc-events.xml")); final EscEvents testee = unmarshal(expectedXml, EscEvents.class, MyMeta.class, MyEvent.class, Base64Data.class); assertThat(testee).isNotNull(); assertThat(testee.getList()).isNotNull(); assertThat(testee.getList().size()).isEqualTo(2); assertThat(testee.getList().get(0).getEventId()).isEqualTo("68616d90-cf72-4c2a-b913-32bf6e6506ed"); assertThat(testee.getList().get(1).getEventId()).isEqualTo("c198a02e-126e-4fbb-910c-918abf39a4a6"); final String xml = marshal(testee, EscEvents.class, MyMeta.class, MyEvent.class, Base64Data.class); final Diff documentDiff = DiffBuilder.compare(expectedXml).withTest(xml).ignoreWhitespace().build(); assertThat(documentDiff.hasDifferences()).describedAs(documentDiff.toString()).isFalse(); }
@Test public final void testUnmarshalJsonB() throws Exception { final String expectedJson = IOUtils.toString(this.getClass().getResourceAsStream("/esc-events.json")); final SimpleSerializedDataTypeRegistry typeRegistry = new SimpleSerializedDataTypeRegistry(); typeRegistry.add(MyEvent.SER_TYPE, MyEvent.class); typeRegistry.add(MyMeta.SER_TYPE, MyMeta.class); final JsonbDeSerializer jsonbDeSer = JsonbDeSerializer.builder() .withSerializers(EscSpiUtils.createEscJsonbSerializers()) .withDeserializers(EscSpiUtils.createEscJsonbDeserializers()) .withPropertyVisibilityStrategy(new FieldAccessStrategy()) .withEncoding(Charset.forName("utf-8")) .build(); initSerDeserializerRegistry(typeRegistry, jsonbDeSer); try (final Jsonb jsonb = jsonbDeSer.getJsonb()) { final EscEvents testee = jsonb.fromJson(expectedJson, EscEvents.class); assertThat(testee.getList()).hasSize(2); assertThat(testee.getList().get(0).getEventId()).isEqualTo("b2a936ce-d479-414f-b67f-3df4da383d47"); assertThat(testee.getList().get(1).getEventId()).isEqualTo("68616d90-cf72-4c2a-b913-32bf6e6506ed"); } }