当在模型响应中传递带有转义序列的字符串时,响应对象中会出现额外的转义序列

When a String is passed with escape sequences in a model response,additional escape sequences appear in the response object

购物车型号:

public class GeneralCartModel implements Serializable {
    /** The Constant serialVersionUID. */
    private static final long serialVersionUID = 8186401416931298029L;

    /** active_cart.participantId. */
    private UUID participantId;

    /** active_cart.storeId. */
    private Integer storeId;

    /** isConsolidationNeeded. */
    private Boolean isConsolidationNeeded;

    /** Cart entity. */
    private Cart cartEntity;

    // With Getters and setters and to-String.

}

购物车(一个实体 class 在 cassandra 中持久化):

@Table(keyspace = "keyspace1", name = "cart")

public class ActiveCart implements Serializable {

    /**
     * the serialVersionUID.
     */
    @Transient
    private static final long serialVersionUID = 5893895498496519909L;

    /** active_cart.total_product. */
    @Column(name = "total_product")
    private Integer totalProduct;

    /** active_cart.billing_address. */
    @Column(name = "billing_address")
    private String billingAddress;
    // With getters and setters
}

以下代码的REST调用:

JSONObject billingAddress = new JSONObject();
billingAddress.put("organizationName", "organizationName");
billingAddress.put("attentionTo", "attentionTo");
billingAddress.put("department", "department");

/**set billing address in entity.*/
CartModel cartModel=new CartModel;
cartModel.getcartEntity.setBillingAddress(billingAddress.toString());

/** build response.*/
final Response response = Response.build().entity(generalCartModel);
response.setStatus(Status.OK.getStatusCode());
return response;

响应:

{  
   "participantId":null,
   "storeId":null,
   "isConsolidationNeeded":null,
   "activeCartEntity":{  
      "totalProduct":3,
      "billingAddress":**"{\"country\":\"US\",\"organizationName\":\"UNIV OF CHICAGO (SMW)\",\"street3\":\"\",\"street4\":\"\",\"city\":\"CHICAGO\",\"street\":\"1225 E 60TH ST\",\"street5\":\"\",\"postalcode\":\"60637\",\"attentionTo\":\"CENTRAL PROCURMENT\",\"state\":\"\",\"department\":\"\",\"buildingRoom\":\"\"}"**
   }
}

我想要的回复是:

{  
   "participantId":null,
   "storeId":null,
   "isConsolidationNeeded":null,
   "activeCartEntity":{  
      "totalProduct":3,
      "billingAddress":**"{"country":"US","organizationName":"UNIV OF CHICAGO (SMW)","street3":"","street4":"","city":"CHICAGO","street":"1225 E 60TH ST","street5":"","postalcode":"60637","attentionTo":"CENTRAL PROCURMENT","state":"","department":"","buildingRoom":""}"**
   }
}

我该怎么做?

即使使用 GSON,我也遇到了同样的问题 issue.So,我修改了代码,将值作为地图发送到 JSON object.Thats 中,按预期工作。 (即)我将帐单地址添加为 "Map",而不是 JSON 对象。