Skip to content

Commit

Permalink
Fix GraphMetadata serialization: attributes' order (#659)
Browse files Browse the repository at this point in the history
Signed-off-by: Olivier Perrin <olivier.perrin@rte-france.com>
  • Loading branch information
olperr1 authored Dec 2, 2024
1 parent ae5dae7 commit b68a4f0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@
"positionName" : "NW_LABEL"
} ]
}, {
"unescapedId" : "LCC_1",
"id" : "idLCC_95_1",
"vid" : "VoltageLevel1",
"nextVId" : "VoltageLevel2",
Expand All @@ -134,8 +135,7 @@
"labels" : [ {
"id" : "LCC_1_S_LABEL",
"positionName" : "S_LABEL"
} ],
"unescapedId" : "LCC_1"
} ]
}, {
"id" : "LABEL_VL_VoltageLevel1",
"vid" : "VoltageLevel1",
Expand Down Expand Up @@ -164,6 +164,7 @@
"vlabel" : false,
"labels" : [ ]
}, {
"unescapedId" : "VSC_1",
"id" : "idVSC_95_1",
"vid" : "VoltageLevel1",
"nextVId" : "VoltageLevel2",
Expand All @@ -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",
Expand Down

0 comments on commit b68a4f0

Please sign in to comment.