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

Generic model parsing error #195

Open
nicolashaan opened this issue Jan 18, 2017 · 0 comments
Open

Generic model parsing error #195

nicolashaan opened this issue Jan 18, 2017 · 0 comments

Comments

@nicolashaan
Copy link

nicolashaan commented Jan 18, 2017

Hi,
First of all, thank you for this wonderful library!
Unfortunately, we are facing an issue with a Generic model. I've modified one of the library test to match the use case:

@JsonObject
public class SimpleGenericModel<T> {

    @JsonField
    public String string;

    @JsonField
    public Date date;

    @JsonField(name = "test_int")
    public int testInt;

    @JsonField(name = "test_long")
    public long testLong;

    @JsonField(name = "test_float")
    public float testFloat;

    @JsonField(name = "test_double")
    public double testDouble;

    @JsonField(name = "test_string")
    public String testString;

    @JsonField(name = "test_int_obj")
    public Integer testIntObj;

    @JsonField(name = "test_long_obj")
    public Long testLongObj;

    @JsonField(name = "test_float_obj")
    public Float testFloatObj;

    @JsonField(name = "test_double_obj")
    public Double testDoubleObj;

    @JsonField(name = "test_t")
    public T testT;

    @JsonField(name = "test_nested_generic")
    public SimpleGenericModel<String> testNestedGeneric;

}
@JsonObject
public class AnotherClass {
        @JsonField
        public int value;

        @JsonField
        public String name;
}

The json looks like this:

String json = "{\"date\":\"2015-02-21T18:45:50.748+0000\",\"string\":\"testString\",\"test_double\":342.0,\"test_double_obj\":345.0,\"test_float\":898.0,\"test_float_obj\":382.0,\"test_int\":32,\"test_int_obj\":323,\"test_long\":932,\"test_long_obj\":3920,\"test_string\":\"anotherTestString\",\"test_t\":{\"name\":\"generic string!\", \"value\":\"123\"}}";

Finally, I'm parsing this data using:

ParameterizedType<SimpleGenericModel<AnotherClass>> parameterizedType
           = new ParameterizedType<SimpleGenericModel<AnotherClass>>() {
};
SimpleGenericModel<AnotherClass> simpleModel
                    = LoganSquare.parse(json, parameterizedType);

This code give me a:

Class com.bluelinelabs.logansquare.processor.model.SimpleGenericModel could not be mapped to a JSON object. Perhaps it hasn't been annotated with @JsonObject?

Is it a supported use case?

Please find below a link to the patch I used to highlight my issue:

nicolashaan@e2277e0

Best regards,
Nicolas

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

1 participant