com.fasterxml.jackson.core.JsonParseException: Illegal unquoted character ((CTRL-CHAR, code 10))

4,054 views
Skip to first unread message

Gregg Freeman

unread,
Jun 30, 2016, 12:58:53 PM6/30/16
to jackson-user
We're trying to parse this JSON received from a 3rd party:

{
"comments": 
"\\",
"foo": "bar"
}

However, Jackson (2.5.0) seem to throw the exception in the title.  Should Jackson be able to successfully parse this?

Tatu Saloranta

unread,
Jun 30, 2016, 1:25:32 PM6/30/16
to jackso...@googlegroups.com
If content does indeed contain character 10 (Unicode), that is, linefeed, it is prohibited by JSON specification (should be escaped as \n), so the content should be fixed and parser is right to report it.
This is assuming content does have that; cut'n pasting JSON can not quite tell that, so you'd have to check it.

However it is possible to make parser more lenient by enabling `JsonParser.Feature.ALLOW_UNQUOTED_CONTROL_CHARS` to let this violation be skipped and character included as-is during parsing.

So: caller should NOT send such unescaped characters, but you may want to temporarily enable those before sender has been fixed.

Hope this helps,

-+ Tatu +-

ps. Not too that version 2.5.0 is old and there are patch releases, so should at least upgrade to 2.5.5 -- I don't think there are bug fixes relevant to this use case but it's good habit to ensure latest patch is used before checking for bugs



--
You received this message because you are subscribed to the Google Groups "jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jackson-user...@googlegroups.com.
To post to this group, send email to jackso...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Gregg Freeman

unread,
Jun 30, 2016, 1:48:49 PM6/30/16
to jackson-user
Thank you very much for the response.  I looked through the defects and agree that I didn't see anything related to this.  The Feature setting you specified will help us out a ton.

Our environment is pretty "structured" for getting new releases, but we'll try to get the patch release.

Thanks again!
Reply all
Reply to author
Forward
0 new messages