processing order for Jackson/Jaxb annotations
Signed-off-by: Maxim Nesen <maxim.nesen@oracle.com>
diff --git a/media/json-jackson/src/main/java/org/glassfish/jersey/jackson/internal/DefaultJacksonJaxbJsonProvider.java b/media/json-jackson/src/main/java/org/glassfish/jersey/jackson/internal/DefaultJacksonJaxbJsonProvider.java
index 8b4ce1c..8219cb1 100644
--- a/media/json-jackson/src/main/java/org/glassfish/jersey/jackson/internal/DefaultJacksonJaxbJsonProvider.java
+++ b/media/json-jackson/src/main/java/org/glassfish/jersey/jackson/internal/DefaultJacksonJaxbJsonProvider.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2020, 2021 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -17,10 +17,11 @@
package org.glassfish.jersey.jackson.internal;
import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.Module;
import org.glassfish.jersey.jackson.internal.jackson.jaxrs.cfg.Annotations;
import org.glassfish.jersey.jackson.internal.jackson.jaxrs.json.JacksonJaxbJsonProvider;
-import java.util.Objects;
+import java.util.List;
import javax.inject.Singleton;
/**
@@ -29,7 +30,11 @@
@Singleton
public class DefaultJacksonJaxbJsonProvider extends JacksonJaxbJsonProvider {
+ //do not register JaxbAnnotationModule because it brakes default annotations processing
+ private static final String EXCLUDE_MODULE_NAME = "JaxbAnnotationModule";
+
public DefaultJacksonJaxbJsonProvider() {
+ super();
findAndRegisterModules();
}
@@ -39,14 +44,16 @@
}
private void findAndRegisterModules() {
- final ObjectMapper defaultMapper = _mapperConfig.getDefaultMapper();
- if (Objects.nonNull(defaultMapper)) {
- defaultMapper.findAndRegisterModules();
- }
+ final ObjectMapper defaultMapper = _mapperConfig.getDefaultMapper();
final ObjectMapper mapper = _mapperConfig.getConfiguredMapper();
- if (Objects.nonNull(mapper)) {
- mapper.findAndRegisterModules();
+
+ final List<Module> modules = ObjectMapper.findModules();
+ modules.removeIf(mod -> mod.getModuleName().contains(EXCLUDE_MODULE_NAME));
+
+ defaultMapper.registerModules(modules);
+ if (mapper != null) {
+ mapper.registerModules(modules);
}
}
-}
+}
\ No newline at end of file
diff --git a/media/json-jackson/src/test/java/org/glassfish/jersey/jackson/internal/model/ServiceTest.java b/media/json-jackson/src/test/java/org/glassfish/jersey/jackson/internal/model/ServiceTest.java
index 027064b..f3a664c 100644
--- a/media/json-jackson/src/test/java/org/glassfish/jersey/jackson/internal/model/ServiceTest.java
+++ b/media/json-jackson/src/test/java/org/glassfish/jersey/jackson/internal/model/ServiceTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2020, 2021 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -23,6 +23,7 @@
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
+import javax.xml.bind.annotation.XmlElement;
@Path("/entity/")
public final class ServiceTest {
@@ -45,6 +46,7 @@
this.value = value;
}
+ @XmlElement(name = "jaxb")
@JsonGetter("name")
public final String getName() {
return name;