diff --git a/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-webapp/src/main/java/com/azure/spring/sample/aad/utils/JsonMapper.java b/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-webapp/src/main/java/com/azure/spring/sample/aad/utils/JsonMapper.java index d26dd5d37680f..0d809634a573a 100644 --- a/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-webapp/src/main/java/com/azure/spring/sample/aad/utils/JsonMapper.java +++ b/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-webapp/src/main/java/com/azure/spring/sample/aad/utils/JsonMapper.java @@ -6,6 +6,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.security.oauth2.client.OAuth2AuthorizedClient; @@ -13,17 +14,18 @@ public class JsonMapper { private static final Logger LOGGER = LoggerFactory.getLogger(JsonMapper.class); private static final ObjectMapper MAPPER = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT); + static { + MAPPER.registerModule(new JavaTimeModule()); + } - public static final String toJsonString(OAuth2AuthorizedClient authorizedClient) { - String clientJsonString = "Json String for OAuth2AuthorizedClient"; - + public static String toJsonString(OAuth2AuthorizedClient authorizedClient) { + String clientJsonString; try { clientJsonString = MAPPER.writeValueAsString(authorizedClient); } catch (JsonProcessingException e) { - LOGGER.warn("Error with transfer OAuth2AuthorizedClient to Json"); + LOGGER.warn("Error when transfer OAuth2AuthorizedClient to Json", e); clientJsonString = "Fail to generate Json String of current OAuth2AuthorizedClient"; } - LOGGER.info(clientJsonString); return clientJsonString; }