@DoNotExpose Annotation
See original GitHub issueI was wondering why not include an annotation that allows the exclusion of only a single field or just few fields while serialization.
Example:
Class Test{ String s1; String s2; String s3; String s4; }
If I want to avoid serializing s1 and want to expose the other fields then it currently would look like :
Class Test{ String s1; @Expose String s2; @Expose String s3; @Expose String s4; }
But, I think it would be way more easier to have it the following :
Class Test{ **@DoNotExpose** String s1; String s2; String s3; String s4; }
Can someone please tell if there is a reason for not having this annotation or if there is a cleaner workaround for this available already, as we have a case where we want to avoid serializing a single heavy reference in classes and still expose the other fields.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:4
- Comments:6 (3 by maintainers)
Top GitHub Comments
Use the
transient
modifier?@lyubomyr-shaydariv True 😉. For an API project which I’m working on, though I have few fields (around 15-20), I have many classes (around 35-40). For now, I use two duplicate classes; one for domain objects and one for API objects. I use API objects only for external interface and domain objects for everything else used internally. Specific to this issue, I’m using User Defined Exclusion Strategy to annotate few fields to
@GsonExclude
instead of many fields to@Expose
.