0

I have a class serialized by GSON into JSON. One particular field should be deserialized but not serialized, i.e., read from JSON but not written to JSON.

I know how to completely exclude properties by marking them as transient, and I know about the @Expose annotation, and, in essence what I need is @Expose(serialize = false), but currently I don't have the excludeFieldsWithoutExposeAnnotation setting set, and I'd prefer not to because I think it really clutters my classes (I do want to serialize all other fields expect this only one in one single class).

Is there any way I could achieve deserialization but not serialization of one particular field without having to resort to explicitly annotating everything else with @Expose? If I need to resort to a custom serializer of this one class, what is the smoothest way of accomplishing the default behaviour short of this one field that should be ignored when serializing?

JHH
  • 8,567
  • 8
  • 47
  • 91
  • 1
    [This answer](http://stackoverflow.com/a/27986860/180100) is probably what you need (see comments also) –  Feb 17 '16 at 15:31
  • Customized serialization is better and make sense I think .. Only those values will be appended as a json which u needs – Vikrant Kashyap Feb 17 '16 at 15:40
  • @RC. Thanks, great answer. Since that question itself is not exactly the same, but that particular answer applies well to my question, I am hesitant to marking my question as a duplicate. If you want to create an answer containing the use of a custom exclude annotation and a link to that answer, I will mark it as accepted. – JHH Feb 17 '16 at 16:31
  • 1
    I think it's best if this question is marked as a duplicate. (the linked answer is great, no need to add content) –  Feb 17 '16 at 16:34
  • Fair enough. I flagged it as duplicate. Thanks again. – JHH Feb 17 '16 at 16:36

0 Answers0