样品:
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import org.codehaus.jackson.map.ObjectMapper;
public class Test {
public static void main(String[] args) throws Exception {
ObjectMapper mapper = new ObjectMapper();
Map<Foo, Foo> map = new HashMap<Foo, Foo>();
map.put(new Foo("foo1"), new Foo("foo2"));
System.out.println(mapper.writeValueAsString(map));
}
public static class Foo implements Serializable {
public String a;
public Foo(String a) {
this.a = a;
}
}
}
预期:
{{"a": "foo1"}:{"a":"foo2"}}
输出继电器:
{"Test$Foo@4f4a7090":{"a":"foo2"}}
我使用了jackson-core-asl-1.9.13.jar。任何人都知道为什么Key没有被序列化以及我如何修改它以便它被序列化?