You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Shaun Lim <sh...@gmail.com> on 2012/10/11 01:38:41 UTC

Struts2-rest-plugin with PUT/POST not mapping received values to model

Hi guys,

I'm using Struts2 with the Struts 2 REST plugin version 2.2.3. I'm having
trouble sending values to my REST controller and getting it to map to the
model.

*Controller:*

import com.opensymphony.xwork2.ModelDriven;
import org.apache.struts2.rest.DefaultHttpHeaders;
import org.apache.struts2.rest.HttpHeaders;

public class TestController extends ControllerParent implements
ModelDriven<Object> {
    private String testString = new String();
    private String id;

    public TestController() {
        super(TestController.class);
    }

    @Override
    public Object getModel() {
        return testString;
    }

    public String update() {
        logger.info("ID:" + id);
        logger.info(testString);
        return "update";
    }

    public HttpHeaders create() {
        logger.info("ID:" + id);
        logger.info(testString);
        return new DefaultHttpHeaders("create");
    }

    public String getId() {
        return id;
    }

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

    public String getTestString() {
        return testString;
    }

    public void setTestString(String testString) {
        this.testString = testString;
    }
}

And I'm calling:

http://localhost:8080/coreserviceswrapper/test/10.json

{
"testString":"bar"
}

When I try to output the passed value, I get an empty String. Any help will
be appreciated.

I also have a more detailed question on SO here:
http://stackoverflow.com/questions/12813045/struts2-rest-plugin-sending-json-data-to-put-post

Thanks,
Shaun