2015-09-02 107 views
1

如何使用java.util.Properties作爲bean類中的數據類型?另外,如何在休息服務中發送JSON請求對象?如何將java.util.Properties數據類型以JSON形式傳遞給Controller?

import java.util.Properties; 

public class TestRequest { 
     public static final int UNDEFINED = -1; 
     public static final int RESET = 0; 
     public static final int UPDATE = 1; 
     private int msgType = UNDEFINED; 
     private Properties properties = new Properties(); 

     public TestRequest(int msgType) { 
      this.setMsgType(msgType); 
     } 

     public int getMsgType() { 
      return msgType; 
     } 

     public void setMsgType(int msgType) { 
      this.msgType = msgType; 
     } 

     public void setProperty(String itemKey, Object itemValue) { 
      this.properties.put(itemKey, itemValue); 
     } 

     public Object getProperty(String itemKey) { 
      return this.properties.get(itemKey); 
     } 
    } 

對於上面的豆,我送以下JSON數據:

{"msgType":7, 
     "properties":{"targetItem":{"userName":"[email protected]"}} 
} 

但它不分配值對這個bean。 如何在JSON中使用Properties數據類型?

+0

你用什麼來將'TestRequest'類轉換爲'JSON'?該映射如何執行? –

+0

嘗試將類型從「屬性」更改爲「Map Bohemian

回答

0

Properties本質上是一個破碎的類;

將類型從Properties更改爲Map<String, Object>;所有的JSON序列化庫都可以(de)序列化成地圖。

相關問題