簡體   English   中英

如何將JSON中的java.util.Properties數據類型傳遞給Controller?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM