JSON / UTF-8和unicode 2022的Jackson序列化问题

时间:2016-12-19 18:49:15

标签: java json encoding utf-8 jackson

我们的Web客户端允许用户输入文本,通常来自MS Word并包含项目符号。项目符号点是2022 unicode字符,但在从服务返回给客户端时没有正确序列化。

根据文档,utf-8是jackson序列化的默认值。我们发现它处理unicode项目符号的问题。以下示例演示了这一点:

   @POST
   @Path("/utfBullet1")
   @Produces(MediaType.APPLICATION_JSON)
   public String getUTFBullet() throws UnsupportedEncodingException;

   @POST
   @Path("/utfBullet1")
   @Produces(MediaType.TEXT_PLAIN)
   public String getUTFBullet2() throws UnsupportedEncodingException;

   @Override
   public String getUTFBullet() throws UnsupportedEncodingException {
          // TODO Auto-generated method stub
          String s = Character.toString((char)0X2022);
          return s;
   }

   @Override
   public String getUTFBullet2() throws UnsupportedEncodingException {
          // TODO Auto-generated method stub
          return this.getUTFBullet();
   }

使用@Produces指定charset(" application / json; charset = utf-8")不起作用,我们得到unicode替换字符?,charset = CP-1252确实有效但是我们想要保留utf-8。

建议?

0 个答案:

没有答案