Skip to content
Merged
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
Expand Up @@ -72,6 +72,11 @@ public DefaultSerializer(@Nonnull final ILogger logger) {
/**
* Creates a DefaultSerializer with an option to enable serializing of the null values.
*
* Serializing of null values can have side effects on the service behavior.
* Sending null values in a PATCH request might reset existing values on the service side.
* Sending null values in a POST request might prevent the service from assigning default values to the properties.
* It is not recommended to send null values to the service in general and this setting should only be used when serializing information for a local store.
*
* @param logger the logger
* @param serializeNulls the setting of whether or not to serialize the null values in the JSON object
*/
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/microsoft/graph/serializer/GsonFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ public static Gson getGsonInstance(@Nonnull final ILogger logger) {
/**
* Creates an instance of GSON
*
* Serializing of null values can have side effects on the service behavior.
* Sending null values in a PATCH request might reset existing values on the service side.
* Sending null values in a POST request might prevent the service from assigning default values to the properties.
* It is not recommended to send null values to the service in general and this setting should only be used when serializing information for a local store.
*
* @param logger the logger
* @param serializeNulls the setting of whether or not to serialize the null values in the JSON object
* @return the new instance
Expand Down
26 changes: 13 additions & 13 deletions src/test/java/com/microsoft/graph/http/CoreHttpProviderTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

public class CoreHttpProviderTests {
class CoreHttpProviderTests {

private CoreHttpProvider mProvider;
private Gson GSON = new GsonBuilder().create();

@Test
public void testErrorResponse() throws Exception {
void testErrorResponse() throws Exception {
final GraphErrorCodes expectedErrorCode = GraphErrorCodes.INVALID_REQUEST;
final String expectedMessage = "Test error!";
final GraphErrorResponse toSerialize = new GraphErrorResponse();
Expand All @@ -85,7 +85,7 @@ public void testErrorResponse() throws Exception {
}

@Test
public void testVerboseErrorResponse() throws Exception {
void testVerboseErrorResponse() throws Exception {
final GraphErrorCodes expectedErrorCode = GraphErrorCodes.INVALID_REQUEST;
final String expectedMessage = "Test error!";
final GraphErrorResponse toSerialize = new GraphErrorResponse();
Expand Down Expand Up @@ -119,25 +119,25 @@ public void testVerboseErrorResponse() throws Exception {
}

@Test
public void testHasHeaderReturnsTrue() {
void testHasHeaderReturnsTrue() {
HeaderOption h = new HeaderOption("name", "value");
assertTrue(CoreHttpProvider.hasHeader(Arrays.asList(h), "name"));
}

@Test
public void testHasHeaderReturnsTrueWhenDifferentCase() {
void testHasHeaderReturnsTrueWhenDifferentCase() {
HeaderOption h = new HeaderOption("name", "value");
assertTrue(CoreHttpProvider.hasHeader(Arrays.asList(h), "NAME"));
}

@Test
public void testHasHeaderReturnsFalse() {
void testHasHeaderReturnsFalse() {
HeaderOption h = new HeaderOption("name", "value");
assertFalse(CoreHttpProvider.hasHeader(Arrays.asList(h), "blah"));
}

@Test
public void testStreamToStringReturnsData() {
void testStreamToStringReturnsData() {
String data = GSON.toJson(Maps.newHashMap(
ImmutableMap.<String, String>builder()
.put("key", "value")
Expand All @@ -149,14 +149,14 @@ public void testStreamToStringReturnsData() {
}

@Test
public void testStreamToStringReturnsEmpty() {
void testStreamToStringReturnsEmpty() {
final InputStream inputStream = new ByteArrayInputStream(new byte[0]);

String convertedData = CoreHttpProvider.streamToString(inputStream);
assertEquals("", convertedData);
}
@Test
public void emptyPostContentTypeIsNotReset() {
void emptyPostContentTypeIsNotReset() {
final String contentTypeValue = "application/json";
final HeaderOption ctype = new HeaderOption("Content-Type", contentTypeValue);
final ArrayList<Option> options = new ArrayList<>();
Expand All @@ -173,7 +173,7 @@ public void emptyPostContentTypeIsNotReset() {
assertEquals(contentTypeValue, request.body().contentType().toString());
}
@Test
public void emptyPostContentTypeIsNotSet() {
void emptyPostContentTypeIsNotSet() {
final IHttpRequest absRequest = new BaseRequest<String>("https://localhost", mock(IBaseClient.class), Collections.emptyList(), String.class) {{
this.setHttpMethod(HttpMethod.POST);
}};
Expand Down Expand Up @@ -210,7 +210,7 @@ private void setCoreHttpProvider(final Object toSerialize) throws IOException {
mClient);
}
@Test
public void getHttpRequestDoesntSetRetryOrRedirectOptionsOnDefaultValues() throws MalformedURLException {
void getHttpRequestDoesntSetRetryOrRedirectOptionsOnDefaultValues() throws MalformedURLException {
final IHttpRequest absRequest = mock(IHttpRequest.class);
when(absRequest.getRequestUrl()).thenReturn(new URL("https://graph.microsoft.com/v1.0/me"));
when(absRequest.getHttpMethod()).thenReturn(HttpMethod.GET);
Expand Down Expand Up @@ -239,7 +239,7 @@ public void getHttpRequestDoesntSetRetryOrRedirectOptionsOnDefaultValues() throw
}

@Test
public void getHttpRequestSetsRetryOrRedirectOptionsOnNonDefaultValues() throws MalformedURLException {
void getHttpRequestSetsRetryOrRedirectOptionsOnNonDefaultValues() throws MalformedURLException {
final IHttpRequest absRequest = mock(IHttpRequest.class);
when(absRequest.getRequestUrl()).thenReturn(new URL("https://graph.microsoft.com/v1.0/me"));
when(absRequest.getHttpMethod()).thenReturn(HttpMethod.GET);
Expand Down Expand Up @@ -295,7 +295,7 @@ public void getHttpRequestSetsRetryOrRedirectOptionsOnNonDefaultValues() throws
}

@Test
public void getHttpRequestWithTextPlainBodyDoesNotSerializeAsJson() throws IOException {
void getHttpRequestWithTextPlainBodyDoesNotSerializeAsJson() throws IOException {
final IHttpRequest absRequest = mock(IHttpRequest.class);
when(absRequest.getRequestUrl()).thenReturn(new URL("https://graph.microsoft.com/v1.0/me"));
when(absRequest.getHttpMethod()).thenReturn(HttpMethod.POST);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;

public class DefaultSerializerTest {
class DefaultSerializerTest {

final ILogger logger = mock(ILogger.class);
Gson gson = GsonFactory.getGsonInstance(logger);
DefaultSerializer defaultSerializer = new DefaultSerializer(logger);

@Test
public void testDeserializationOfObjectWithODataTypeProperty() {
void testDeserializationOfObjectWithODataTypeProperty() {
// Given
final String testJsonResponse =
"{\"@odata.type\": \"#microsoft.graph.subReactionStub1\"}";
Expand All @@ -36,7 +36,7 @@ public void testDeserializationOfObjectWithODataTypeProperty() {
}

@Test
public void testDefaultSerializerDoesNotIncludeNullValuesByDefault() {
void testDefaultSerializerDoesNotIncludeNullValuesByDefault() {
// Given
final String testJsonResponse =
"{\"@odata.type\": \"#microsoft.graph.messageStub\", \"body\": null}";
Expand All @@ -50,7 +50,7 @@ public void testDefaultSerializerDoesNotIncludeNullValuesByDefault() {
}

@Test
public void testDefaultNullSerializerDoesIncludeNullValues() {
void testDefaultNullSerializerDoesIncludeNullValues() {
// Given
final String testJsonResponse =
"{\"@odata.type\": \"#microsoft.graph.messageStub\",\"body\":null}";
Expand Down