小编Pad*_*dyD的帖子

使用toString进行rapidxml序列化并使用String构造函数进行反序列化

我有一个POJO,看起来像这样:

public class Thing
{
   private final int x;
   private final int y;
   private final int z;

   public Thing(String strThing)
   {
       // parse strThing which is in some arbitrary format to set x, y and z
   }

   @Override
   public String toString()
   {
       // return a string representation of thing
       // (same format as that parsed by the constructor)
   }

   @Override
   public boolean equals(Object obj) ...

   @Override
   public int hashCode() ...

}
Run Code Online (Sandbox Code Playgroud)

我希望将它用作映射的键​​(例如HashMap<Thing, SomeOtherPOJO>),当序列化为json时,使用Thing的toString()表示键,并且在反序列化时使用String构造函数.这可能是使用像jackson数据绑定注释这样简单的东西吗?解决这个问题的最佳方法是什么?

java json dictionary fasterxml

8
推荐指数
1
解决办法
7048
查看次数

标签 统计

dictionary ×1

fasterxml ×1

java ×1

json ×1