Error when generating/serializing keys with multilines and colon
See original GitHub issueHello there
I wanted to report that a key containing a colon :
followed by new line chars \n
does not seem to be parsing correctly. For example the following test case reproduces the error
@Test(expected = JsonParseException.class)
public void testYamlMultiLineNotCanonical() throws Exception {
String key = "SomeKey:\n\nOtherLine";
ObjectMapper jsonMapper = new ObjectMapper();
ObjectNode jsonRoot = jsonMapper.createObjectNode();
jsonRoot.put(key, 302);
YAMLFactory yamlFactory = new YAMLFactory();
ObjectMapper yamlObjectMapper = new ObjectMapper(yamlFactory);
yamlObjectMapper.configure(JsonParser.Feature.STRICT_DUPLICATE_DETECTION, true);
StringWriter swriter = new StringWriter();
yamlObjectMapper.writeValue(swriter, jsonRoot);
ObjectMapper readMapper = new ObjectMapper(yamlFactory);
ObjectNode readJsonRoot = (ObjectNode) readMapper.readTree(swriter.toString());
Assert.assertEquals(readJsonRoot.get(key).asInt(),302 );
}
I would have expected the parser to quote the key as \n
and :
are supported yaml content.
There is work around for this: Force canonical output.
yamlFactory.configure(YAMLGenerator.Feature.CANONICAL_OUTPUT, true);
That however could have other side effects. Maybe I am missing some other configuration that would do the same?
Thoughts, comments are welcomed.
Issue Analytics
- State:
- Created 2 years ago
- Comments:11 (8 by maintainers)
Top Results From Across the Web
How to repair a serialized string which has been corrupted by ...
This solved my problem in Laravel 5. I changed the column definition from string() to binary().
Read more >Struggling to deserialize JSON with escaped double quotes
I'll try to illustrate this. This is valid JSON. { "errors": [ { "params": { "password": "size must be between 4 and 30",...
Read more >Serialization - Archive Exceptions - Boost C++ Libraries
This exception is thrown when it is detected that the serialization of the same type has been instantiated more than once. This might...
Read more >Database Engine events and errors - SQL Server
Consult this MSSQL error code list to find explanations for error messages for SQL Server database engine events.
Read more >Binary Object Serialization using Template ... - YouTube
AbstractThere are many mechanisms for a program to persist data. Most are slow, bulky, and inflexible, that typically store flat data, ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I added a simple failing test like so:
and will try to see if I can figure out how to resolve this, since SnakeYAML should be able to handle it properly.
@asomov Will do if need be, thanks!
Fix is in, for 2.13.2 release. Covers linefeed case but I suspect there may be other things that require quoting.