Sample:
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;
}
}
}
Expected:
{{"a": "foo1"}:{"a":"foo2"}}
Ouput:
{"Test$Foo@4f4a7090":{"a":"foo2"}}
I used jackson-core-asl-1.9.13.jar. Anyone know why the Key is not serialized and how I can modify it such that it is serialized?