我试图弄清楚如何解释泽西和杰克逊如何反序列化我作为字节 [] 传递的未来。
我创建了自己的 ContextResolver
public class ObjectMapperContextResolver implements ContextResolver<ObjectMapper> {
private static ObjectMapper mapper = null;
public ObjectMapperContextResolver() {
mapper = ObjectMapperFactory.getObjectMapper();
}
@Override
public ObjectMapper getContext(Class<?> type) {
return mapper;
}
}
以及 ObjectMapper 的实现
public static ObjectMapper getObjectMapper() {
ObjectMapper defaultObjectMapper = new ObjectMapper();
SimpleModule futureModule = new SimpleModule("FutureModule");
futureModule.<Future>addDeserializer(Future.class, new FutureDeserializer<String>());
defaultObjectMapper.registerModule(futureModule);
return defaultObjectMapper;
}
然后最后在我的 FutureDeserializer 的实现中
public class FutureDeserializer<T> extends StdDeserializer<Future<T>>{
public FutureDeserializer() {
super(Future.class);
}
@Override
public Future<T> deserialize(JsonParser jp, DeserializationContext ctxt)
throws IOException {
ObjectMapper mapper=(ObjectMapper)jp.getCodec();
//TODO: Breakpoint never stop here
return null;
}
}
然后我在我ResourceConfig
开始之前注册JerseyTest
ResourceConfig rc = new ResourceConfig();
rc.register(SpringLifecycleListener.class);
rc.register(RequestContextFilter.class);
rc.register(new JacksonFeature());
rc.register(new ObjectMapperContextResolver());
但是当我运行测试时,调用了 ObjectMapperContextResolver 并将映射器返回到 Jersey,但他从不使用 FutureDeserializer。
知道我在做什么错吗?