FasterXML / jackson-core

Core part of Jackson that defines Streaming API as well as basic shared abstractions
Apache License 2.0
2.26k stars 792 forks source link

add support for FAIL_ON_TRAILING_TOKENS at JsonParser level #1074

Open pjfanning opened 1 year ago

pjfanning commented 1 year ago

jackson-core equivalent of https://javadoc.io/static/com.fasterxml.jackson.core/jackson-databind/2.15.2/com/fasterxml/jackson/databind/DeserializationFeature.html#FAIL_ON_TRAILING_TOKENS

It feels like jackson-core should support this too. Not just jackson-databind.

cowtowncoder commented 1 year ago

My first instinct is that I disagree, mostly from complexity of implementation. Keeping in mind that not checking this is a requirement for root-level value streaming (like line-separated JSON).

The way things are implemented I am not even sure where we would be forcing this. I guess one possibility would be that if a feature was enabled, check was made on close()... and if (but only if!) document is completely read, next token would fail.

Compared to trying to do this at streaming level, support from databind is almost trivial: after binding full value verify that parser.nextToken() returns null.