poser55 / linked-db-rows

Relational databases work with rows of data that can be linked to other rows via foreign keys. All linked rows form a graph. Linked db rows works on graphs of such database rows: It allows exporting such graphs to JSON and re-importing them again into databases.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Wrong escaping of characters in json (also tab)

poser55 opened this issue · comments

When using the json in other json frameworks, we get the following exception:

com.fasterxml.jackson.databind.ObjectMapper jsonMapper = ...;

jsonNode = jsonMapper.readTree(jsonAsString); // line with exception:

c.f.j.c.JsonParseException: Illegal unquoted character ((CTRL-CHAR, code 9)): has to be escaped using backslash to be included in string value
at [Source: (StringReader); line: 1, column: 85933]
at c.f.j.c.JsonParser._constructError(JsonParser.java:1804)
at c.f.j.c.b.ParserMinimalBase._reportError(ParserMinimalBase.java:693)
at c.f.j.c.b.ParserMinimalBase._throwUnquotedSpace(ParserMinimalBase.java:657)
at c.f.j.c.j.ReaderBasedJsonParser._finishString2(ReaderBasedJsonParser.java:2053)
at c.f.j.c.j.ReaderBasedJsonParser._finishString(ReaderBasedJsonParser.java:2024)
at c.f.j.c.j.ReaderBasedJsonParser.getText(ReaderBasedJsonParser.java:278)
at c.f.j.d.d.s.BaseNodeDeserializer.deserializeObject(JsonNodeDeserializer.java:264)
at c.f.j.d.d.s.JsonNodeDeserializer.deserialize(JsonNodeDeserializer.java:68)
at c.f.j.d.d.s.JsonNodeDeserializer.deserialize(JsonNodeDeserializer.java:15)
at c.f.j.d.ObjectMapper._readTreeAndClose(ObjectMapper.java:4057)
at c.f.j.d.ObjectMapper.readTree(ObjectMapper.java:2552)

Escapes or unescapes a JSON string removing traces of offending characters that could prevent parsing.
The following characters are reserved in JSON and must be properly escaped to be used in strings:
• Backspace is replaced with \b
• Form feed is replaced with \f
• Newline is replaced with \n
• Carriage return is replaced with \r
• Tab is replaced with \t
• Double quote is replaced with "
• Backslash is replaced with \

Use the new method:
Record.asJsonNode()

We have now extended the tests that test this part better (they compare the old and new json export).