Skip to content

Commit

Permalink
Revert "Make error message better in json shortcircuit"
Browse files Browse the repository at this point in the history
This reverts commit c19c80e.

Signed-off-by: Coline PILOQUET <coline.piloquet@rte-france.com>
  • Loading branch information
colinepiloquet committed Feb 24, 2023
1 parent 7f73e75 commit 83bdaa7
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/
package com.powsybl.shortcircuit;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.powsybl.commons.json.JsonUtil;
import com.powsybl.shortcircuit.json.ShortCircuitAnalysisJsonModule;
Expand Down Expand Up @@ -78,7 +77,7 @@ static void write(List<Fault> faults, Path jsonFile) {

static List<Fault> read(Path jsonFile) {
try (InputStream is = Files.newInputStream(jsonFile)) {
return createObjectMapper().disable(DeserializationFeature.WRAP_EXCEPTIONS).readerForListOf(Fault.class).readValue(is);
return createObjectMapper().readerForListOf(Fault.class).readValue(is);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/
package com.powsybl.shortcircuit;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.powsybl.commons.json.JsonUtil;
import com.powsybl.shortcircuit.json.ShortCircuitAnalysisJsonModule;
Expand Down Expand Up @@ -144,7 +143,7 @@ public static void write(List<FaultParameters> parameters, Path jsonFile) {

public static List<FaultParameters> read(Path jsonFile) {
try (InputStream is = Files.newInputStream(jsonFile)) {
return createObjectMapper().disable(DeserializationFeature.WRAP_EXCEPTIONS).readerForListOf(FaultParameters.class).readValue(is);
return createObjectMapper().readerForListOf(FaultParameters.class).readValue(is);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
Expand Down Expand Up @@ -98,7 +99,7 @@ void readUnexpectedField() throws IOException {
Files.copy(getClass().getResourceAsStream("/FaultParametersFileInvalid.json"), fileSystem.getPath("/FaultParametersFileInvalid.json"));

Path path = fileSystem.getPath("/FaultParametersFileInvalid.json");
IllegalStateException e = assertThrows(IllegalStateException.class, () -> FaultParameters.read(path));
assertEquals("Unexpected field: unexpected", e.getMessage());
UncheckedIOException e = assertThrows(UncheckedIOException.class, () -> FaultParameters.read(path));
assertEquals("com.fasterxml.jackson.databind.JsonMappingException: Unexpected field: unexpected (through reference chain: java.util.ArrayList[0])", e.getMessage());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/
package com.powsybl.shortcircuit.json;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.powsybl.commons.json.JsonUtil;
import com.powsybl.commons.test.AbstractConverterTest;
Expand Down Expand Up @@ -44,7 +43,7 @@ private static void write(List<FortescueValue> values, Path jsonFile) {

private static List<FortescueValue> read(Path jsonFile) {
try (InputStream is = Files.newInputStream(jsonFile)) {
return createObjectMapper().disable(DeserializationFeature.WRAP_EXCEPTIONS).readerForListOf(FortescueValue.class).readValue(is);
return createObjectMapper().readerForListOf(FortescueValue.class).readValue(is);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
Expand All @@ -62,7 +61,7 @@ void readUnexpectedField() throws IOException {
Files.copy(getClass().getResourceAsStream("/FortescueValueInvalid.json"), fileSystem.getPath("/FortescueValueInvalid.json"));

Path path = fileSystem.getPath("/FortescueValueInvalid.json");
IllegalStateException e = assertThrows(IllegalStateException.class, () -> read(path));
assertEquals("Unexpected field: unexpected", e.getMessage());
UncheckedIOException e = assertThrows(UncheckedIOException.class, () -> read(path));
assertEquals("com.fasterxml.jackson.databind.JsonMappingException: Unexpected field: unexpected (through reference chain: java.util.ArrayList[0])", e.getMessage());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import com.powsybl.shortcircuit.Fault;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
Expand Down Expand Up @@ -40,16 +40,16 @@ void readUnexpectedField() throws IOException {
Files.copy(getClass().getResourceAsStream("/FaultsFileInvalid.json"), fileSystem.getPath("/FaultsFileInvalid.json"));

Path path = fileSystem.getPath("/FaultsFileInvalid.json");
IllegalStateException e = assertThrows(IllegalStateException.class, () -> Fault.read(path));
assertEquals("Unexpected field: unexpected", e.getMessage());
UncheckedIOException e = assertThrows(UncheckedIOException.class, () -> Fault.read(path));
assertEquals("com.fasterxml.jackson.databind.JsonMappingException: Unexpected field: unexpected (through reference chain: java.util.ArrayList[0])", e.getMessage());
}

@Test
void readNoType() throws IOException {
Files.copy(getClass().getResourceAsStream("/FaultsFileNoType.json"), fileSystem.getPath("/FaultsFileNoType.json"));

Path path = fileSystem.getPath("/FaultsFileNoType.json");
IllegalStateException e = assertThrows(IllegalStateException.class, () -> Fault.read(path));
assertEquals("Required type field is missing", e.getMessage());
UncheckedIOException e = assertThrows(UncheckedIOException.class, () -> Fault.read(path));
assertEquals("com.fasterxml.jackson.databind.JsonMappingException: Required type field is missing (through reference chain: java.util.ArrayList[0])", e.getMessage());
}
}

0 comments on commit 83bdaa7

Please sign in to comment.