From 0bc50d9944b9b9720904277265f00728c4b420c7 Mon Sep 17 00:00:00 2001 From: Michal Fudala Date: Fri, 15 Dec 2023 20:46:30 +0100 Subject: [PATCH 1/2] Make equals and hashCode generation deterministic (order of expressions) Order of lines of code in equals and hashCode was non-deterministic. This means that the generated files with code have changed between generations (even if nothing has changed in the schema itself). After the change, the order of these lines will be the same as the order of fields in the schema. --- .../main/java/org/jsonschema2pojo/rules/ObjectRule.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/rules/ObjectRule.java b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/rules/ObjectRule.java index 852016c2f..743305945 100644 --- a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/rules/ObjectRule.java +++ b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/rules/ObjectRule.java @@ -16,14 +16,17 @@ package org.jsonschema2pojo.rules; +import static java.util.Comparator.comparing; +import static java.util.stream.Collectors.toList; import static org.apache.commons.lang3.StringUtils.*; import static org.jsonschema2pojo.rules.PrimitiveTypes.*; import static org.jsonschema2pojo.util.TypeUtil.*; import java.util.Arrays; -import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; import java.util.Map; import java.util.Set; @@ -427,7 +430,7 @@ private void addHashCode(JDefinedClass jclass, JsonNode node) { } private Map removeFieldsExcludedFromEqualsAndHashCode(Map fields, JsonNode node) { - Map filteredFields = new HashMap<>(fields); + Map filteredFields = new LinkedHashMap<>(fields); JsonNode properties = node.get("properties"); From 73299c2657fe727d6e80a03f61bd11a3a55bf6a7 Mon Sep 17 00:00:00 2001 From: Michal Fudala Date: Fri, 15 Dec 2023 20:55:09 +0100 Subject: [PATCH 2/2] Remove not needed imports --- .../src/main/java/org/jsonschema2pojo/rules/ObjectRule.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/rules/ObjectRule.java b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/rules/ObjectRule.java index 743305945..c76b5589c 100644 --- a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/rules/ObjectRule.java +++ b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/rules/ObjectRule.java @@ -16,8 +16,6 @@ package org.jsonschema2pojo.rules; -import static java.util.Comparator.comparing; -import static java.util.stream.Collectors.toList; import static org.apache.commons.lang3.StringUtils.*; import static org.jsonschema2pojo.rules.PrimitiveTypes.*; import static org.jsonschema2pojo.util.TypeUtil.*; @@ -26,7 +24,6 @@ import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashMap; -import java.util.List; import java.util.Map; import java.util.Set;