Robospice and Jackson annotations seems to be ignored

126 views Asked by At

I have problem with Jackson + Retrofit + Robospice.
I am trying to create simple project, and get data from my api.
But when obect is mapped by Jackson I get an exception.

>    Caused by:
> com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException:
> Unrecognized field "id" (class
> com.crosp.solutions.malibushop.rest.model.SlideshowImage), not marked
> as ignorable (6 known properties: "desiredHeight", "redirectUrl",
> "imageUrl", "title", "desiredWidth", "slideId"])

My JSON format is following.

[{"id":"121","source":"some url","title":"Hello"},{"id":"120","source":"some url","title":"Girls"},{"id":"119","source":"some url","title":"Girl2"}]

My POJO

/**
 * Created by crosp on 6/8/15.
 */
@JsonIgnoreProperties(ignoreUnknown=true)
public class SlideshowImage {
    private String mImageUrl;
    private String mRedirectUrl;
    private String mTitle;
    private int mSlideId;
    private int mDesiredHeight;
    private int mDesiredWidth;

    public int getDesiredWidth() {
        return mDesiredWidth;
    }

    public void setDesiredWidth(int desiredWidth) {
        mDesiredWidth = desiredWidth;
    }

    public int getDesiredHeight() {
        return mDesiredHeight;
    }

    public void setDesiredHeight(int desiredHeight) {
        mDesiredHeight = desiredHeight;
    }

    public int getSlideId() {
        return mSlideId;
    }
    @JsonProperty("id")
    public void setSlideId(int slideId) {
        mSlideId = slideId;
    }

    public String getTitle() {
        return mTitle;
    }
    @JsonProperty("title")
    public void setTitle(String title) {
        mTitle = title;
    }

    public String getRedirectUrl() {
        return mRedirectUrl;
    }

    public void setRedirectUrl(String redirectUrl) {
        mRedirectUrl = redirectUrl;
    }

    public String getImageUrl() {
        return mImageUrl;
    }
    @JsonProperty("source")
    public void setImageUrl(String imageUrl) {
        mImageUrl = imageUrl;
    }
    @SuppressWarnings("serial")
    public static class List extends ArrayList<SlideshowImage> {

    }

}

As you can see annotation to ignore unknown properties is present but not used by object mapper. Also there are annotations to map my POJO object field to different name in json, but this still doesn't affect.
Seems that Jackson annotation are ignored.

If name fields exactly as in response - everything works.

Service

public class RestRetrofitSpiceService extends RetrofitJackson2SpiceService {
    private static final String API_SERVER_BASE_URL = "url api";
    @Override
    protected String getServerUrl() {
        return API_SERVER_BASE_URL;
    }

}

Where is my fault ?

1

There are 1 answers

0
CROSP On

The problem has been solved.

There were dependency conflicts, because all libraries with group id

org.codehaus.jackson

Have moved to the new url.

com.fasterxml.jackson

So just remove all dependencies org.codehaus.jackson from your build file and use com.fasterxml.jackson instead