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:
Tapan Avasthi 2023-04-14 06:41:25 +05:30 committed by GitHub
parent ae52ba3968
commit b86f875dbe
1 changed files with 3 additions and 3 deletions

View File

@ -1,6 +1,6 @@
package com.baeldung.jackson.map;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import org.junit.Test;
@ -25,7 +25,7 @@ public class MapWithJsonKeyValueUnitTest {
@Test
public void givenMapWithObjectKeys_WhenSerialize_ThenUseJsonKeyForSerialization() throws JsonProcessingException {
// Given
Map<Fruit, String> selectionByFruit = new HashMap<>();
Map<Fruit, String> selectionByFruit = new LinkedHashMap();
selectionByFruit.put(FRUIT1, "Hagrid");
selectionByFruit.put(FRUIT2, "Hercules");
// When
@ -37,7 +37,7 @@ public class MapWithJsonKeyValueUnitTest {
@Test
public void givenMapWithObjectValues_WhenSerialize_ThenUseJsonValueForSerialization() throws JsonProcessingException {
// Given
Map<String, Fruit> selectionByPerson = new HashMap<>();
Map<String, Fruit> selectionByPerson = new LinkedHashMap();
selectionByPerson.put("Hagrid", FRUIT1);
selectionByPerson.put("Hercules", FRUIT2);
// When