question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Disable Jackson mapper for a particular annotation

See original GitHub issue

With Jackson, it’s easy to disable all annotations for a given ObjectMapper. Is there a way to only disable one given annotation?

// disable all
ObjectMapper mapper = new ObjectMapper()
mapper.disable(MapperFeature.USE_ANNOTATIONS);

// disable one?
ObjectMapper mapper = new ObjectMapper()
mapper.disable(@JsonIgnore);

Using @JacksonAnnotationsInside, I’ve defined a custom Jackson annotation and I only want it to be used in certain circumstances.

Issue Analytics

  • State:closed
  • Created 11 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
yamsellemcommented, Dec 29, 2012

I was looking for a way to disable a particular annotation, if it works with JacksonAnnotationIntrospector, so be it. Can you provide a sample code? Like:

ObjectMapper mapper = new ObjectMapper();
JacksonAnnotationIntrospector introspector = new JacksonAnnotationIntrospector();
introspector.disable(@JsonIgnore);
mapper.setAnnotationIntrospector(introspector);

The isHandled method seemed to be what I expected, but it is deprecated and do not say how to replace it. Thanks a lot.

0reactions
mjballcommented, Jul 27, 2015

If you’re not using Jackson 2.6 yet, this annotation introspector seems to work well for disabling a specific annotation (@JsonUnwrapped in this case; other annotations not tested):

public class IgnoreJsonUnwrappedAnnotationInspector extends JacksonAnnotationIntrospector {
  @Override
  public NameTransformer findUnwrappingNameTransformer(AnnotatedMember member) {
    return null;
  }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Disable Jackson mapper for a particular annotation
With Jackson, it's easy to disable all annotations for a given ObjectMapper . Is there a way to only disable one given annotation?...
Read more >
Jackson Annotations - Disable - Tutorialspoint
We can disable jackson annotations using disable() function of ObjectMapper. Example - Disabling Annotation. import java.io.
Read more >
How to disable all Jackson annotations in Java - Educative.io
The method takes in the different features to disable as parameters. We use the USE_ANNOTATIONS of the MapperFeature enum to disable all the...
Read more >
Disable Annotation in Jackson - Javatpoint
Usually we need to disable the Jackson annotation after completing its work. So, we use the disable() method of ObjectMapper class for disabling...
Read more >
Jackson Ignore Properties on Marshalling - Baeldung
Control your JSON Output - Ignore certain fields directly, ... A quick and practical guide to the @JsonFormat annotation in Jackson.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found