Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ObjectMapperShim in all core packages, deprecate direct ObjectMapper usage #24138

Merged
merged 5 commits into from
Sep 21, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -14,6 +14,6 @@ public final class AzureJacksonAdapter extends JacksonAdapter {
* Creates an instance of the Azure flavored Jackson adapter.
*/
public AzureJacksonAdapter() {
super((mapper, innerMapper) -> mapper.registerModule(ManagementErrorDeserializer.getModule(innerMapper)));
super((outerMapper, innerMapper) -> outerMapper.registerModule(ManagementErrorDeserializer.getModule(innerMapper)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ public ObjectMapper createXmlMapper() {
.enable(FromXmlParser.Feature.EMPTY_ELEMENT_AS_NULL)
.build();


if (useReflectionToSetCoercion) {
try {
Object object = coersionConfigDefaults.invoke(xmlMapper);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,7 @@ public String convertMemberName(Member member) {
}
}

public <T extends JsonNode> T valueToTree(Object fromValue)
throws IllegalArgumentException {
public <T extends JsonNode> T valueToTree(Object fromValue) {
try {
return mapper.valueToTree(fromValue);
} catch (LinkageError ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,27 @@ public JacksonAdapter() {
}

/**
* Creates a new JacksonAdapter instance with default mapper settings and additional
* configuration.
* Creates a new JacksonAdapter instance with Azure Core mapper settings and applies
* additional configuration through {@code configureSerialization} callback.
*
* @param configure Function that applies additional configuration to outer
* mapper using inner (simple) mapper for module chaining.
* {@code configureSerialization} callback provides outer and inner instances of {@link ObjectMapper}.
* Both of them are pre-configured for Azure serialization needs, but only outer is mapper capable of
* flattening and populating additionalProperties. Outer module is used by {@code JacksonAdapter} for
* all serialization needs.
*
* Register custom modules on the outer instance to add custom (de)serializers similar to
* {@code new JacksonAdapter((outer, inner) -> outer.registerModule(new MyModule()))}
*
* Use inner mapper for chaining serialization logic in your (de)serializers.
*
* @param configureSerialization Applies additional configuration to outer
* mapper using inner mapper for module chaining.
*/
public JacksonAdapter(BiConsumer<ObjectMapper, ObjectMapper> configure) {
public JacksonAdapter(BiConsumer<ObjectMapper, ObjectMapper> configureSerialization) {
lmolkova marked this conversation as resolved.
Show resolved Hide resolved
this.headerMapper = ObjectMapperShim.createHeaderMapper();
this.xmlMapper = ObjectMapperShim.createXmlMapper();
this.mapper = ObjectMapperShim.createJsonMapper(ObjectMapperShim.createSimpleMapper(),
(outerMapper, innerMapper) -> captureRawMappersAndConfigure(outerMapper, innerMapper, configure));
(outerMapper, innerMapper) -> captureRawMappersAndConfigure(outerMapper, innerMapper, configureSerialization));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,7 @@
* Tests for {@link Option} that can represent tri-sate (non-null-value, null-value, or no-value).
*/
public class OptionSerializerTests {
private static final JacksonAdapter ADAPTER;

static {
JacksonAdapter adapter = new JacksonAdapter((mapper, innerMapper) -> mapper.registerModule(new OptionModule()));

ADAPTER = adapter;
}
private static final JacksonAdapter ADAPTER = new JacksonAdapter((outerMapper, innerMapper) -> outerMapper.registerModule(new OptionModule()));

@Test
public void canSerializeExplicitNull() throws IOException {
Expand Down