以下のように、Jersey WS のシリアル化された JSON オブジェクトから返される日付形式を構成しようとしています。
@Component
@Provider
@Produces("application/json")
public class JacksonContextResolver implements ContextResolver<ObjectMapper> {
private ObjectMapper mapper = new ObjectMapper();
public JacksonContextResolver() {
mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd"));
}
@Override
public ObjectMapper getContext(Class<?> arg0) {
return mapper;
}
}
しかし、問題はgetContext(Class arg0)メソッドが呼び出されないことです。コンストラクターJacksonContextResolver()のみが呼び出されます。
ただし、次の JAXB の ContextResolver は正常に動作しています。
@Component
@Provider
public class JAXBContextResolver implements ContextResolver<JAXBContext> {
private JAXBContext context;
private Class<?>[] types = {
UserDto.class, AttachmentDto.class
};
public JAXBContextResolver() throws Exception {
this.context = new JSONJAXBContext(JSONConfiguration.natural().rootUnwrapping(false).build(), types);
}
public JAXBContext getContext(Class<?> objectType) {
return context;
}
}
不足している構成があるかどうか、誰にもアドバイスできますか?