FastJSON JSONObject 字段排序 Feature.OrderedField

package cn.tongdun.robot.web;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.alibaba.fastjson.parser.Feature;

import java.util.List;

/**
 * @author hello
 * @date 2019-10-18 13:46
 * @description
 */
public class Hello {
    public static void main(String[] args) {
        String str = "[\n" +
                "  {\n" +
                "    \"type\": \"SEND\",\n" +
                "    \"dataMapping\": {\n" +
                "      \"userid\": \"account\",\n" +
                "      \"ts\": \"ts\",\n" +
                "      \"sign\": \"sign\",\n" +
                "      \"mobile\": \"taskItem.mobile\",\n" +
                "      \"msgcontent\": \"taskItem.content\",\n" +
                "      \"time\": \"taskItem.scheduleTime\",\n" +
                "      \"URL\": \"http://1.1.1.1:8081/api/sms/send\",\n" +
                "      \"password\": \"password\"\n" +
                "    },\n" +
                "    \"maxSendCount\": \"1000\",\n" +
                "    \"tps\": \"50\",\n" +
                "    \"channelPattern\": \"JSON\",\n" +
                "    \"sendSeparate\": \"\",\n" +
                "    \"httpHeaderParams\": {\n" +
                "      \"Authorization\": \"authorization\"\n" +
                "    }\n" +
                "  },\n" +
                "  {\n" +
                "    \"type\": \"REPORT\",\n" +
                "    \"dataMapping\": {\n" +
                "      \"userid\": \"account\",\n" +
                "      \"ts\": \"ts\",\n" +
                "      \"sign\": \"sign\",\n" +
                "      \"password\": \"password\",\n" +
                "      \"URL\": \"http://1.1.1.1/api/v2/sms/query\"\n" +
                "    },\n" +
                "    \"tps\": \"10\",\n" +
                "    \"channelPattern\": \"JSON\"\n" +
                "  }\n" +
                "]";

//        Object list = JSON.parse(str, Feature.OrderedField);

        List<HelloBean> list = JSON.parseObject(str, new TypeReference<List<HelloBean>>() {}.getType(), Feature.OrderedField);
        System.out.println(list);
    }
}

  

 

package cn.tongdun.robot.web;

import com.alibaba.fastjson.JSONObject;

/**
 * @author hello
 * @date 2019-10-18 14:29
 * @description
 */
public class HelloBean {

    /**
     * type : REPORT
     * dataMapping : {"userid":"account","ts":"ts","sign":"sign","password":"password","URL":"http://47.99.224.177:8081/api/v2/sms/query"}
     * tps : 10
     * channelPattern : JSON
     */

    private String type;
    private JSONObject dataMapping;
    private String tps;
    private String channelPattern;

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public JSONObject getDataMapping() {
        return dataMapping;
    }

    public void setDataMapping(JSONObject dataMapping) {
        this.dataMapping = dataMapping;
    }

    public String getTps() {
        return tps;
    }

    public void setTps(String tps) {
        this.tps = tps;
    }

    public String getChannelPattern() {
        return channelPattern;
    }

    public void setChannelPattern(String channelPattern) {
        this.channelPattern = channelPattern;
    }
}

  

 

posted @ 2019-10-18 14:38  牧之丨  阅读(10610)  评论(0编辑  收藏  举报