如何在数据库中存储html字符串而不用Java中的符号转换

时间:2013-12-20 09:33:08

标签: java json web-services

我在UI端使用ck编辑器以html格式(作为字符串)向后端发送一些文本。在这个过程中,我使用的JSON将携带所有必需的键值来进行服务。 从UI开始,帖子将包含以下数据:

{
  "payload": {
    "title": "Some title",
    "categoryId": 64,
    "richContent": "<p>\n\this is the content that need to be stored in the database</p>\n",
    "goLiveOn": 1388219580000,
    "id": 150
  }
}

当它到达服务方法时,我正在检索JSON对象,如下所示:

@POST
    @RestService(input = Article.class, output = Boolean.class)
    @ServiceStatus(value = "complete")
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    @Path("/save")
    public String save(@Context HttpHeaders headers, @Context UriInfo uriInfo,
                       WebserviceRequest request) throws Exception {
        Article article = (Article) JsonUtil.getObject(request.getPayload(),
                Article.class);
        Boolean saveStatus = ArticleHandler.getInstance().save(article);
        return JsonUtil.getJsonBasedOnDescriptor(saveStatus,
                Boolean.class);
    }

但是当此对象到达处理程序中的save mthod时,richContent将更改为

  

&amp; lt; p&amp; gt;这是需要存储在内容中的内容   数据库&安培; LT; / P&安培; GT;

getObject方法的代码如下:

public static Object getObject(Object source, Class targetType) {
        try {
            return objMapper.convertValue(source, targetType);
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }
    }

但我需要的格式与之前的格式相同,以便在将其保存到db之前可以对其执行更多操作。任何帮助将不胜感激。提前谢谢。

0 个答案:

没有答案