我正在尝试反序列化 java.net.HttpCookie,它没有默认的无参数构造函数,并且得到: org.codehaus.jackson.map.JsonMappingException:找不到类型 [简单类型,类 java.net. HttpCookie]:无法从 JSON 对象实例化(需要添加/启用类型信息?),位于 [来源:java.io.StringReader@5a395674;行:1,列:35
这是与 jackson-mapper-asl v 1.9.13 一起使用的
我发现Jackson 3rd Party Class With No Default Constructor并尝试通过 getDeserializationConfig 和 using 模块使用他们的解决方案。我在下面展示了模块代码。
abstract class HttpCookieMixIn {
@JsonCreator
public HttpCookieMixIn(@JsonProperty("name") String name, @JsonProperty("value") String value) {
logger.info("Mixin called!");
}
}
public class MyModule extends SimpleModule {
public MyModule() {
super("ModuleName", new Version(0,0,1,null));
}
@Override
public void setupModule(SetupContext context) {
context.setMixInAnnotations(java.net.HttpCookie.class, HttpCookieMixIn.class);
logger.info("Set mixin annotation");
}
}
Run Code Online (Sandbox Code Playgroud)
在服务器端点的构造函数中,我有以下内容:
public ServerEndpointConstructor() {
mapper = new ObjectMapper();
mapper.registerModule(new …Run Code Online (Sandbox Code Playgroud)