Skip to content

TreeBuildingGenerator#writeNumber(String) writes Number as String #5528

@gaeljw

Description

@gaeljw

Search before asking

  • I searched in the issues and found nothing similar.

Describe the bug

Hello folks,

As part of some work in upgrading from Jackson 2.x to 3.x (but I think it's unrelated in the end), I came upon the behaviour of TreeBuildingGenerator#writeNumber(String) which seems odd to me.

public JsonGenerator writeNumber(String encodedValue) {
return writeString(encodedValue);
}

It writes the number (encoded as a string in input parameters) as a string in the underlying representation, especially it adds quotes around the input string. And it's then deserialized as a StringNode rather than a NumericNode.

This doesn't match what other implementations of JsonGenerator do, like WriterBasedJsonGenerator where the fact that it's a number is preserved: https://github.com/FasterXML/jackson-core/blob/0406a51a186125a451e3353ee1824f9a0407b152/src/main/java/tools/jackson/core/json/WriterBasedJsonGenerator.java#L907-L918

Am I missing something ; is this the intended behaviour?

Version Information

3.0.3

Reproduction

None yet but I can come up with something if needed.

Expected behavior

Write numbers as numbers.

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions