play-json icon indicating copy to clipboard operation
play-json copied to clipboard

avoid reparsing numbers when serializing

Open pjfanning opened this issue 1 year ago • 2 comments

Alternative to #1073

This change avoids creating NumericNodes and parsing strings to numbers which ultimately have to be turned back to strings to write them.

I've had to leave the BigIntegerNode usage in there. Removing it breaks some tests. I've debugged and it is down to how writeNumber(String) is implemented in jackson-databind TokenBuffer. We would need to change this class in jackson-databind to fix this (and that is not likely to happen as it will probably cause other issues). Basically, writeNumber(String) is assumed to be a non-integer in TokenBuffer.

pjfanning avatar Sep 05 '24 03:09 pjfanning

Unit test required

cchantep avatar Sep 13 '24 20:09 cchantep

Unit test required

@cchantep I think the existing tests do a good job of testing this code change.

pjfanning avatar Sep 13 '24 20:09 pjfanning

@mkurz I can make a small adjustment in this PR because newer jackson releases have a new method that I added so this PR can use it

pjfanning avatar Jul 09 '25 22:07 pjfanning

@mkurz I can make a small adjustment in this PR because newer jackson releases have a new method that I added so this PR can use it

haha, I just commented in the code ;) yes please go ahead

(I guess it will be

            case tb: TokenBuffer =>
              tb.writeNumber(raw, true)

because I was looking at your fork already ;) )

mkurz avatar Jul 09 '25 22:07 mkurz

@mkurz I can make a small adjustment in this PR because newer jackson releases have a new method that I added so this PR can use it

haha, I just commented in the code ;) yes please go ahead

(I guess it will be

            case tb: TokenBuffer =>
              tb.writeNumber(raw, true)

because I was looking at your fork already ;) )

I pushed that change.

pjfanning avatar Jul 09 '25 22:07 pjfanning

@pjfanning Looking at your fork, do you also want to add PRs for the rest?

  • optional support for Jackson's fast decimal parser
  • StreamWriteConstraints

?

mkurz avatar Jul 09 '25 22:07 mkurz