【问题标题】:How to serialize Map with values being Lists to JSON?如何将值为列表的映射序列化为 JSON?
【发布时间】:2013-11-08 15:39:42
【问题描述】:

我需要用 flexJSON 2.0 序列化这个特定的对象:

public class DiagramNodeDataSerializableRepresentation {

    private List<Node> nodes;
    private Map<Node, List<NodeOutput>> connections;

    public DiagramNodeDataSerializableRepresentation() {

    }

    public List<Node> getNodes() {
        return nodes;
    }

    public void setNodes(List<Node> nodes) {
        this.nodes = nodes;
    }

    public Map<Node, List<NodeOutput>> getConnections() {
        return connections;
    }

    public void setConnections(Map<Node, List<NodeOutput>> connections) {
        this.connections = connections;
    }

}

Node 和 NodeOutput 只是带有一些字符串字段的 POJO。 我被地图卡住了>。 我尝试了许多不同的方法,但都没有成功。 你能帮我解决这个问题吗?

【问题讨论】:

    标签: java flexjson


    【解决方案1】:

    使用 deepSerialize 方法代替通常的序列化对我有用:

        DiagramNodeDataSerializableRepresentation p = createTestData();
        JSONSerializer serializer = new JSONSerializer();
        String retval = serializer.deepSerialize( p );
    

    这个类似问题的答案会告诉你所有你需要知道的:How to serialize Map<String, List<Object>> with FlexJSON

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-13
      • 1970-01-01
      • 2021-05-10
      • 1970-01-01
      • 2020-06-24
      • 1970-01-01
      • 1970-01-01
      • 2017-08-24
      相关资源
      最近更新 更多