java拦截json提交的数据有非法字符,将Json数据中的非法无引号字符发布为请求

I am trying to get JSON data from user (any format). I want to take that data and validate it and then store it in database.

I have written code for getting the data and storing it, which is working very fine, problem come when I try to send some Illegal data from user which is giving me error as Illegal unquoted character How do I get illegal data from user and handle it with exception clause.

My class for getting data is

@JsonInclude(Include.NON_NULL)

@JsonIgnoreProperties(ignoreUnknown = true)

public class EventData extends BasicDBObject{

/**

* Social information of user

*/

private static final long serialVersionUID = 1L;

private Object data;

public Object getData() {

return data;

}

public void setData(Object data) {

this.data = data;

}

}

I have controller which will get the data and call the appropriate service to handle it. I think we need to add some code here in pojo class which will allow illegal JSON data.

I am getting exception as

21:17:14,606 ERROR ExceptionHandler:38 - Could not read document: Illegal unquoted character ((CTRL-CHAR, code 10)): has to be escaped using backslash to be included in string value

at [Source: java.io.PushbackInputStream@1a67dc76; line: 35, column: 38]

at [Source: java.io.PushbackInputStream@1a67dc76; line: 35, column: 19] (through reference chain: java.util.ArrayList[2]->com.microinvest.documents.UserActionEvent["eventData"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Illegal unquoted character ((CTRL-CHAR, code 10)): has to be escaped using backslash to be included in string value

at [Source: java.io.PushbackInputStream@1a67dc76; line: 35, column: 38]

at [Source: java.io.PushbackInputStream@1a67dc76; line: 35, column: 19] (through reference chain: java.util.ArrayList[2]->com.microinvest.documents.UserActionEvent["eventData"])

org.springframework.http.converter.HttpMessageNotReadableException: Could not read document: Illegal unquoted character ((CTRL-CHAR, code 10)): has to be escaped using backslash to be included in string value

at [Source: java.io.PushbackInputStream@1a67dc76; line: 35, column: 38]

at [Source: java.io.PushbackInputStream@1a67dc76; line: 35, column: 19] (through reference chain: java.util.ArrayList[2]->com.microinvest.documents.UserActionEvent["eventData"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Illegal unquoted character ((CTRL-CHAR, code 10)): has to be escaped using backslash to be included in string value

at [Source: java.io.PushbackInputStream@1a67dc76; line: 35, column: 38]

at [Source: java.io.PushbackInputStream@1a67dc76; line: 35, column: 19] (through reference chain: java.util.ArrayList

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值