2
votes

I have successfully implemented Jersey for simple WebService calls (queryparams and simple objects) but when I try to sync a store or save a record, jersey doesn't understand the rootProperty of the writer. It doesn't know where to start and it cannot Consume the json record ExtJS is sending. Unfortunately rootProperty is mandatory according to ExtJS when you transform the data to JSON so I can't do without it. I can obviously use Consumes(MediaType.TEXT_PLAIN) and transform the object myself but I'm trying to take advantage of Jersey's automatic object marshalling etc.

What is the general practice used to .sync store data or .save records?

EDIT: I don't think the problem is with my object's JSON. My store's proxy is configured as follows:

proxy: {
        type: 'ajax',
        url: 'ext/AnnouncementHelper/myFunction',
        headers: {'Content-Type': 'application/json;charset=utf-8'},
        reader: {
            type: 'json',
            rootProperty: 'data',
            messageProperty: 'processMessage'
        },
        writer: {
            type: 'json',
            rootProperty: 'data',
            encode: true,
            writeAllFields: true
        }

What this does is create a POST request with the following parameter:

data={id: 1, description: 'status 1'}

My model is configured as follows:

public class AnnouncementStatus {

    private int id;
    private String description;

    @JsonCreator
    public AnnouncementStatus() {

    }

    public void setId(int id) {
        this.id = id;
    }

    public int getId() {
        return id;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getDescription() {
        return description;
    }
}

My function declaration is:

@POST
@Path("myFunction")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response myFunction(AnnouncementStatus status)

This gives me the following error in java:

org.codehaus.jackson.JsonParseException: Unexpected character ('d' (code 100)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')

I'm guessing jackson doesn't like that my object is starting with the data= but I cannot avoid this since it is mandatory to have a root property when using stores and records.

1

1 Answers

0
votes

I found a solution to the problem I had although not to the question at hand.

I still have no idea how to read the writer's root property using jersey but I found out I don't need to anymore since if we change our proxy's writer to have encoding: false it is not mandatory to set a rootProperty and it just sends the records as an array. This is understood by Jersey's serializer and it can decode the data into objects correctly.