On Thu, May 3, 2018 at 9:36 AM, Tatu Saloranta <[email protected]> wrote: > On Thu, May 3, 2018 at 5:02 AM, <[email protected]> wrote: >> It seems that the ObjectNode.PutPOJO method does not put quotes around the >> members of a string array, >> >> List<String> names = List.of("Zaphod", "Arthur", "Trillian", "Ford"); >> >> >> ObjectMapper objectMapper = new ObjectMapper(); >> >> >> ObjectNode rootNode = objectMapper.createObjectNode(); >> >> rootNode.putPOJO("pojo", names); >> >> rootNode.set("set", objectMapper.valueToTree(names)); >> >> System.out.println(rootNode); >> >> >> The above code demonstrates the issue. >> >> The string output cannot be parsed by ObjectMapper.readTree > > > This is not really along original intended usage for putPOJO (since > `List`s are not POJOs), but it would seem like > supporting it might be easy enough. > > Could you do me a favor and file an issue against `jackson-databind`, > with above description? > That way you get credit for reporting the issue and I can link new > feature to reported issue for release notes.
Oh actually, no, never mind. Your problem is here: System.out.println(rootNode); JsonNode.toString() is explicitly defined not to necessarily produce valid JSON, and it should never be used for anything other than diagnostics or debugging. In fact I am planning to make it so that in 3.0 it will usually not produce valid JSON to make this explicit. To produce JSON you have to serialize node using `ObjectMapper` or `ObjectWriter`: this will use all configured settings to handle serialization details. Problem with `toString()` is that it would have to replicate aspects of serialization since there is no way to access any object capable of serialization (there has to be a `JsonGenerator` to use, fundamentally). I hope this helps, -+ Tatu +- -- 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 [email protected]. To post to this group, send email to [email protected]. For more options, visit https://groups.google.com/d/optout.
