Skip to content

Commit

Permalink
[eclipse-ee4j#624]Tests for the deserializer as a lambda expression
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Pinsky <[email protected]>
  • Loading branch information
api-from-the-ion committed Oct 12, 2023
1 parent f0eff31 commit 819d38f
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/test/java/org/eclipse/yasson/serializers/SerializersTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,18 @@ public void serialize(Box box, JsonGenerator out, SerializationContext ctx) {
out.write(box.secondBoxStr);
out.writeEnd();
}
};

private static final JsonbSerializer<Box> BOX_ARRAY_SERIALIZER_CHAINED_AS_LAMBDA = (box, out, ctx) -> out.writeStartArray()
.write(box.boxStr)
.write(box.secondBoxStr)
.writeEnd();

private static final JsonbSerializer<Box> BOX_ARRAY_SERIALIZER_AS_LAMBDA = (box, out, ctx) -> {
out.writeStartArray();
out.write(box.boxStr);
out.write(box.secondBoxStr);
out.writeEnd();
};

@Test
Expand Down Expand Up @@ -801,6 +813,30 @@ public void testBoxToArray() {
assertThat(jsonb.toJson(box), is(expected));
}

@Test
public void testBoxToArrayChainedWithLambda() {
JsonbConfig cfg = new JsonbConfig().withSerializers(BOX_ARRAY_SERIALIZER_CHAINED_AS_LAMBDA);
assertThrows(JsonbException.class, () -> JsonbBuilder.create(cfg));
/*Box box = new Box();
box.boxStr = "str1";
box.secondBoxStr = "str2";
String expected = "[\"str1\",\"str2\"]";
assertThat(jsonb.toJson(box), is(expected));*/
}

@Test
public void testBoxToArrayWithLambda() {
JsonbConfig cfg = new JsonbConfig().withSerializers(BOX_ARRAY_SERIALIZER_AS_LAMBDA);
assertThrows(JsonbException.class, () -> JsonbBuilder.create(cfg));
/*Box box = new Box();
box.boxStr = "str1";
box.secondBoxStr = "str2";
String expected = "[\"str1\",\"str2\"]";
assertThat(jsonb.toJson(box), is(expected));*/
}

@Test
public void testCustomSerializersInContainer(){
Jsonb jsonb = JsonbBuilder.create();
Expand Down

0 comments on commit 819d38f

Please sign in to comment.