How can I tell jackson to ignore a property for which I don't have control over the source code?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
When a class comes from a library, generated code, or a shared module you cannot edit, you cannot add Jackson annotations directly to it. The standard Jackson answer is to attach annotations externally with a mix-in, which lets your ObjectMapper behave as though the original class had been annotated.
Use a Mix-in to Ignore a Property
Suppose you receive a third-party type that contains a field you do not want in JSON output.
If you owned the class, you could place @JsonIgnore on getPasswordHash. Since you do not, create an abstract mix-in instead.
Now register that mix-in on the mapper you actually use.
The serialized JSON contains username, but not passwordHash.
Ignore Several Properties at Once
If you need to exclude multiple properties, a class-level ignore annotation is often shorter.
That approach is convenient when the property names are stable and you do not need method-level control.
Serialization and Deserialization Are Different Questions
Be precise about what “ignore” means. Sometimes the requirement is:
- do not serialize the property
- do not deserialize the property
- do not do either
A mix-in with @JsonIgnore often affects both directions. If you need asymmetric behavior, consider @JsonProperty(access = JsonProperty.Access.WRITE_ONLY) or READ_ONLY, again through a mix-in if necessary.
That kind of detail matters when you want to accept a field from input but never expose it in output.
When a Custom Serializer Is the Better Tool
A mix-in is the cleanest answer when the change is annotation-like. If you need to reshape the JSON entirely, a custom serializer is more appropriate.
That is more code, so do not reach for it unless you really need full output control.
Scope the Configuration Carefully
Mix-ins are attached to an ObjectMapper, not to the class globally. That is good because it keeps behavior scoped, but it also means you must register the mix-in on the mapper used by your application path. In larger systems, a mix-in can appear to “not work” simply because a different mapper instance handled serialization.
Common Pitfalls
- Creating the mix-in correctly but registering it on the wrong
ObjectMapperor not registering it at all. - Using
@JsonIgnoreProperties(ignoreUnknown = true)when the real goal is to ignore a known property on the target class. - Reaching for a custom serializer when a simple mix-in would solve the problem with less code.
- Forgetting to think about whether the property should be ignored for serialization, deserialization, or both.
- Depending on property names that may change across library versions without tests to catch the break.
Summary
- Jackson mix-ins let you apply ignore annotations to classes you cannot modify.
- Use method-level
@JsonIgnorefor one property or class-level@JsonIgnorePropertiesfor several. - Register the mix-in on the mapper that actually performs JSON conversion.
- Use property access settings when you need different read and write behavior.
- Use a custom serializer only when you need more than an annotation-style override.

