-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Adding support for using getter/setter methods based on user choice #232 #1094
base: main
Are you sure you want to change the base?
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed, please reply here (e.g.
|
I signed it! |
CLAs look good, thanks! |
Hello @rajsrivastav1919 any chance this will be incorporated into a new gson release? It would be great to have this feature. I'm already using 2.8.5 and it doesn't look like there is a way to force it to go through getters and setters. |
@thiagotom The community was not in favour of adding this support officially in Gson library as per the last discussion. You can comment on the actual issue's thread to discuss this further with them. |
Thank you Raj for making these changes. We were originally looking at Gson for use in our company, but since Gson works at the member level, we could not easily overwrite enumerations/non Gson capable classes. Yes we could have written our own deserializers, but that would have been painful for all our objects. We have existing objects that were used when we were converting from XML and we wanted to use the same objects, just different source. The objects are a combination of primative types and classes. And to make it worse, the XML to JSON is not a one to one mapping. But by being able to use the setters and getters, we can create extending classes which can set the correct values in the parents. |
This PR contains changes to use getter/setter methods instead of field level reflection methods for serialization/deserialization of objects, if the user has specified this preference while instantiating Gson.