From b68a4f0acd9ef6dfbef04a04285b6635db5a0913 Mon Sep 17 00:00:00 2001 From: Olivier Perrin Date: Mon, 2 Dec 2024 09:49:46 +0100 Subject: [PATCH] Fix GraphMetadata serialization: attributes' order (#659) Signed-off-by: Olivier Perrin --- .../src/main/java/com/powsybl/sld/svg/GraphMetadata.java | 6 ++++++ .../test/resources/substDiag_with_hvdc_line_metadata.json | 8 ++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/GraphMetadata.java b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/GraphMetadata.java index b488dbb07..b36599c83 100644 --- a/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/GraphMetadata.java +++ b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/GraphMetadata.java @@ -10,6 +10,7 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.collect.ImmutableList; import com.powsybl.commons.json.JsonUtil; @@ -32,6 +33,11 @@ public class GraphMetadata extends AbstractMetadata { @JsonInclude(JsonInclude.Include.NON_NULL) + // On some systems, the export order is determined by the order of the 1st encountered JsonCreator's attributes + // and "unescapedId" is put in last place. But on other systems, the export order is determined by the getters' order + // and "unescapedId" is put in 1st place, which leads to comparison errors in the unit tests. + // To prevent this discrepancy, the order is manually fixed. + @JsonPropertyOrder(value = {"unescapedId", "id", "vid", "nextVId", "componentType", "open", "direction", "vlabel", "equipmentId", "labels"}) public static class NodeMetadata { private final String unescapedId; diff --git a/single-line-diagram/single-line-diagram-core/src/test/resources/substDiag_with_hvdc_line_metadata.json b/single-line-diagram/single-line-diagram-core/src/test/resources/substDiag_with_hvdc_line_metadata.json index 5a38191b5..63b95725b 100644 --- a/single-line-diagram/single-line-diagram-core/src/test/resources/substDiag_with_hvdc_line_metadata.json +++ b/single-line-diagram/single-line-diagram-core/src/test/resources/substDiag_with_hvdc_line_metadata.json @@ -123,6 +123,7 @@ "positionName" : "NW_LABEL" } ] }, { + "unescapedId" : "LCC_1", "id" : "idLCC_95_1", "vid" : "VoltageLevel1", "nextVId" : "VoltageLevel2", @@ -134,8 +135,7 @@ "labels" : [ { "id" : "LCC_1_S_LABEL", "positionName" : "S_LABEL" - } ], - "unescapedId" : "LCC_1" + } ] }, { "id" : "LABEL_VL_VoltageLevel1", "vid" : "VoltageLevel1", @@ -164,6 +164,7 @@ "vlabel" : false, "labels" : [ ] }, { + "unescapedId" : "VSC_1", "id" : "idVSC_95_1", "vid" : "VoltageLevel1", "nextVId" : "VoltageLevel2", @@ -175,8 +176,7 @@ "labels" : [ { "id" : "VSC_1_N_LABEL", "positionName" : "N_LABEL" - } ], - "unescapedId" : "VSC_1" + } ] }, { "id" : "idBUSCO_95_Bus1_95_VSC_95_1", "vid" : "VoltageLevel1",