简体   繁体   English

JSON Jackson序列化反序列化列表列表

[英]JSON Jackson serialize deserialize List of List

I use Json-Jackson to serialize/deserialize my object and all goes well with built-in classes. 我使用Json-Jackson序列化/反序列化我的对象,并且与内置类一起运行都很好。
String, int, and so on are very good. 字符串,整数等等都是非常好的。 But now I must serialize/deserialize an object built in a particular manner. 但是现在我必须序列化/反序列化以特定方式构建的对象。 Follow the declaration: 遵循声明:

class A implements Serializable {  
   private String id;
   private List<B> bobjs;
   ...getters & setters (but not for String id)
}
class B implements Serializable {
   private String id;
   private String label;
   private List<C> cobjs;
   ...getters & setters (but not for String id)
}
class C implements Serializable {
   private String id;
   private String label;
   private BigDecimal counts;
   ...getters & setters (but not for String id)
}

If I use the standard serializer/deserialize, it says to me an error message like " java.lang.UnsupportedOperationException..." so it cannot serialize/deserialize bobjs. 如果我使用标准的序列化器/反序列化,它会告诉我一条错误消息,例如“ java.lang.UnsupportedOperationException ...”,因此它无法序列化/反序列化bobjs。
How can I do this in a general manner, so I do not write 3 serializer/deserializer, but only tell to Json-Jackson when encounter an object of type "List" it must serialize/deserialize it like an array (for example). 如何以一般方式执行此操作,因此我不编写3序列化器/反序列化器,而只是告诉Json-Jackson当遇到“列表”类型的对象时,它必须像数组一样对它进行序列化/反序列化。
Thanks all! 谢谢大家!

PS I find examples on google, but they are only for simple object but not for List that are formed of List.. and so on. PS我在google上找到了示例,但它们仅用于简单对象,不适用于由List ..等组成的List。

The problem was due to a really deep object not serializable. 问题是由于无法序列化的对象很深。 Really deep and little. 真的很深,很少。 Thanks all. 谢谢大家

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM