[英]How can the java.util.Properties datatype be passed in JSON to the Controller?
如何在bean類中使用java.util.Properties
作為數據類型? 另外,如何在rest服務中發送JSON
請求對象?
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);
}
}
對於上面的bean,我正在發送以下JSON
數據:
{"msgType":7,
"properties":{"targetItem":{"userName":"vigneshr2311@gmail.com"}}
}
但這不是將值分配給該bean。 如何在JSON
使用Properties
數據類型?
Properties
本質上是一個壞類。
將類型從Properties
更改為Map<String, Object>
; 所有JSON序列化庫都可以與地圖進行反序列化。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.