style: format code with spotless
All checks were successful
Build, test and publish the Quarkus libraries / build (push) Successful in 1m22s
All checks were successful
Build, test and publish the Quarkus libraries / build (push) Successful in 1m22s
This commit is contained in:
parent
e5e100076c
commit
40598dbe87
17 changed files with 88 additions and 155 deletions
|
@ -9,5 +9,4 @@ public interface JsonService {
|
|||
<T> T fromJson(String json, Class<T> clazz);
|
||||
|
||||
<T> T fromJson(String json, TypeReference<T> typeReference);
|
||||
|
||||
}
|
||||
|
|
|
@ -30,10 +30,9 @@ class JsonServiceImpl implements JsonService {
|
|||
try {
|
||||
return objectMapper.readValue(json, clazz);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new IllegalArgumentException("Unable to read object of class [" + clazz.getName()
|
||||
+ "] from json String: " + json, e);
|
||||
throw new IllegalArgumentException(
|
||||
"Unable to read object of class [" + clazz.getName() + "] from json String: " + json, e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -41,8 +40,10 @@ class JsonServiceImpl implements JsonService {
|
|||
try {
|
||||
return objectMapper.readValue(json, typeReference);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new IllegalArgumentException("Unable to read object of type [" + typeReference.getType().getTypeName()
|
||||
+ "] from json String: " + json, e);
|
||||
throw new IllegalArgumentException(
|
||||
"Unable to read object of type [" + typeReference.getType().getTypeName() + "] from json String: "
|
||||
+ json,
|
||||
e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,24 +1,21 @@
|
|||
package ch.phoenixtechnologies.quarkus.commons.json;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import jakarta.inject.Inject;
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import jakarta.inject.Inject;
|
||||
import java.util.List;
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@QuarkusTest
|
||||
class JsonServiceImplTest {
|
||||
|
||||
public static final TypeReference<List<TestRecord>> TYPE_REFERENCE = new TypeReference<>() {
|
||||
};
|
||||
public static final TypeReference<List<TestRecord>> TYPE_REFERENCE = new TypeReference<>() {};
|
||||
|
||||
record TestRecord(String name, int age) {
|
||||
}
|
||||
record TestRecord(String name, int age) {}
|
||||
|
||||
@Inject
|
||||
JsonServiceImpl jsonService;
|
||||
|
@ -29,9 +26,7 @@ class JsonServiceImplTest {
|
|||
|
||||
var actual = jsonService.toJson(new TestRecord("John Doe", 30));
|
||||
|
||||
assertThat(actual)
|
||||
.as("Json should match expected value")
|
||||
.isEqualTo(expected);
|
||||
assertThat(actual).as("Json should match expected value").isEqualTo(expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -41,9 +36,7 @@ class JsonServiceImplTest {
|
|||
|
||||
var actual = jsonService.fromJson(json, TestRecord.class);
|
||||
|
||||
assertThat(actual)
|
||||
.as("Deserialized object should match expected value")
|
||||
.isEqualTo(expected);
|
||||
assertThat(actual).as("Deserialized object should match expected value").isEqualTo(expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -53,7 +46,8 @@ class JsonServiceImplTest {
|
|||
assertThatThrownBy(() -> jsonService.fromJson(json, TestRecord.class))
|
||||
.as("Should throw IllegalArgumentException when input is invalid")
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("Unable to read object of class [ch.phoenixtechnologies.quarkus.commons.json.JsonServiceImplTest$TestRecord] from json String: {\"name\":\"John Doe\",\"age\":\"30\"");
|
||||
.hasMessage(
|
||||
"Unable to read object of class [ch.phoenixtechnologies.quarkus.commons.json.JsonServiceImplTest$TestRecord] from json String: {\"name\":\"John Doe\",\"age\":\"30\"");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -75,6 +69,7 @@ class JsonServiceImplTest {
|
|||
assertThatThrownBy(() -> jsonService.fromJson(json, TYPE_REFERENCE))
|
||||
.as("Should throw IllegalArgumentException when input is invalid")
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("Unable to read object of type [java.util.List<ch.phoenixtechnologies.quarkus.commons.json.JsonServiceImplTest$TestRecord>] from json String: {\"name\":\"John Doe\",\"age\":30},{\"name\":\"Jane Doe\",\"age\":\"25\"}");
|
||||
.hasMessage(
|
||||
"Unable to read object of type [java.util.List<ch.phoenixtechnologies.quarkus.commons.json.JsonServiceImplTest$TestRecord>] from json String: {\"name\":\"John Doe\",\"age\":30},{\"name\":\"Jane Doe\",\"age\":\"25\"}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue