Jackson Object mapper to convert java map to json maintaining order of keys -
I'm using the I pass a map sorted by value to the Is there a way to change the map using Jackson without affecting the order of objects in Maps in Maps. I tried setting the value to said any ideas for implementing the behavior. with Jackson 2.3.1 (you do not know for previous versions) as an example Treemark, Sort can be respected. Here is an example in Junior 4: And here's the result: with a map a sorted map ` 1 Sorting with a map Order will not be given, alphabet will be ordered using the second key with the tree mark. You can pass a comparator to the papermap for a different order. EDIT: It also works on Jackson with a Linkedic Mac, even if it is not a random map. This is the implementation of the map which maintains the order which was inserted into the key on the map. It can be what you want. jackson.map.ObjectMapper API to convert the json string to the map I am I'm using writeValueAsString method to get this.
writeValueAsString method. The JSON string I get is surrounded by keys.
Feature.SORT_PROPERTIES_ALPHABETICALLY , but according to the documentation it is applicable only for POJO types.
@Test pushes public Zero Test (Cyrilize) JsonProcessingException {ObjectMapper om = new ObjectMapper (); Om.configure (SerializationFeature.WRITE_NULL_MAP_VALUES, false); Om.configure (SerializationFeature.INDENT_OUTPUT, true); Om.setSerializationInclusion (Include.NON_NULL); SortedMap & LT; String, string & gt; Sorted map = new trendmark & lt; String, string & gt; (); Click the & lt; String, string & gt; Map = new hashmap & lt; String, string & gt; (); Map.put ("aaa", "aAA"); Map.put ("bbb", "bbb"); Map.put ("CCC", "CCC"); Map.put ("ddd", "DDD"); SortedMap.putAll (map); Println (om.writeValueAsString (map)); Println (om.writeValueAsString (sortedMap)); }
{"aaa": "AAA", "deed" : "AAA", "CD", "CCC", "BBB": "BBB"}
"BBB": "Bbb", "CCC": "CCC", "Deed D": "DDD"}
Comments
Post a Comment