在Spring MVC应用程序中读取JSON输入 - 电子邮件问题

时间:2013-10-07 15:40:33

标签: json spring spring-mvc

我试图在我的请求中传递emaild ..

在我的控制器类中读取它时,我遇到异常......

[ Catch Exception :  Error Message: Unexpected end-of-input: was expecting closing quote for a string value
 at [Source: java.io.StringReader@200a200a; line: 1, column: 195] ]


http://localhost:8080/appln/fetch/
ipdata={"date":"2013-10-05","emailId":"my.email.com@gmail.com"}

如果我将emailId设为“myemailcom @ gmailcom”.. ..效果很好......

我的控制器代码看起来很...... ..

ObjectMapper mapper = new ObjectMapper();
mapper.readValue(ipdataString,InputRequestBean.class);

-

得到的是什么...... {“date”:“2013-10-05”,“emailId”:“我的

我的bean是

public class InputRequestBean {
    private String date;
    private String emailId;
    /**
     * @return the date
     */
    public String getDate() {
        return date;
    }
    /**
     * @param date the date to set
     */
    public void setDate(String date) {
        this.date = date;
    }
    /**
     * @return the emailId
     */
    public String getEmailId() {
        return emailId;
    }
    /**
     * @param emailId the emailId to set
     */
    public void setEmailId(String emailId) {
        this.emailId = emailId;
    }

}

1 个答案:

答案 0 :(得分:0)

做了一些谷歌搜索..这是有效的修复..

@RequestMapping(value =“/ appln / fetch / {ipdata:。+}”,method = RequestMethod.GET)

Spring Doc ...: http://docs.spring.io/spring/docs/3.2.x/spring-framework-reference/html/mvc.html#mvc-ann-requestmapping-uri-templates-regex