BAEL-6307: Use LinkedHashMap to fix order of keys during serialization (#13832)
Co-authored-by: Tapan Avasthi <tavasthi@Tapans-MacBook-Air.local>
This commit is contained in:
parent
ae52ba3968
commit
b86f875dbe
|
@ -1,6 +1,6 @@
|
||||||
package com.baeldung.jackson.map;
|
package com.baeldung.jackson.map;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -25,7 +25,7 @@ public class MapWithJsonKeyValueUnitTest {
|
||||||
@Test
|
@Test
|
||||||
public void givenMapWithObjectKeys_WhenSerialize_ThenUseJsonKeyForSerialization() throws JsonProcessingException {
|
public void givenMapWithObjectKeys_WhenSerialize_ThenUseJsonKeyForSerialization() throws JsonProcessingException {
|
||||||
// Given
|
// Given
|
||||||
Map<Fruit, String> selectionByFruit = new HashMap<>();
|
Map<Fruit, String> selectionByFruit = new LinkedHashMap();
|
||||||
selectionByFruit.put(FRUIT1, "Hagrid");
|
selectionByFruit.put(FRUIT1, "Hagrid");
|
||||||
selectionByFruit.put(FRUIT2, "Hercules");
|
selectionByFruit.put(FRUIT2, "Hercules");
|
||||||
// When
|
// When
|
||||||
|
@ -37,7 +37,7 @@ public class MapWithJsonKeyValueUnitTest {
|
||||||
@Test
|
@Test
|
||||||
public void givenMapWithObjectValues_WhenSerialize_ThenUseJsonValueForSerialization() throws JsonProcessingException {
|
public void givenMapWithObjectValues_WhenSerialize_ThenUseJsonValueForSerialization() throws JsonProcessingException {
|
||||||
// Given
|
// Given
|
||||||
Map<String, Fruit> selectionByPerson = new HashMap<>();
|
Map<String, Fruit> selectionByPerson = new LinkedHashMap();
|
||||||
selectionByPerson.put("Hagrid", FRUIT1);
|
selectionByPerson.put("Hagrid", FRUIT1);
|
||||||
selectionByPerson.put("Hercules", FRUIT2);
|
selectionByPerson.put("Hercules", FRUIT2);
|
||||||
// When
|
// When
|
||||||
|
|
Loading…
Reference in New Issue