Skip to content

Commit c3a67f2

Browse files
refactoring: use default methods in ISerializer
1 parent 49bdbb5 commit c3a67f2

3 files changed

Lines changed: 33 additions & 31 deletions

File tree

‎src/main/java/com/microsoft/graph/serializer/DefaultSerializer.java‎

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -73,26 +73,12 @@ public DefaultSerializer(@Nonnull final ILogger logger) {
7373
this.gson = GsonFactory.getGsonInstance(logger);
7474
}
7575

76-
/**
77-
* Deserializes an object from the input string
78-
*
79-
* @param inputStream the string that stores the representation of the item
80-
* @param clazz the class of the item to be deserialized
81-
* @param <T> the type of the item to be deserialized
82-
* @return the deserialized item from the input string
83-
*/
84-
@Override
85-
@Nullable
86-
public <T> T deserializeObject(@Nonnull final InputStream inputStream, @Nonnull final Class<T> clazz) {
87-
return deserializeObject(inputStream, clazz, emptyMap());
88-
}
89-
9076
@SuppressWarnings("unchecked")
9177
@Override
9278
@Nullable
93-
public <T> T deserializeObject(@Nonnull final String inputString, @Nonnull final Class<T> clazz) {
79+
public <T> T deserializeObject(@Nonnull final String inputString, @Nonnull final Class<T> clazz, @Nonnull final Map<String, List<String>> responseHeaders) {
9480
final JsonElement rawElement = gson.fromJson(inputString, JsonElement.class);
95-
return deserializeObject(rawElement, clazz, emptyMap());
81+
return deserializeObject(rawElement, clazz, responseHeaders);
9682
}
9783

9884
@SuppressWarnings("unchecked")

‎src/main/java/com/microsoft/graph/serializer/ISerializer.java‎

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,15 @@
2525
import com.google.gson.JsonElement;
2626

2727
import java.io.InputStream;
28+
import java.util.Collections;
2829
import java.util.List;
2930
import java.util.Map;
3031

3132
import javax.annotation.Nullable;
3233
import javax.annotation.Nonnull;
3334

35+
import static java.util.Collections.emptyMap;
36+
3437
/**
3538
* Serializes and deserializes items from strings into their types
3639
*/
@@ -45,21 +48,37 @@ public interface ISerializer {
4548
* @return the deserialized item from the input string
4649
*/
4750
@Nullable
48-
<T> T deserializeObject(@Nonnull final String inputString, @Nonnull final Class<T> clazz);
51+
default <T> T deserializeObject(@Nonnull final String inputString, @Nonnull final Class<T> clazz) {
52+
return deserializeObject(inputString, clazz, emptyMap());
53+
}
4954

5055
/**
5156
* Deserialize an object from the input string
5257
*
58+
* @param inputString the string that stores the representation of the item
59+
* @param clazz the {@code Class} of the item to be deserialized
60+
* @param responseHeaders the HTTP response headers
61+
* @param <T> the type of the item to be deserialized
62+
* @return the deserialized item from the input string
63+
*/
64+
@Nullable
65+
<T> T deserializeObject(@Nonnull final String inputString, @Nonnull final Class<T> clazz, @Nonnull final Map<String, List<String>> responseHeaders);
66+
67+
/**
68+
* Deserialize an object from the input stream
69+
*
5370
* @param inputStream the stream that stores the representation of the item
5471
* @param clazz the {@code Class} of the item to be deserialized
5572
* @param <T> the type of the item to be deserialized
56-
* @return the deserialized item from the input string
73+
* @return the deserialized item from the input string
5774
*/
5875
@Nullable
59-
<T> T deserializeObject(@Nonnull final InputStream inputStream, @Nonnull final Class<T> clazz);
60-
76+
default <T> T deserializeObject(@Nonnull final InputStream inputStream, @Nonnull final Class<T> clazz) {
77+
return deserializeObject(inputStream, clazz, emptyMap());
78+
}
79+
6180
/**
62-
* Deserialize an object from the input string
81+
* Deserialize an object from the input stream
6382
*
6483
* @param inputStream the stream that stores the representation of the item
6584
* @param clazz the {@code Class} of the item to be deserialized
@@ -71,7 +90,7 @@ public interface ISerializer {
7190
<T> T deserializeObject(@Nonnull final InputStream inputStream, @Nonnull final Class<T> clazz, @Nonnull final Map<String, List<String>> responseHeaders);
7291

7392
/**
74-
* Deserialize an object from the input string
93+
* Deserialize an object from the input JsonElement
7594
*
7695
* @param jsonElement the {@code JsonElement} that stores the representation of the item
7796
* @param clazz the {@code Class} of the item to be deserialized

‎src/test/java/com/microsoft/graph/core/GraphServiceClientTest.java‎

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,26 +77,23 @@ public <T> String serializeObject(T serializableObject) {
7777
return null;
7878
}
7979

80+
@Nullable
8081
@Override
81-
public <T> T deserializeObject(InputStream inputStream, Class<T> clazz,
82+
public <T> T deserializeObject(String inputString, Class<T> clazz,
8283
Map<String, List<String>> responseHeaders) {
8384
return null;
8485
}
8586

86-
@Nullable
8787
@Override
88-
public <T> T deserializeObject(@NotNull JsonElement jsonElement, @NotNull Class<T> clazz, @NotNull Map<String, List<String>> responseHeaders) {
88+
public <T> T deserializeObject(InputStream inputStream, Class<T> clazz,
89+
Map<String, List<String>> responseHeaders) {
8990
return null;
9091
}
9192

9293
@Nullable
9394
@Override
94-
public <T> T deserializeObject(@NotNull String inputString, @NotNull Class<T> clazz) {
95-
return null;
96-
}
97-
98-
@Override
99-
public <T> T deserializeObject(InputStream inputString, Class<T> clazz) {
95+
public <T> T deserializeObject(JsonElement jsonElement, Class<T> clazz,
96+
Map<String, List<String>> responseHeaders) {
10097
return null;
10198
}
10299
};

0 commit comments

Comments
 (0)