From b86f875dbef7b7f9a5593825f2ac76a680dc1aa3 Mon Sep 17 00:00:00 2001 From: Tapan Avasthi Date: Fri, 14 Apr 2023 06:41:25 +0530 Subject: [PATCH] BAEL-6307: Use LinkedHashMap to fix order of keys during serialization (#13832) Co-authored-by: Tapan Avasthi --- .../baeldung/jackson/map/MapWithJsonKeyValueUnitTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/jackson-modules/jackson-conversions/src/test/java/com/baeldung/jackson/map/MapWithJsonKeyValueUnitTest.java b/jackson-modules/jackson-conversions/src/test/java/com/baeldung/jackson/map/MapWithJsonKeyValueUnitTest.java index 87c425fe96..0b4639ca3b 100644 --- a/jackson-modules/jackson-conversions/src/test/java/com/baeldung/jackson/map/MapWithJsonKeyValueUnitTest.java +++ b/jackson-modules/jackson-conversions/src/test/java/com/baeldung/jackson/map/MapWithJsonKeyValueUnitTest.java @@ -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 selectionByFruit = new HashMap<>(); + Map 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 selectionByPerson = new HashMap<>(); + Map selectionByPerson = new LinkedHashMap(); selectionByPerson.put("Hagrid", FRUIT1); selectionByPerson.put("Hercules", FRUIT2); // When