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

Cannot marshal Ticket to JSON #573

Closed
afm497 opened this issue Mar 25, 2023 · 6 comments · Fixed by #595
Closed

Cannot marshal Ticket to JSON #573

afm497 opened this issue Mar 25, 2023 · 6 comments · Fixed by #595
Labels

Comments

@afm497
Copy link

afm497 commented Mar 25, 2023

Describe the bug
Cannot, at least using both GSON and Jackson, marshal a Ticket to JSON. Multiple fields named priority. One in the Ticket itself, another in it's superclass, Request. The priority in Ticket is private, in Request it's protected.

To Reproduce
Steps to reproduce the behavior:

  1. Using the API, grab a Ticket object.
  2. Try to marshal to JSON using either GSON or Jackson. Though it probably would apply to others, only have used those.
  3. See IllegalArgumentException referencing multiple fields named "priority".

Expected behavior
Ability to marshal Ticket object to JSON for proper transmission.

Additional context
Not sure anymore is needed, but happy provide anything additional.

@PierreBtz
Copy link
Collaborator

@afm497 while the shadowed field is indeed less than ideal, I'm unsure why it wouldn't work. Following code is working at producing a json:

    public static void main(String[] args) throws IOException {
        var ticket = new Ticket();
        ticket.setPriority(Priority.HIGH);
        var mapper = new ObjectMapper();
        mapper.writeValue(System.out, ticket);
    }

Please provide a fully self contained reproducer.

@afm497
Copy link
Author

afm497 commented Apr 4, 2023

I guess we differ on what "less than ideal" covers :) Just for the record, I use your library and find it very worthwhile, valuable and sincerely thank you for your efforts in creating and sharing.

Quick snippet:

    public static void main(String[] args) {
        new Gson().toJson(new Ticket());
    }

will result in
java.lang.IllegalArgumentException: class org.zendesk.client.v2.model.Ticket declares multiple JSON fields named priority

So while yes, one could use a custom exclusion strategy, detect this kind of thing and work around it, it seems like either the field should be fixed to only declare once if they represent the same thing or transition to distinct fields.

I'll add, now that I see the package name there, I believe this is part of your library , but if not and it's coming from elsewhere, let me know.

@PierreBtz
Copy link
Collaborator

I agree with you, I'm afraid I just don't have time to invest on the library currently. Code change itself looks trivial, but testing nothing is broken is not. I'm happy to accept a PR though :)

@afm497
Copy link
Author

afm497 commented Apr 24, 2023

Totally understand. I'll submit a PR for you here. Didn't want to do it out of the blue so glad we could connect here. Thanks very much for being open here.

@github-actions
Copy link

This issue/PR is stale because it has been opened 60 days with no activity. Remove stale label or comment or this will be closed in 7 days

@afm497
Copy link
Author

afm497 commented Jun 25, 2023

Had totally forgotten to create PR but got a notification that the issue was going stale so finally made the PR. Not sure if there is anything else I would need to do to ensure it no longer is treated as stale, but hopefully the activity addresses it.

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

Successfully merging a pull request may close this issue.

2 participants