后端新增功能,post请求json参数中包含单引号或者=,请求封装实体会失败

与子缱绻 发布于 06/30 17:09
阅读 146
收藏 1

精选30+云产品,助力企业轻松上云!>>>

@若依开源 你好,想跟你请教个问题:

参数如:

{
    "aaa":"aaa",
    "bbb":"bbb",
    "ccc":[
        {
            "ddd":"ddd=1",
            "eee":"eee='1'"
        },
        {
           "ddd":"ddd2",
           "eee":"eee2" 
        }
    ]
}
实体类属性如下:
    private String aaa;

    private String bbb;

    private List<Ccc> ccc;

public class Ccc{
    private String ddd;

    private String eee;


两个实体类都有对应的setter/getter方法,并且都有无参构造函数;

控制层在使用的使用使用@RequestBody注解实体类做为参数,在请求过程中会报如下异常:

Caused by: com.fasterxml.jackson.core.JsonParseException: Unexpected character ('=' (code 61)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')
 at [Source: (PushbackInputStream); line: 1, column: 2]

或者

org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Unexpected character (''' (code 39)): expected a valid value (number, String, array, object, 'true', 'false' or 'null'); nested exception is com.fasterxml.jackson.core.JsonParseException: Unexpected character (''' (code 39)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')
 at [Source: (PushbackInputStream); line: 1, column: 2]

返回顶部
顶部