Skip to content

Commit

Permalink
Shim for ObjectMapper
Browse files Browse the repository at this point in the history
  • Loading branch information
lmolkova committed Aug 19, 2021
1 parent 6bd4054 commit ccc4edc
Show file tree
Hide file tree
Showing 56 changed files with 1,437 additions and 468 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -661,10 +661,10 @@
<!-- Serializers define non-transient non-serializable instance field -->
<Match>
<Or>
<Class name="com.azure.core.util.serializer.FlatteningSerializer"/>
<Class name="com.azure.core.util.serializer.FlatteningDeserializer"/>
<Class name="com.azure.core.util.serializer.AdditionalPropertiesSerializer"/>
<Class name="com.azure.core.util.serializer.AdditionalPropertiesDeserializer"/>
<Class name="com.azure.core.implementation.jackson.FlatteningSerializer"/>
<Class name="com.azure.core.implementation.jackson.FlatteningDeserializer"/>
<Class name="com.azure.core.implementation.jackson.AdditionalPropertiesSerializer"/>
<Class name="com.azure.core.implementation.jackson.AdditionalPropertiesDeserializer"/>
</Or>
<Bug pattern="SE_BAD_FIELD"/>
</Match>
Expand Down
122 changes: 106 additions & 16 deletions sdk/core/azure-core-jackson-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -163,36 +163,49 @@
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version> <!-- {x-version-update;org.apache.maven.plugins:maven-surefire-plugin;external_dependency} -->
<configuration>
<dependenciesToScan>
<dependency>com.azure:azure-core</dependency>
</dependenciesToScan>
<excludes>
<!-- TODO(limolkova) requires azure-core test resources-->
<exclude>**/RestProxyXMLTests.java</exclude>
</excludes>
</configuration>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.2</version> <!-- {x-version-update;org.apache.maven.plugins:maven-jar-plugin;external_dependency} -->
<executions>
<execution>
<id>test-jar</id>
<phase>test-compile</phase>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>java-lts</id>
<id>default</id>
<activation>
<jdk>[11,)</jdk>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version> <!-- {x-version-update;org.apache.maven.plugins:maven-surefire-plugin;external_dependency} -->
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</build>

</profile>

<profile>
<id>jackson-version-test-matrix</id>
<id>jackson-supported-version-test-matrix</id>
<activation>
<property><name>env.AZURE_CORE_TEST_JACKSON_VERSION</name></property>
<property><name>env.AZURE_CORE_TEST_SUPPORTED_JACKSON_VERSION</name></property>
</activation>
<properties>
<jackson.version>${env.AZURE_CORE_TEST_JACKSON_VERSION}</jackson.version>
<jackson.version>${env.AZURE_CORE_TEST_SUPPORTED_JACKSON_VERSION}</jackson.version>
</properties>
<dependencies>
<!--Have to redeclare dependencies here to allow x-version-update script to work properly-->
Expand Down Expand Up @@ -226,8 +239,85 @@
<version>${jackson.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version> <!-- {x-version-update;org.apache.maven.plugins:maven-surefire-plugin;external_dependency} -->
<configuration>
<dependenciesToScan>
<dependency>com.azure:azure-core</dependency>
</dependenciesToScan>
<excludes>
<!-- TODO(limolkova) requires azure-core test resources-->
<exclude>**/RestProxyXMLTests.java</exclude>
<exclude>**/UnsupportedJacksonVersionsTests.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</profile>

<profile>
<id>jackson-unsupported-version-test</id>
<activation>
<property><name>env.AZURE_CORE_TEST_UNSUPPORTED_JACKSON_VERSION</name></property>
</activation>
<properties>
<jackson.version>${env.AZURE_CORE_TEST_UNSUPPORTED_JACKSON_VERSION}</jackson.version>
</properties>
<dependencies>
<!--Have to redeclare dependencies here to allow x-version-update script to work properly-->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>${jackson.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${jackson.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>${jackson.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<version>${jackson.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version> <!-- {x-version-update;org.apache.maven.plugins:maven-surefire-plugin;external_dependency} -->
<configuration>
<includes>
<include>**/UnsupportedJacksonVersionsTests.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>

</profile>
</profiles>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.core.implementation.jackson;

import com.azure.core.util.CoreUtils;
import com.azure.core.util.serializer.JacksonAdapter;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertThrows;

public class UnsupportedJacksonVersionsTests {
@Test
public void testme() {
String jacksonVersionString = ObjectMapper.class.getPackage().getImplementationVersion();
String azureCoreVersion = CoreUtils
.getProperties("azure-core.properties")
.getOrDefault("version", null);

JacksonVersion version = JacksonVersion.getInstance();
String helpInfo = version.getHelpInfo();
assertTrue(helpInfo.contains("jackson-annotations=" + jacksonVersionString));
assertTrue(helpInfo.contains("jackson-core=" + jacksonVersionString));
assertTrue(helpInfo.contains("jackson-databind=" + jacksonVersionString));
assertTrue(helpInfo.contains("jackson-dataformat-xml=" + jacksonVersionString));
assertTrue(helpInfo.contains("jackson-datatype-jsr310=" + jacksonVersionString));
assertTrue(helpInfo.contains("azure-core=" + azureCoreVersion));

Error error = assertThrows(Error.class, () -> new JacksonAdapter());
assertTrue(error.getMessage().contains(helpInfo));
}
}
1 change: 1 addition & 0 deletions sdk/core/azure-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@
--add-opens com.azure.core/com.azure.core.implementation.models.jsonflatten=com.fasterxml.jackson.databind
--add-opens com.azure.core/com.azure.core.implementation.models.jsonflatten=ALL-UNNAMED
--add-opens com.azure.core/com.azure.core.implementation.serializer=ALL-UNNAMED
--add-opens com.azure.core/com.azure.core.implementation.jackson=ALL-UNNAMED
--add-opens com.azure.core/com.azure.core.models=ALL-UNNAMED
--add-opens com.azure.core/com.azure.core.util=ALL-UNNAMED
--add-opens com.azure.core/com.azure.core.util.logging=ALL-UNNAMED
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@
import com.azure.core.http.HttpRequest;
import com.azure.core.http.HttpResponse;
import com.azure.core.implementation.http.HttpPipelineCallContextHelper;
import com.azure.core.implementation.jackson.ObjectMapperShim;
import com.azure.core.util.Context;
import com.azure.core.util.CoreUtils;
import com.azure.core.util.UrlBuilder;
import com.azure.core.util.logging.ClientLogger;
import com.azure.core.util.logging.LogLevel;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import reactor.core.publisher.Mono;

import java.io.ByteArrayOutputStream;
Expand All @@ -37,7 +36,7 @@
* The pipeline policy that handles logging of HTTP requests and responses.
*/
public class HttpLoggingPolicy implements HttpPipelinePolicy {
private static final ObjectMapper PRETTY_PRINTER = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT);
private static final ObjectMapperShim PRETTY_PRINTER = ObjectMapperShim.createPrettyPrintMapper();
private static final int MAX_BODY_LOG_SIZE = 1024 * 16;
private static final String REDACTED_PLACEHOLDER = "REDACTED";

Expand Down
Loading

0 comments on commit ccc4edc

Please sign in to comment.