Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

rajsrivastav1919
Copy link

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.

@googlebot
Copy link

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!) and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
  • If you signed the CLA as a corporation, please let us know the company's name.

@rajsrivastav1919
Copy link
Author

I signed it!

@googlebot
Copy link

CLAs look good, thanks!

@thiagotom
Copy link

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.

@rajsrivastav1919
Copy link
Author

@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.

@mrydeen
Copy link

mrydeen commented Nov 30, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants