On Fri, Jul 24, 2020 at 9:16 PM mark r <[email protected]> wrote:
>
> Hello!
>
>
> I'm trying to serialize an ObjectNode value that contains nested ObjectNode
> values. What is the correct way to have Jackson serialize the keys in 
> alphabetical
> order? Bear in mind that I don't actually know the structure of the 
> ObjectNodes
> before I serialize them; only that they're effectively arbitrarily nested 
> key/value
> structures.

Tree model (JsonNode / ObjectNode) is meant to represent JSON content
exactly as-is, with few if
any transformations, and is handled quite differently from POJOs.
As such there is no auto-sorting feature at this point, although there
are some plans to maybe add support:

https://github.com/FasterXML/jackson-future-ideas/wiki/JSTEP-3

However: you should be able to convert `ObjectNode` into `Map` (or
just `Object` more generally) with

Map<String, Object> map = mapper.treeToValue(node, Map.class);

after which `SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS` should
work on serialization.
So 2-step processing should handle this particular case.

-+ 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 view this discussion on the web visit 
https://groups.google.com/d/msgid/jackson-user/CAL4a10iLks4AdyNDRY0rp4WpSTL%3DU%3D2UDer-BDDFHhD7s%3D5U4A%40mail.gmail.com.

Reply via email to