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!

-- 
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/238c5528-0635-4533-80e8-5bac4a1f480bo%40googlegroups.com.

Reply via email to