-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Ignore property during deserialization but retain in serialization not working #95
Comments
Which version did this work in? And what kind of failure do you get? (exception?) |
Actually, its possible it never worked as I wanted :$ . I just reverted to 2.0.6 with same result. I thought that Is there an annotation-based way to get this behavior? |
Hmmh. I see, yes, that is bit problematic. I can think of alternatives, but none entirely good:
The underlying problem is due to per-class |
I'd like to be able to achieve this with annotations and no extra fields or bogus API additions -- seems like a common desire for computed properties. I understand adjusting existing annotation behaviors/implications is hard to do while maintaining backward compatibility. Should I leave this issue open to be interpreted as a feature request or close it as an invalid bug? |
I think title is clear enough to work as an RFE. And I do see the utility. But I am not 100% sure of how to do it, since semantics of Can you think of additional ways to go about this? As usual, adding a new FWIW ,another work-around (for time being) for your case is of course using "ignoreUnknown=true". ... and thinking of this, yet another way to expose this would be to add
which would basically recognize "gettable" things as ignorable, implicitly. But I may be thinking along convoluted paths here, so better suggestions are completely welcome! |
I don't really like implementing this with a new |
Interesting idea, wrt Another possibility could be to try to add some kind of "read-only" semantics: this could even go in As to kind of work-around approaches: we still have |
I stumbled on the same issue. Any progress with implementing read-only properties in an elegant way ? |
I am open to suggestions of best way (from user perspective) to do it. No concrete plans at this point. |
+1 for @nezda's suggestion. |
Either @JsonNoDeserialize or @JsonReadOnly which might be easier to understand. It would be great as well if that worked when the property is not an instance variable (in my case there just a getter). |
My main concern with One more possibility would be to add a property to existing
since it could also be added for |
+1 for adding a property to the existing @JsonDeserialize and @JsonSerialize annotations. Seems like an intuitive and clear approach. What would be the best "non-hacky" approach to prevent deserialization of spesific fields until this feature is implemented? |
+1 |
2 similar comments
+1 |
+1 |
+1 |
👍 +1 |
+1 Would be nice to handle the |
+1 |
2 similar comments
+1 |
+1 |
Ok: I ended up adding new properties @JsonIgnoreProperties(value={ "computed" }, allowGetters=true)
public class Stuff {
// other accessors first...
// and then pseudo-property with just getter, no matching setters
public int getComputed() { return 42; }
} If alternative constructs are desired (like, say, adding ability to say |
Thank you very much guys this is the thing that really helped me 👍 |
I have tried |
@vkrishna17 This is a closed issue to if have remaining issues it makes sense to file a new issue with specific remaining problem(s). |
Using
com.fasterxml.jackson.core:jackson-{core,annotations,databind} 2.1.0
, I think the code below to ignore a computed property (i.e., no field) during deserialization (propertyzip
), but include it in serialization used to work, but now it doesn't. I also tried removing class level@JsonIgnoreProperties({"zip"})
and adding@JsonIgnore
along with@JsonProperty("zip")
but that didn't work either.The variant with a field still works: https://gist.github.com/2510887 .
The text was updated successfully, but these errors were encountered: