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.
I've seen the Stack Overflow answers:
https://stackoverflow.com/questions/27577701/jackson-objectmapper-specify-serialization-order-of-object-properties... And they're either not relevant to my problem (specifying annotations on
classes used for deserialization when I'm dealing with ObjectNodes I didn't
deserialize), or specify various combinations of the MapperFeature.SORT_PROPERTIES_ALPHABETICALLY,
or SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS flags,
which don't appear to have any effect.
My code essentially looks like this:
```
fun canonicalize(
objectNode: ObjectNode,
outputStream: OutputStream
) {
val mapper = ObjectMapper()
mapper.configure(SerializationFeature.INDENT_OUTPUT, false)
mapper.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true)
mapper.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true)
mapper.writeValue(outputStream, objectNode)
}
```
The data written to the output stream does _not_ have the keys sorted
in alphabetical order.
Any help would be appreciated!