-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Closed
Description
Jackson version: 2.3.0
While trying to work around Issue #357, I found another bug.
Jackson does not honor contentUsing
in @JsonSerialize
under some circumstances.
static class A {
public String unexpected = "Bye.";
}
static class B {
@JsonSerialize(as = Iterable.class, contentUsing = ASerializer.class)
public List<A> list = Arrays.asList(new A());
}
static class ASerializer extends JsonSerializer<A> {
@Override
public void serialize(A a, JsonGenerator jsonGenerator, SerializerProvider provider) throws IOException {
jsonGenerator.writeStartArray();
jsonGenerator.writeString("Hello world.");
jsonGenerator.writeEndArray();
}
}
@Test
void testBSerialization() throws Exception {
System.out.println(new ObjectMapper().writeValueAsString(new B()));
}
This gives the following output:
{"list":[{"unexpected":"Bye."}]}
However, replacing as = Iterable.class
by as = List.class
gives output:
{"list":[["Hello world."]]}
Metadata
Metadata
Assignees
Labels
No labels