use of com.microsoft.graph.serializer.DefaultSerializer in project msgraph-sdk-java-core by microsoftgraph.
the class BatchResponseContentTest method includeVerboseInformation.
@Test
public void includeVerboseInformation() {
String responsebody = "{\"responses\":[{\"id\":\"1\",\"status\":400,\"headers\":{\"Cache-Control\":\"no-cache\",\"x-ms-resource-unit\":\"1\",\"Content-Type\":\"application/json\"},\"body\":{\"error\":{\"code\":\"Request_BadRequest\",\"message\":\"Avalueisrequiredforproperty'displayName'ofresource'User'.\",\"innerError\":{\"date\":\"2021-02-02T19:19:38\",\"request-id\":\"408b8e64-4047-4c97-95b6-46e9f212ab48\",\"client-request-id\":\"102910da-260c-3028-0fb3-7d6903a02622\"}}}}]}";
ISerializer serializer = new DefaultSerializer(new DefaultLogger() {
{
setLoggingLevel(LoggerLevel.DEBUG);
}
});
BatchResponseContent batchresponse = serializer.deserializeObject(responsebody, BatchResponseContent.class);
if (batchresponse != null) {
if (// this is done by the batch request in the fluent API
batchresponse.responses != null)
for (final BatchResponseStep<?> step : batchresponse.responses) {
step.serializer = serializer;
}
try {
batchresponse.getResponseById("1").getDeserializedBody(BatchRequestContent.class);
} catch (GraphServiceException ex) {
final GraphErrorResponse response = ex.getError();
assertNotNull(response);
assertNotNull(response.error);
assertNotNull(response.error.message);
assertEquals(ex.getMessage(true), ex.getMessage());
}
} else
fail("batch response was null");
}
use of com.microsoft.graph.serializer.DefaultSerializer in project msgraph-sdk-java-core by microsoftgraph.
the class BatchResponseContentTest method responseParsing.
@Test
public void responseParsing() {
final BatchResponseContent batchResponse = new DefaultSerializer(mock(ILogger.class)).deserializeObject("{\"responses\": [{\"id\": \"1\",\"status\": 200,\"body\": null}]}", BatchResponseContent.class);
assertEquals(1, batchResponse.responses.size());
final BatchResponseStep<?> response = batchResponse.getResponseById("1");
assertNotNull(response);
assertNull(batchResponse.getResponseById("2"));
}
use of com.microsoft.graph.serializer.DefaultSerializer in project java-spring-webhooks-sample by microsoftgraph.
the class ListenController method handleNotification.
/**
* This method receives and processes incoming notifications from Microsoft Graph
*
* @param jsonPayload the JSON body of the request
* @return A 202 Accepted response
*/
@PostMapping("/listen")
public CompletableFuture<ResponseEntity<String>> handleNotification(@RequestBody final String jsonPayload) {
// Deserialize the JSON body into a ChangeNotificationCollection
final var serializer = new DefaultSerializer(new DefaultLogger());
final var notifications = serializer.deserializeObject(jsonPayload, ChangeNotificationCollection.class);
// Check for validation tokens
boolean areTokensValid = true;
if (notifications.validationTokens != null && !notifications.validationTokens.isEmpty()) {
areTokensValid = TokenHelper.areValidationTokensValid(new String[] { clientId }, new String[] { tenantId }, notifications.validationTokens, keyDiscoveryUrl);
}
if (areTokensValid) {
for (ChangeNotification notification : notifications.value) {
// Look up subscription in store
var subscription = subscriptionStore.getSubscription(notification.subscriptionId.toString());
// the client state in the notification matches
if (subscription != null && subscription.clientState.equals(notification.clientState)) {
if (notification.encryptedContent == null) {
// No encrypted content, this is a new message notification
// without resource data
processNewMessageNotification(notification, subscription);
} else {
// With encrypted content, this is a new channel message
// notification with encrypted resource data
processNewChannelMessageNotification(notification, subscription);
}
}
}
}
return CompletableFuture.completedFuture(ResponseEntity.accepted().body(""));
}
use of com.microsoft.graph.serializer.DefaultSerializer in project msgraph-sdk-java by microsoftgraph.
the class DefaultClientConfig method getSerializer.
/**
* Gets the serializer
*
* @return the serializer
*/
@Override
public ISerializer getSerializer() {
if (serializer == null) {
serializer = new DefaultSerializer(getLogger());
getLogger().logDebug("Created DefaultSerializer");
}
return serializer;
}
use of com.microsoft.graph.serializer.DefaultSerializer in project msgraph-sdk-java by microsoftgraph.
the class PlannerTests method testPlannerChecklistItemDeserialization.
@Test
public void testPlannerChecklistItemDeserialization() throws Exception {
String input = "{\"@odata.context\":\"https://graph.microsoft.com/v1.0/$metadata#planner/tasks('433tZlfn_USJwWRL9khDx8kALTM7')/details/$entity\",\"@odata.etag\":\"W/\\\"JzEtVGFza0RldGFpbHMgQEBAQEBAQEBAQEBAQEBAcCc=\\\"\",\"description\":\"This is a test description of test event two.\",\"previewType\":\"automatic\",\"id\":\"433tZlfn_USJwWRL9khDx8kALTM7\",\"references\":{},\"checklist\":{\"55554\":{\"@odata.type\":\"#microsoft.graph.plannerChecklistItem\",\"isChecked\":false,\"title\":\"Test Item 2\",\"orderHint\":\"8586580527[2\",\"lastModifiedDateTime\":\"2018-11-30T05:01:53.0387892Z\",\"lastModifiedBy\":{\"user\":{\"displayName\":null,\"id\":\"ec786dee-da15-4896-8e73-57141477bae7\"}}},\"91100\":{\"@odata.type\":\"#microsoft.graph.plannerChecklistItem\",\"isChecked\":true,\"title\":\"Test Item 1 \",\"orderHint\":\"8586580528393292964Pc\",\"lastModifiedDateTime\":\"2018-11-30T05:01:47.4138223Z\",\"lastModifiedBy\":{\"user\":{\"displayName\":null,\"id\":\"ec786dee-da15-4896-8e73-57141477bae7\"}}}}}";
final DefaultSerializer serializer = new DefaultSerializer(new DefaultLogger());
PlannerTaskDetails ptd = serializer.deserializeObject(input, PlannerTaskDetails.class);
assertNotNull(ptd);
PlannerChecklistItem item1 = ptd.checklist.get("91100");
assertEquals(item1.title, "Test Item 1 ");
PlannerChecklistItem item2 = ptd.checklist.get("55554");
assertEquals(item2.title, "Test Item 2");
}
Aggregations