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

updated JsonDeserializer example #2192

Merged
merged 6 commits into from
Sep 12, 2022
Merged

Conversation

deeptimarrivada1
Copy link
Contributor

resolves #1425

@google-cla
Copy link

google-cla bot commented Sep 6, 2022

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

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@deeptimarrivada1
Copy link
Contributor Author

deeptimarrivada1 commented Sep 6, 2022

Sample test method:

@Test
    public void test() {
        String inputString
                = "{\"clazz\":com.foo.MyObject,\"value\":20}";
        IdDeserializer deserializer = new IdDeserializer();
        Gson gson = new GsonBuilder()
                .registerTypeAdapter(Id.class, deserializer)
                .create();
        Id outList = gson.fromJson(inputString, new TypeToken<Id>(){}.getType());
        System.out.println(outList.getValue());
    }

Copy link
Collaborator

@Marcono1234 Marcono1234 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you able to sign the CLA? I think it will be necessary for this PR to be merged.

gson/src/main/java/com/google/gson/JsonDeserializer.java Outdated Show resolved Hide resolved
@deeptimarrivada1
Copy link
Contributor Author

Are you able to sign the CLA? I think it will be necessary for this PR to be merged.

yes

@deeptimarrivada1
Copy link
Contributor Author

deeptimarrivada1 commented Sep 9, 2022

Sample test:

@Test
   public void test() {
       Id id = new Id(Foo.class, 20);
       Gson gson = new GsonBuilder().registerTypeAdapter(Id.class, new IdSerializer()).create();
       Gson gson2 = new GsonBuilder()
               .registerTypeAdapter(Id.class, new IdDeserializer())
               .create();
       Id outList = gson2.fromJson(gson.toJson(id), new TypeToken<Id>(){}.getType());
       System.out.println(outList.getValue());
   }

Copy link
Collaborator

@Marcono1234 Marcono1234 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for your work on this!

@eamonnmcmanus, could you please have a look?

@eamonnmcmanus
Copy link
Member

Thanks for doing this!

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.

JsonDeserializer API doc example may be incomplete-cannot resolve symbol 'id'
3 participants