-
Notifications
You must be signed in to change notification settings - Fork 355
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
feat: allow json-jackson to auto-discover modules #4447
feat: allow json-jackson to auto-discover modules #4447
Conversation
I am not sure about this. The thing is that the Ideally, the change would be made to Jackson itself. On the other hand, this is not the first PR we register that asks for changing the Jackson classes (Note that for any change like this in the 3rd party content we probably need to ask Eclipse Legal to approve). We ought to think about some kind of wrapper, if possible. |
It looks like it is possible to pass the
Create
And create the constructor, such as (also in
Would that work? |
Unfortunately, with: @Singleton
public final class DirectJacksonJaxbJsonProvider extends JacksonJsonProvider {
public DirectJacksonJaxbJsonProvider() {
super(new DefaultJacksonObjectMapper(), BASIC_ANNOTATIONS);
}
public DirectJacksonJaxbJsonProvider(final Annotations... annotationsToUse) {
super(new DefaultJacksonObjectMapper(), annotationsToUse);
}
} final class DefaultJacksonObjectMapper extends ObjectMapper {
DefaultJacksonObjectMapper() {
findAndRegisterModules();
}
} We are setting public class ObjectMapperContextResolver implements ContextResolver<ObjectMapper> {
@Context
private HttpHeaders headers;
private final ObjectMapper mapper;
public ObjectMapperContextResolver() {
mapper = new ObjectMapper();
mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
}
@Override
public ObjectMapper getContext(Class<?> type) {
return mapper;
}
} I tried a simple: @Singleton
public class DefaultJacksonJaxbJsonProvider extends JacksonJaxbJsonProvider {
public DefaultJacksonJaxbJsonProvider() {
findAndRegisterModules();
}
public DefaultJacksonJaxbJsonProvider(final Annotations... annotationsToUse) {
super(annotationsToUse);
findAndRegisterModules();
}
private void findAndRegisterModules() {
final ObjectMapper defaultMapper = _mapperConfig.getDefaultMapper();
if (Objects.nonNull(defaultMapper)) {
defaultMapper.findAndRegisterModules();
}
final ObjectMapper mapper = _mapperConfig.getConfiguredMapper();
if (Objects.nonNull(mapper)) {
mapper.findAndRegisterModules();
}
}
} But it seams to break the JDK8 (-Ptravis_e2e_skip) and JDK15 (-Ptravis_e2e) tests :/ I will investigate it. |
The Travis is good at exposing imperfections in tests, so the tests fail intermittently. I can see all the tests passed now with this PR. |
It looks good. Please update the copyright years to 2020 and add a copyright header to the new file. I would not mind a test for the provided functionality, too. |
Signed-off-by: Théo Gaillard <[email protected]>
Filed CQ 22138 for jackson-modules-java8. |
The CQ has been approved |
Currently, we cannot register module to
jersey-media-json-jackson
.This MR will allow json-jackson to auto-discover the modules in use.
We may for example add to
pom.xml
:Will fix: #4311