2015-10-29 45 views
0

我將"this\'s my case!"設置爲對象的字段。如何避免傑克遜逃避反斜槓?

調用writeAsString,輸出是"this\\\'s my case!"。我想期待"this\'s my case!"

我怎樣才能得到我想要的?

public class CommonUtils { 
    public static ObjectMapper objectMapper = new ObjectMapper(); 
    public static ObjectMapper getObjectMapperInstance(){ 
     return objectMapper; 
    } 

    public static void main(String[] args) throws IOException { 
     CommonUtils commonUtils = new CommonUtils(); 
     commonUtils.test(); 
    } 
    public void test() throws IOException { 
     List<MyObject> list = new ArrayList<MyObject>(); 
     String xx = "page://list?params={\"city\"}"; 
     list.add(new MyObject(1,xx)); 
    } 
    class MyObject{ 

     public MyObject(int tag,String str){ 
      this.tag = tag; 
      this.str = str; 
     } 
     int tag; 
     String str; 

     public int getTag() { 
      return tag; 
     } 

     public void setTag(int tag) { 
      this.tag = tag; 
     } 

     public String getStr() { 
      return str; 
     } 

     public void setStr(String str) { 
      this.str = str; 
     } 
    } 
} 

輸出的上面的代碼:

[{ 「標籤」:1, 「STR」: 「頁://列表PARAMS = {\\?」 城市\\「}]

我要的是: [{ 「標籤」:1, 「STR」: 「頁面://列表PARAMS = {\」 城\「}]

+0

你得到的輸出有什麼問題。我沒有得到 –

回答

0

如果您更改字符串XX到

你會得到想要的結果;

[ { "tag" : 1, "str" : "page://list?params={\"city\"}] 
+0

謝謝。但我不接受那種方式。傑克遜是否有配置來處理這種情況? – Tiysee

+0

然後你想要什麼輸出? – Shivam

+0

謝謝。我編輯了我的問題。 – Tiysee