Jackson ignores private fields

class POJO {
private int i;

@JsonIgnore
public int getI() {
return i + 1;
}
}
class POJO {
private int i;

@JsonIgnore
public int getI() {
return i + 1;
}
}
this way the field i is completely ignored, can i somehow include it? tried mapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY); but that did not work
9 Replies
JavaBot
JavaBot6mo ago
This post has been reserved for your question.
Hey @Koblížkáč! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
dan1st
dan1st6mo ago
Why do you want to make it visible after explicitly ignoring it? Do you just not want jackson to call the getter?
Koblížkáč
KoblížkáčOP6mo ago
yea the getter returns the value, but modified i want the serialized value to not be modified
dan1st
dan1st6mo ago
I think you can configure it to use field access without @JsonIgnore
dan1st
dan1st6mo ago
Stack Overflow
How to specify jackson to only use fields - preferably globally
Default jackon behaviour seems to use both properties (getters and setters) and fields to serialize and deserialize to json. I would like to use the fields as the canonical source of serialization
dan1st
dan1st6mo ago
set the field visibility to any and the getter visibility to none also with @JsonAutoDetect
Kyo-chan
Kyo-chan6mo ago
Also, smarter approach: use a DTO, without a getter that modifies the value
dan1st
dan1st6mo ago
also that
JavaBot
JavaBot6mo ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
Want results from more Discord servers?
Add your server