使用jackson将json反序列化为java - 特殊字符问题 [英] Deserialize json to java using jackson - issues with special characters

查看:1534
本文介绍了使用jackson将json反序列化为java - 特殊字符问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用杰克逊(泽西和码头)作为我的REST网络服务 - 一切进展顺利。但是我要求在json post请求中的一个名称值对中包含一个特殊字符。即
json请求(在帖子正文中) -

  {
id:1,
print-color:red
}

// - inprint-color给出了问题。



现在我对应的java bean中有这个对象 Item.java class,我不能创建一个名为print-color的属性(因为不允许使用 - )。如何在映射中处理它?<​​/ p>

谢谢。

解决方案

您可以在Java POJO中尝试以下内容:

  @JsonProperty(print-color)


I am using jackson (jersey and jetty) for my REST webservices - and all is going well. But I have a requirement to include a special character in one of the name value pairs in json post request. i.e. json request (in post body)-

{
  "id": "1",
   "print-color" : "red"
}

//"-" in "print-color" is giving problems.

Now inside my corresponding java bean for this object Item.java class, I cant make a property with name print-color (because "-" is not allowed). How do I deal with it in mapping?

Thanks.

解决方案

You could try following in Java POJO:

@JsonProperty("print-color")

这篇关于使用jackson将json反序列化为java - 特殊字符问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆