Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Copyright (c) 2025, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

package org.gridsuite.network.map.config;

import org.gridsuite.network.map.config.nan.NaNAsNullModule;
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
* @author Thang PHAM <quyet-thang.pham at rte-france.com>
*/
@Configuration
public class NetworkMapJsonConfig {
@Bean
public Jackson2ObjectMapperBuilderCustomizer jsonCustomizer() {
return builder -> builder
.modulesToInstall(new NaNAsNullModule());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.gridsuite.network.map.config.nan;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;

public class NaNAsNullDoubleSerializer extends JsonSerializer<Double> {

@Override
public void serialize(Double value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
if (value == null || value.isNaN()) {
gen.writeNull();
} else {
gen.writeNumber(value);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.gridsuite.network.map.config.nan;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;

public class NaNAsNullFloatSerializer extends JsonSerializer<Float> {

@Override
public void serialize(Float value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
if (value == null || value.isNaN()) {
gen.writeNull();
} else {
gen.writeNumber(value);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.gridsuite.network.map.config.nan;

import com.fasterxml.jackson.databind.module.SimpleModule;

public class NaNAsNullModule extends SimpleModule {
public NaNAsNullModule() {
this.addSerializer(Double.class, new NaNAsNullDoubleSerializer())
.addSerializer(Float.class, new NaNAsNullFloatSerializer());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.gridsuite.network.map.config.nan;

public class NullAndNaNFilter {

@Override
public boolean equals(Object value) {
if (value == null) {
return true; // Ignore null
} else if (value instanceof Double doubleValue && doubleValue.isNaN()) {
return true; // Ignore NaN
} else if (value instanceof Float floatValue && floatValue.isNaN()) {
return true; // Ignore NaN
}
return false;
}

@Override
public int hashCode() {
return 0; // 0 due to not important
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import org.gridsuite.network.map.config.nan.NullAndNaNFilter;

import java.util.List;

Expand All @@ -25,7 +26,7 @@ public class CurrentLimitsData {
@JsonInclude(JsonInclude.Include.NON_NULL)
private String id;

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullAndNaNFilter.class)
private Double permanentLimit;

@JsonInclude(JsonInclude.Include.NON_NULL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import org.gridsuite.network.map.config.nan.NullAndNaNFilter;

/**
* @author Seddik Yengui <seddik.yengui at rte-france.com>
Expand All @@ -21,9 +22,9 @@
@EqualsAndHashCode
public class MinMaxReactiveLimitsMapData {

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullAndNaNFilter.class)
private Double minQ;

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullAndNaNFilter.class)
private Double maxQ;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@

import com.fasterxml.jackson.annotation.JsonInclude;
import com.powsybl.iidm.network.PhaseTapChanger;
import lombok.*;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import org.gridsuite.network.map.config.nan.NullAndNaNFilter;

import java.util.List;

Expand All @@ -31,16 +34,16 @@ public class TapChangerData {
@JsonInclude(JsonInclude.Include.NON_NULL)
private Boolean hasLoadTapChangingCapabilities;

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullAndNaNFilter.class)
private Double targetV;

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullAndNaNFilter.class)
private Double targetDeadband;

@JsonInclude(JsonInclude.Include.NON_NULL)
private PhaseTapChanger.RegulationMode regulationMode;

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullAndNaNFilter.class)
private Double regulationValue;

@JsonInclude(JsonInclude.Include.NON_NULL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.*;
import org.gridsuite.network.map.config.nan.NullAndNaNFilter;

/**
* @author Hugo Marcellin <hugo.marcelin at rte-france.com>
Expand All @@ -19,22 +20,22 @@ public class TapChangerStepData {
@JsonInclude(JsonInclude.Include.NON_NULL)
private Integer index;

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullAndNaNFilter.class)
private Double rho;

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullAndNaNFilter.class)
private Double r;

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullAndNaNFilter.class)
private Double x;

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullAndNaNFilter.class)
private Double g;

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullAndNaNFilter.class)
private Double b;

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullAndNaNFilter.class)
private Double alpha;
}

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import org.gridsuite.network.map.config.nan.NullAndNaNFilter;

/**
* @author David Braquart <david.braquart at rte-france.com>
Expand All @@ -20,7 +21,7 @@
public class TemporaryLimitData {
private String name;

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullAndNaNFilter.class)
private Double value;

@JsonInclude(JsonInclude.Include.NON_NULL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Getter;
import lombok.experimental.SuperBuilder;
import org.gridsuite.network.map.config.nan.NullAndNaNFilter;
import org.gridsuite.network.map.dto.ElementInfosWithProperties;
import org.gridsuite.network.map.dto.definition.extension.ActivePowerControlInfos;
import org.gridsuite.network.map.dto.definition.extension.ConnectablePositionInfos;
import org.gridsuite.network.map.dto.common.MinMaxReactiveLimitsMapData;
import org.gridsuite.network.map.dto.common.ReactiveCapabilityCurveMapData;
import org.gridsuite.network.map.dto.definition.extension.ActivePowerControlInfos;
import org.gridsuite.network.map.dto.definition.extension.ConnectablePositionInfos;

import java.util.List;
import java.util.Optional;
Expand All @@ -27,15 +28,15 @@
public class BatteryFormInfos extends ElementInfosWithProperties {
private String voltageLevelId;

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullAndNaNFilter.class)
private Double p;

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullAndNaNFilter.class)
private Double q;

private Double targetP;

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullAndNaNFilter.class)
private Double targetQ;

private Double minP;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
import com.powsybl.iidm.network.Country;
import lombok.Getter;
import lombok.experimental.SuperBuilder;
import org.gridsuite.network.map.config.nan.NullAndNaNFilter;
import org.gridsuite.network.map.dto.ElementInfosWithProperties;
import org.gridsuite.network.map.dto.definition.extension.ActivePowerControlInfos;
import org.gridsuite.network.map.dto.definition.extension.ConnectablePositionInfos;
import org.gridsuite.network.map.dto.common.MinMaxReactiveLimitsMapData;
import org.gridsuite.network.map.dto.common.ReactiveCapabilityCurveMapData;
import org.gridsuite.network.map.dto.definition.extension.ActivePowerControlInfos;
import org.gridsuite.network.map.dto.definition.extension.ConnectablePositionInfos;
import org.gridsuite.network.map.dto.definition.extension.InjectionObservabilityInfos;
import org.gridsuite.network.map.dto.definition.extension.MeasurementsInfos;

Expand All @@ -30,15 +31,15 @@
public class BatteryTabInfos extends ElementInfosWithProperties {
private String voltageLevelId;

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullAndNaNFilter.class)
private Double p;

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullAndNaNFilter.class)
private Double q;

private Double targetP;

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullAndNaNFilter.class)
private Double targetQ;

private Double minP;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.powsybl.iidm.network.Country;
import lombok.Getter;
import lombok.experimental.SuperBuilder;
import org.gridsuite.network.map.config.nan.NullAndNaNFilter;
import org.gridsuite.network.map.dto.ElementInfosWithProperties;
import org.gridsuite.network.map.dto.definition.extension.InjectionObservabilityInfos;
import org.gridsuite.network.map.dto.definition.extension.MeasurementsInfos;
Expand All @@ -36,19 +37,19 @@ public class DanglingLineTabInfos extends ElementInfosWithProperties {
@JsonInclude(JsonInclude.Include.NON_NULL)
private String pairingKey;

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullAndNaNFilter.class)
private Double p;

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullAndNaNFilter.class)
private Double q;

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullAndNaNFilter.class)
private Double p0;

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullAndNaNFilter.class)
private Double q0;

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullAndNaNFilter.class)
private Double i;

@JsonInclude(JsonInclude.Include.NON_ABSENT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Builder;
import lombok.Getter;
import org.gridsuite.network.map.config.nan.NullAndNaNFilter;

/**
* @author Souissi Maissa <maissa.souissi at rte-france.com>
Expand All @@ -15,7 +16,7 @@ public class ActivePowerControlInfos {
@JsonInclude(JsonInclude.Include.NON_NULL)
private Boolean participate;

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullAndNaNFilter.class)
private Double droop;

@JsonInclude(JsonInclude.Include.NON_NULL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import org.gridsuite.network.map.config.nan.NullAndNaNFilter;

/**
* @author Souissi Maissa <maissa.souissi at rte-france.com>
Expand All @@ -16,10 +17,10 @@ public class CoordinatedReactiveControlInfos {

// As this attribute has only one lower case letter at its start (xXXXX), the getters is parsed as getQPercent and the field for Jackson is parsed as qpercent
// while we expect qPercent. JsonProperty let fix the json field to qPercent
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullAndNaNFilter.class)
@JsonProperty("qPercent")
@Getter(AccessLevel.NONE)
private double qPercent;
private Double qPercent;

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Builder;
import lombok.Getter;
import org.gridsuite.network.map.config.nan.NullAndNaNFilter;

/**
* @author Souissi Maissa <maissa.souissi at rte-france.com>
Expand All @@ -12,10 +13,10 @@
@Builder
public class GeneratorShortCircuitInfos {

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullAndNaNFilter.class)
private Double directTransX;

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullAndNaNFilter.class)
private Double stepUpTransformerX;

}
Expand Down
Loading