-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Closed
Milestone
Description
Describe the bug
Calling the writeString
method on JsonGenerator
that accepts a Reader
throws when the underlying implementation is TokenBuffer
. This happens for instance one when calls convertValue
, but makes it awkward for the Serializer to be agnostic to whether it's being called for conversion or serialization.
Version information
Which Jackson version(s) was this for?
2.14.x
To Reproduce
Here's a contrived example:
@JsonSerialize(using = Foo.Serializer.class)
class Foo {
static class Serializer extends StdSerializer<Foo> {
Serializer() {
super(Foo.class);
}
@Override
public void serialize(Foo value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeStartObject();
gen.writeFieldName("field");
gen.writeString(new StringReader("foobar"), 6);
gen.writeEndObject();
}
}
}
ObjectMapper mapper = new ObjectMapper();
Foo obj = new Foo();
// works
String serialized = mapper.writeValueAsString(obj);
// fails
Map<String, String> map = mapper.convertValue(obj, new TypeReference<Map<String, String>>() {});
Metadata
Metadata
Assignees
Labels
No labels