Skip to content

SerializableString value can not directly render to Writer #480

@marschall

Description

@marschall

We have a JsonGenerator on a Writer. We would like to write Java 8 Date Time values to JSON. We would like to do so by avoiding intermediate objects and garbage like the String object but instead directly render to the Writer. At first we thought we could achieve this as DateTimeFormatter allows appending to a Appendable and Writer implement Appendable. We thought that by implementing SerializableString we could achieve this. Unfortunately this does not work as WriterBasedJsonGenerator#writeString(SerializableString) always creates a char[] intermediate object. This is in contrast to UTF8JsonGenerator#writeString(SerializableString) which allows directly rendering to the output buffer without creating intermediate objects/garbage.

Ideally the SerializableString would be changed but in your case the intended outcome would be achieved if WriterBasedJsonGenerator#writeString would call #appendQuoted(char[], int) instead.

This is with Jackson 2.9.6.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions