简体   繁体   English

对Java对象使用JsonSanitizer

[英]Using JsonSanitizer for Java Objects

We need to sanitize a Json which is received as Java Object as shown in the below example 我们需要清理一个作为Java对象接收的Json,如下例所示

@Path("/agent”)
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response addAgent(Agent agent) throws Exception {}

We used JsonSanitizer for the purpose. 我们为此目的使用了JsonSanitizer。 However, JsonSanitizer accepts only String, so I had to convert my agent object to Json String, sanitize it and then convert back to agent object. 但是,JsonSanitizer仅接受String,因此我不得不将我的代理对象转换为Json String,对其进行清理,然后再转换回代理对象。

Is there an equivalent API which can sanitize Java Object directly without requiring the intermediate String conversion or any better approach than the one we took 是否存在等效的API,可以直接清理Java Object,而无需中间的String转换或任何比我们采用的方法更好的方法

JsonSanitizer is not the tool you need. JsonSanitizer不是您需要的工具。

It ensures that the output is embeddable and evalable but does not trim whitespace or check balancedness of quotes within a string literal. 它确保输出是可嵌入和可评估的,但不会修剪空格或检查字符串文字内引号的平衡性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM