如何将值列表为JSON的Map序列化?

时间:2013-11-08 15:39:42

标签: java flexjson

我需要使用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&amp; NodeOutput只是POJO,只有一些字符串字段。 我被Map&gt;困住了。 我尝试了许多不同的方法而没有成功。 你能帮我解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

使用deepSerialize方法而不是通常的序列化为我工作:

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

对类似问题的回答将告诉您需要知道的所有内容:How to serialize Map<String, List<Object>> with FlexJSON

相关问题