Skip to content

Commit 49e0e57

Browse files
authored
Have azure-core models implement JsonSerializable (Azure#37046)
Have azure-core models implement JsonSerializable
1 parent 070443e commit 49e0e57

File tree

27 files changed

+1245
-315
lines changed

27 files changed

+1245
-315
lines changed

sdk/core/azure-core-serializer-json-jackson/src/test/java/com/azure/core/serializer/json/jackson/implementation/GeoJsonDeserializerTests.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,21 @@ public class GeoJsonDeserializerTests {
4242
@Test
4343
public void jsonWithoutTypeThrows() {
4444
String missingType = "{\"coordinates\":[0,0]}";
45-
Assertions.assertThrows(IllegalStateException.class,
45+
Assertions.assertThrows(IOException.class,
4646
() -> ADAPTER.deserialize(missingType, GeoObject.class, SerializerEncoding.JSON));
4747
}
4848

4949
@Test
5050
public void jsonWithoutCoordinatesThrows() {
5151
String missingCoordinates = "{\"type\":\"Point\"}";
52-
Assertions.assertThrows(IllegalStateException.class,
52+
Assertions.assertThrows(IOException.class,
5353
() -> ADAPTER.deserialize(missingCoordinates, GeoPoint.class, SerializerEncoding.JSON));
5454
}
5555

5656
@Test
5757
public void unknownGeoTypeThrows() {
5858
String unknownType = "{\"type\":\"Custom\",\"coordinates\":[0,0]}";
59-
Assertions.assertThrows(IllegalStateException.class,
59+
Assertions.assertThrows(IOException.class,
6060
() -> ADAPTER.deserialize(unknownType, GeoObject.class, SerializerEncoding.JSON));
6161
}
6262

@@ -66,7 +66,7 @@ public void unknownGeoTypeThrows() {
6666
"{\"type\":\"Point\",\"coordinates\":[4,4,4,4]}"
6767
})
6868
public void invalidCoordinateCountThrows(String invalidCoordinateCount) {
69-
Assertions.assertThrows(IllegalStateException.class,
69+
Assertions.assertThrows(IOException.class,
7070
() -> ADAPTER.deserialize(invalidCoordinateCount, GeoPoint.class, SerializerEncoding.JSON));
7171
}
7272

@@ -76,14 +76,14 @@ public void invalidCoordinateCountThrows(String invalidCoordinateCount) {
7676
"{\"type\":\"Point\",\"coordinates\":[0,0],\"bbox\":[8,8,8,8,8,8,8,8]}"
7777
})
7878
public void invalidBoundBoxThrows(String invalidBoundBox) {
79-
Assertions.assertThrows(IllegalStateException.class,
79+
Assertions.assertThrows(IOException.class,
8080
() -> ADAPTER.deserialize(invalidBoundBox, GeoPoint.class, SerializerEncoding.JSON));
8181
}
8282

8383
@Test
8484
public void collectionWithoutGeometriesThrows() {
8585
String invalidCollection = "{\"type\":\"GeometryCollection\"}";
86-
Assertions.assertThrows(IllegalStateException.class,
86+
Assertions.assertThrows(IOException.class,
8787
() -> ADAPTER.deserialize(invalidCollection, GeoCollection.class, SerializerEncoding.JSON));
8888
}
8989

sdk/core/azure-core-serializer-json-jackson/src/test/java/com/azure/core/serializer/json/jackson/implementation/GeoJsonSerializerTests.java

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import com.azure.core.models.GeoLineStringCollection;
1010
import com.azure.core.models.GeoLinearRing;
1111
import com.azure.core.models.GeoObject;
12-
import com.azure.core.models.GeoObjectType;
1312
import com.azure.core.models.GeoPoint;
1413
import com.azure.core.models.GeoPointCollection;
1514
import com.azure.core.models.GeoPolygon;
@@ -19,7 +18,6 @@
1918
import com.azure.core.util.serializer.SerializerAdapter;
2019
import com.azure.core.util.serializer.SerializerEncoding;
2120
import org.junit.jupiter.api.Assertions;
22-
import org.junit.jupiter.api.Test;
2321
import org.junit.jupiter.params.ParameterizedTest;
2422
import org.junit.jupiter.params.provider.Arguments;
2523
import org.junit.jupiter.params.provider.MethodSource;
@@ -39,23 +37,6 @@
3937
public class GeoJsonSerializerTests {
4038
private static final SerializerAdapter ADAPTER = JacksonAdapter.defaultSerializerAdapter();
4139

42-
@Test
43-
public void unknownGeoTypeThrows() {
44-
Assertions.assertThrows(IOException.class,
45-
() -> ADAPTER.serialize(new CustomGeoObject(null, null), SerializerEncoding.JSON));
46-
}
47-
48-
private static final class CustomGeoObject extends GeoObject {
49-
protected CustomGeoObject(GeoBoundingBox boundingBox, Map<String, Object> properties) {
50-
super(boundingBox, properties);
51-
}
52-
53-
@Override
54-
public GeoObjectType getType() {
55-
return null;
56-
}
57-
}
58-
5940
@ParameterizedTest
6041
@MethodSource("serializeSupplier")
6142
public <T extends GeoObject> void serialize(T geo, String expectedJson) throws IOException {

sdk/core/azure-core-version-tests/src/test/java/com/azure/core/version/tests/CustomSerializerTests.java

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import com.azure.core.models.GeoLineStringCollection;
1010
import com.azure.core.models.GeoLinearRing;
1111
import com.azure.core.models.GeoObject;
12-
import com.azure.core.models.GeoObjectType;
1312
import com.azure.core.models.GeoPoint;
1413
import com.azure.core.models.GeoPointCollection;
1514
import com.azure.core.models.GeoPolygon;
@@ -19,7 +18,6 @@
1918
import com.azure.core.util.serializer.SerializerAdapter;
2019
import com.azure.core.util.serializer.SerializerEncoding;
2120
import org.junit.jupiter.api.Assertions;
22-
import org.junit.jupiter.api.Test;
2321
import org.junit.jupiter.params.ParameterizedTest;
2422
import org.junit.jupiter.params.provider.Arguments;
2523
import org.junit.jupiter.params.provider.MethodSource;
@@ -142,7 +140,7 @@ private static Stream<Arguments> toStringTestSupplier() {
142140
@ParameterizedTest
143141
@MethodSource("invalidGeoJsonDeserializationSupplier")
144142
public void invalidGeoJsonDeserializationThrowsIllegalStateException(String invalidGeoJson) {
145-
Assertions.assertThrows(IllegalStateException.class,
143+
Assertions.assertThrows(IOException.class,
146144
() -> ADAPTER.deserialize(invalidGeoJson, GeoObject.class, SerializerEncoding.JSON));
147145
}
148146

@@ -258,23 +256,6 @@ private static Object[] deserializerArgumentSupplier(GeoBoundingBox boundingBox,
258256
return new Object[]{GeoSerializationTestHelpers.geoToJson(geoObject), geoObject.getClass(), geoObject};
259257
}
260258

261-
@Test
262-
public void unknownGeoTypeSerializationThrows() {
263-
Assertions.assertThrows(IOException.class,
264-
() -> ADAPTER.serialize(new CustomGeoObject(null, null), SerializerEncoding.JSON));
265-
}
266-
267-
private static final class CustomGeoObject extends GeoObject {
268-
protected CustomGeoObject(GeoBoundingBox boundingBox, Map<String, Object> properties) {
269-
super(boundingBox, properties);
270-
}
271-
272-
@Override
273-
public GeoObjectType getType() {
274-
return null;
275-
}
276-
}
277-
278259
@ParameterizedTest
279260
@MethodSource("geoJsonSerializationSupplier")
280261
public <T extends GeoObject> void geoJsonSerialization(T geo, String expectedJson) throws IOException {

sdk/core/azure-core-version-tests/src/test/java/com/azure/core/version/tests/ResponseErrorDeserializerTests.java

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
import com.azure.core.models.ResponseError;
77
import com.azure.core.util.serializer.JacksonAdapter;
88
import com.azure.core.util.serializer.SerializerEncoding;
9-
import com.fasterxml.jackson.databind.exc.MismatchedInputException;
10-
import org.junit.jupiter.api.Assertions;
11-
import org.junit.jupiter.api.Test;
129
import org.junit.jupiter.params.ParameterizedTest;
1310
import org.junit.jupiter.params.provider.Arguments;
1411
import org.junit.jupiter.params.provider.MethodSource;
@@ -25,38 +22,22 @@ public class ResponseErrorDeserializerTests {
2522
private static final JacksonAdapter MAPPER = new JacksonAdapter();
2623

2724
@ParameterizedTest
28-
@MethodSource("deserializeOffsetDateTimeSupplier")
25+
@MethodSource("deserializeResponseErrorSupplier")
2926
public void deserializeJson(String responseWithError, String expectedCode, String expectedMessage) throws IOException {
3027
ResponseError deserialize = MAPPER.deserialize(responseWithError, ResponseError.class, SerializerEncoding.JSON);
3128
assertEquals(expectedCode, deserialize.getCode());
3229
assertEquals(expectedMessage, deserialize.getMessage());
3330
}
3431

35-
@Test
36-
public void deserializeResponseErrorMissingRequiredProperty() {
37-
// code is a required property and exception should be thrown if it's missing
38-
String missingCodeWithErrorWrapper = "{\"error\": {\"message\": \"Invalid syntax\"}}";
39-
Assertions.assertThrows(MismatchedInputException.class, () -> MAPPER.deserialize(missingCodeWithErrorWrapper, ResponseError.class, SerializerEncoding.JSON));
40-
41-
String missingCodeWithoutErrorWrapper = "{\"message\": \"Invalid syntax\"}";
42-
Assertions.assertThrows(MismatchedInputException.class, () -> MAPPER.deserialize(missingCodeWithoutErrorWrapper, ResponseError.class, SerializerEncoding.JSON));
43-
44-
// message is a required property and exception should be thrown if it's missing
45-
String missingMessageWithErrorWrapper = "{\"error\": {\"code\": \"BAD_QUERY_FORMAT\"}}";
46-
Assertions.assertThrows(MismatchedInputException.class, () -> MAPPER.deserialize(missingMessageWithErrorWrapper, ResponseError.class, SerializerEncoding.JSON));
47-
48-
String missingMessageWithoutErrorWrapper = "{\"code\": \"BAD_QUERY_FORMAT\"}";
49-
Assertions.assertThrows(MismatchedInputException.class, () -> MAPPER.deserialize(missingMessageWithoutErrorWrapper, ResponseError.class, SerializerEncoding.JSON));
50-
}
51-
52-
private static Stream<Arguments> deserializeOffsetDateTimeSupplier() {
53-
32+
private static Stream<Arguments> deserializeResponseErrorSupplier() {
5433
return Stream.of(
55-
Arguments.of("{\"error\": {\"code\": \"BAD_QUERY_FORMAT\", \"message\": \"Invalid syntax\"}}", "BAD_QUERY_FORMAT", "Invalid syntax"),
56-
Arguments.of("{\"code\": \"BAD_QUERY_FORMAT\", \"message\": \"Invalid syntax\"}", "BAD_QUERY_FORMAT", "Invalid syntax"),
57-
Arguments.of("{\"name\": \"foo\", \"error\": {\"code\": \"BAD_QUERY_FORMAT\", \"message\": \"Invalid syntax\"}}", "BAD_QUERY_FORMAT", "Invalid syntax"),
58-
Arguments.of("{\"name\": \"foo\", \"code\": \"BAD_QUERY_FORMAT\", \"message\": \"Invalid syntax\"}", "BAD_QUERY_FORMAT", "Invalid syntax")
59-
);
34+
Arguments.of("{\"error\":{\"code\":\"BAD_QUERY_FORMAT\",\"message\":\"Invalid syntax\"}}",
35+
"BAD_QUERY_FORMAT", "Invalid syntax"),
36+
Arguments.of("{\"code\":\"BAD_QUERY_FORMAT\",\"message\":\"Invalid syntax\"}", "BAD_QUERY_FORMAT",
37+
"Invalid syntax"),
38+
Arguments.of("{\"name\":\"foo\",\"error\":{\"code\":\"BAD_QUERY_FORMAT\",\"message\":\"Invalid syntax\"}}",
39+
"BAD_QUERY_FORMAT", "Invalid syntax"),
40+
Arguments.of("{\"name\":\"foo\",\"code\":\"BAD_QUERY_FORMAT\",\"message\":\"Invalid syntax\"}",
41+
"BAD_QUERY_FORMAT", "Invalid syntax"));
6042
}
61-
6243
}

0 commit comments

Comments
 (0)