GeezerVison is showing github.com — [BUG] Transient properties in classes with @Jacksonized @Accessors(fluent=true) get serialized · Issue #3936 · projectlombok/lombok
[BUG] Transient properties in classes with @Jacksonized @Accessors(fluent=true) get serialized #3936DescriptionDescribe the bug
When creating a class with @Accessors(fluent = true) and @Jacksonized that contains transient fields, they inadvertently get serialized since v1.18.40.
To Reproduce
Class:
@Value
@Builder
@Jacksonized
@Accessors(fluent = true)
public class Foo {
String foo;
transient String transientFoo;
}
results in:
@JsonDeserialize(
builder = FooBuilder.class
)
public final class Foo {
@JsonProperty("foo")
private final String foo;
@JsonProperty("transientFoo")
private final transient String transientFoo;
...
}
Expected behavior
Transient fields should not get @JsonProperty.
Version info (please complete the following information):
Since v1.18.40 on all platforms
Additional context
Probably caused by: #3860 Activityjanrieke commented on Sep 10, 2025 Yeah, @JsonProperty takes precedence over transient. I have not thought about that.
Workaround for the time being is probably putting @JsonIgnore on the field. According to this issue, newer Jackson version should ignore it in this case (but I did not test it).
If that does not work, you could implement the getter manually. renedewaele commented on Sep 10, 2025 Hi @janrieke, indeed. I was already using that workaround ;). liampace commented on Sep 18, 2025 Just to make sure I am understanding this right, the expected output of this:
@Value
@Builder
@Jacksonized
@Accessors(fluent = true)
public class Foo {
String foo;
transient String transientFoo;
}
would be the following?
public final class Foo {
@JsonProperty("foo")
private final String foo;
@JsonIgnore
private final transient String transientFoo;
...
}liampace commented on Sep 18, 2025
When creating a class with @Accessors(fluent = true) and @Jacksonized that contains transient fields, they inadvertently get serialized since v1.18.40.
Is this bug specific to when both @Accessors and @Jacksonized is used?
Or is it a general issue where @Jacksonized disregards transient values? janrieke commented on Sep 18, 2025 A @Jacksonized @Builder also does not ignore transient fields, but that doesn't hurt in most cases, because the field won't be in the payload to be deserialized.
What's new in 1.18.40 is that @Jacksonized @Accessors puts @JsonProperty on all fluent accessors, so suddenly also transient fields are included in the serialization in this case. Lombok should simply not put that annotation on a transient field's accessors (adding a @JsonIgnore is not necessary). renedewaele commented on Sep 18, 2025 Thanks @liampace and @janrieke for looking into this.
@janrieke is right. I only just realized that I’ve been serializing some transient fields all these years :). For some reason I assumed that transient fields in data objects wouldn’t be serialized. But since getters are generated for those fields too, that assumption never really made sense.
As @janrieke also pointed out, it hasn’t caused too many problems for me before because the transient properties were ignored during deserialization.
This has definitely been a wake-up call for me as well. Even after this is fixed, I’ll still keep @JsonIgnore for this reason.
Keep up the good work! liampace commented on Sep 18, 2025 I'm working on implementing a PR for this issue, which will automatically add @JsonIgnore to transient values.
However, would it, a) be a good idea, and b) make sense, to add an override feature like ToString.Include or ToString.Exclude for @Jacksonized as well?
For example:
@Value
@Builder
@Jacksonized
@Accessors(fluent = true)
public class Foo {
@Jacksonized.Exclude String foo;
@Jacksonized.Include transient String transientFoo;
}
would generate the following:
public final class Foo {
@JsonIgnore
private final String foo;
@JsonProperty("transientFoo")
private final transient String transientFoo;
...
}liampace commented on Sep 18, 2025
...(adding a @JsonIgnore is not necessary).
It seems that this is not the case, due to the fact that Jackson relies on getters/setters to determine serializable fields. I think Lombok should automatically add @JsonIgnore to transient fields liampace commented on Sep 18, 2025
However, would it, a) be a good idea, and b) make sense, to add an override feature like ToString.Include or ToString.Exclude for @Jacksonized as well?
Having thought about this for a little bit more, I don't think such a feature would make sense as the whole point of transient is to declare that a field shouldn't be serialized/de-serialized.
On another note, are there any popular annotations that mimic the transient keyword that @Jacksonized should support? I want to make sure that as many bases are covered before submitting the PR. janrieke commented on Sep 18, 2025 @JsonIgnore is not necessary because Jackson does not recognize fluent accessors in the first place.
liampace commented on Sep 18, 2025 Ok, thank you for the clarification.
However, I think it is better to be explicit about this because the implicit behavior of Jackson can always change.
Anyways, I've created a pull request for this bug renedewaele commented on Sep 19, 2025
@JsonIgnore is not necessary because Jackson does not recognize fluent accessors in the first place.
I was thinking of other classes with transient fields that do not have fluent accessors.
@liampace There are some @Transient annotations in the wild too, but I don't think it's always correct to place @JsonIgnore on the getter in those cases. janrieke commented on Sep 29, 2025
However, I think it is better to be explicit about this because the implicit behavior of Jackson can always change.
Yeah, let's play it safe here. We never know what happens in future Jackson versions, especially with Jackson 3 coming up. rzwitserloot commented on Jan 29, 2026 Agree with it all:
Liam Pace wrote:
However, would it, a) be a good idea, and b) make sense, to add an override feature like ToString.Include or ToString.Exclude for @Jacksonized as well?
Agree with your later assessment: Once you slap transient on a field, you made your bed. Not a good idea.
Jan Rieke wrote:
Yeah, let's play it safe here. We never know what happens in future Jackson versions, especially with Jackson 3 coming up.
Hopefully no lint tools are around that generate a warning due to a superfluous @JsonIgnore annotation. But I bet there aren't any - agreed. Conveniently that means Liam's PR should match desired behaviour to a 'T' :) rzwitserloot commented on Jan 29, 2026 PR accepted (in a way that github doesn't appear to understand). Thanks @liampace and @janrieke !
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|