jackson-core icon indicating copy to clipboard operation
jackson-core copied to clipboard

JsonReadFeature: Introduce missing features for JSON5 compatibility

Open GrahamLea opened this issue 2 years ago • 4 comments

The optional features in the JSON parser allow it be configured to almost be a fully-compatible parser for JSON5.

There's just a few missing features, documented here: https://stackoverflow.com/questions/68312227/can-the-jackson-parser-be-used-to-parse-json5

Summarised as:

  • hexadecimal numbers
  • trailing decimal points on numbers (added via #773)
  • plus signs before numbers (added via #774)
  • extra whitespace characters

I propose that additional Jackson features be added for each of these JSON5 features to allow Jackson to be used as a fully-compliant JSON5 parser.

(#612 was a similar but more specific request, though it seems that feature is already covered)

EDIT: Following work has been done:

  • #773 adds JsonReadFeature.ALLOW_LEADING_DECIMAL_POINT_FOR_NUMBERS to allow trailing decimal points on numbers
  • #774: adds JsonReadFeature.ALLOW_LEADING_PLUS_SIGN_FOR_NUMBERS to allow leading plus sign on numbers

GrahamLea avatar Jul 09 '21 06:07 GrahamLea

Sounds reasonable, as long as these are opt-in features (or, possibly, one JSON5 feature), to be added in JsonReadFeature and not defaults. I probably won't have time to work on this in near future but as usual would be happy to help someone else has time for a PR or two!

cowtowncoder avatar Jul 09 '21 18:07 cowtowncoder

So, thanks to @pjfanning 's work, 2 number related features needed here are implemented to go in 2.14!

cowtowncoder avatar Jun 23 '22 22:06 cowtowncoder

Ok, so looks like we have 2 things missing:

  • Hexadecimal numbers
  • Extra whitespace

Of these, hex numbers might be relatively easy to add (esp. for blocking parsers). White space could be trickier to do efficiently but maybe not (esp. for "common" white space like tabs and other low-numeric code ones); also seems like less commonly needed feature.

cowtowncoder avatar Jul 28 '22 16:07 cowtowncoder

If anyone is interested, filing a separate issue for, say, Hexadecimal number support; adding unit tests (failing, under .../failing/) would be a way to get things started. And probably new JsonReadFeature to enable said support (but not yet implemented) If this is something that you are interested in getting implemented.

cowtowncoder avatar May 30 '23 17:05 cowtowncoder