Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TokenBufferdoes not implement writeString(Reader reader, int len) #3816

Closed
kilink opened this issue Mar 9, 2023 · 1 comment
Closed

TokenBufferdoes not implement writeString(Reader reader, int len) #3816

kilink opened this issue Mar 9, 2023 · 1 comment
Milestone

Comments

@kilink
Copy link
Contributor

kilink commented Mar 9, 2023

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>>() {});
@kilink kilink added the to-evaluate Issue that has been received but not yet evaluated label Mar 9, 2023
@cowtowncoder
Copy link
Member

Interesting. Ok, yes, sounds like a missing piece to implement.

@cowtowncoder cowtowncoder added 2.15 and removed to-evaluate Issue that has been received but not yet evaluated labels Mar 10, 2023
@cowtowncoder cowtowncoder added this to the 2.15.0 milestone Mar 12, 2023
@cowtowncoder cowtowncoder changed the title TokenBuffer does not implement writeString(Reader reader, int len) TokenBufferdoes not implement writeString(Reader reader, int len) Mar 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants