2016-06-17 14 views
0

CartModel geben wird:Wenn ein String mit Escape-Sequenzen in einer Modellantwort, zusätzliche Escape-Sequenzen werden in dem Antwortobjekt

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. 

} 

Wagen (Ein Entity-Klasse in cassandra bestehen bleiben):

@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 AUFFORDERUNG ZUR folgenden Code:

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; 

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\":\"\"}"** 
    } 
} 

ICH WILL die Antwort als:

{ 
    "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":""}"** 
    } 
} 

Wie kann ich es tun?

+0

Sie sollten versuchen [GSON] (http://tutorials.jenkov.com/java-json/gson.html) –

Antwort

0

Auch mit GSON habe ich das gleiche Problem konfrontiert.So habe ich den Code geändert, um es die Werte als eine Karte innerhalb des JSON-Objekts zu senden.That funktioniert wie erwartet. (d. H.) Anstelle von JSONObject habe ich die Rechnungsadresse als "Karte" hinzugefügt.