我需要使用 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。 我被 Map > 困住了。 我尝试了许多不同的方法但没有成功。 你能帮我解决这个问题吗?
最佳答案
使用 deepSerialize 方法而不是通常的序列化对我有用:
DiagramNodeDataSerializableRepresentation p = createTestData();
JSONSerializer serializer = new JSONSerializer();
String retval = serializer.deepSerialize( p );
这个类似问题的答案会告诉你所有你需要知道的:How to serialize Map<String, List<Object>> with FlexJSON
关于java - 如何将值为Lists的Map序列化为JSON?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19862902/