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

Issue with ResponseFormatException with polymorphism #249

Closed
nloke opened this issue May 6, 2015 · 0 comments
Closed

Issue with ResponseFormatException with polymorphism #249

nloke opened this issue May 6, 2015 · 0 comments

Comments

@nloke
Copy link
Contributor

nloke commented May 6, 2015

First of all I am using restygwt 2.0.2 which I have recently upgraded from 1.X.
Since the upgrade, I am forced to defined every Dto that has extends with proper JsonSubTypes and JsonTypeNames.

Following is the scenario that is falling for me

Given I have the super class, A as below.

@JsonSubTypes({@Type(A.class), @Type(B.class)})
@JsonTypeName("A")
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "@class")
public class A {
    private String code;

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }
}

and a subclass B as below:

@JsonTypeName("B")
public class B extends A {
    private String desc;

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc= desc;
    }
}

Using Spring MVC (version 3.2.0.RELEASE) I have the following on the server side.

@RequestMapping(method = GET, produces = JSON_TYPE)
public ResponseEntity<List<A>> getA(@RequestParam(CODE) String code) {
    A dto= new A();
    dto.setCode("test code")
    List<A> dtoList= Lists.newArrayList(dto);

    return new ResponseEntity<List<A>>(dtoList, HttpStatus.OK);
}

When the json string is returned from the server it will be

[
    {"code":"test code"}
]

As observed it is missing the "@Class":A which will eventually cause the ResponseFormatException because the generated JsonEncoderDecoder for A will check for sourceName and expects it to be not NULL because A is not a leaf due to B being its subtype.

Is this an actual problem with the way I defined the subtypes? or
Is this a problem with Spring MVC's MappingJackson2HttpMessageConverter not having the "@Class" property in the json response? or
Is this as actual issue with the JsonEncoderDecoderClassCreator where it should also consider the case where there potentially no sourceName is provided?

nloke pushed a commit to nloke/resty-gwt that referenced this issue May 7, 2015
The problem is described at resty-gwt#249
This fix is that by default if sourceName is null, we will use the decoding based on the classtype that we are generating the JsonEncocderDecoderClass for
mkristian added a commit that referenced this issue May 7, 2015
Armageddon- added a commit that referenced this issue Nov 25, 2015
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

No branches or pull requests

2 participants