我试图用RestEasy的客户端调用一个REST服务客户RestEasy的与LocalDateTime
在我的服务我springboot创建并返回一个LocalDateTime PROPERT
如果我用这个depencency
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.8.8</version>
</dependency>
这是我在我的豆中的代码:
private LocalDateTime dtPublicacao;
这是当我打电话给我的服务:
dtPublicacao: "2017-04-20T00:00:00"
如果我删除这样的结果:
dtPublicacao: {
hour: 0,
minute: 0,
second: 0,
nano: 0,
dayOfYear: 110,
dayOfWeek: "THURSDAY",
month: "APRIL",
dayOfMonth: 20,
year: 2017,
monthValue: 4,
chronology: {
id: "ISO",
calendarType: "iso8601"
}
}
所以在我的客户我创建相同的模型,并用它来执行获取
Client client = ClientBuilder.newClient();
WebTarget target = client.target("http://localhost:8585").path("/edital/");
try{
List<EditalVO> response = target.request().get(new GenericType<List<EditalVO>>(){});
return response;
}catch (NotFoundException e) {
throw new NotFoundException();
}
所以,如果我把我的客户LocalDateTime我得到这个错误:
Caused by: org.codehaus.jackson.map.JsonMappingException: Can not instantiate value of type [simple type, class java.time.LocalDateTime] from JSON String; no single-String constructor/factory method (through reference chain: br.com.lumera.protesto.edital.vo.EditalVO["dtExpiracao"])
解决我需要在我的客户端形式LocalDateTime更改为日期,并添加
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date dtPublicacao;
我已经尝试添加在我的客户端相同的依赖,但他注册LocalDateTimeSerializer.class但是当我叫他REST点没有通过序列化方法,我又得到了错误。
我可以从Restasey客户端接收并发送LocalDateTime吗?
TKS
UPDATE 我已经尽力做到这一点太:
ObjectMapper obj = new ObjectMapper();
obj.registerModule(new JavaTimeModule())
没有成功,后来我尝试在我的客户:
client.register(obj);
与没有成功..如果我调试我的应用程序,他输入方法
public LocalDateTimeSerializer(DateTimeFormatter f) {
super(LocalDateTime.class, f);
}
private LocalDateTimeSerializer(LocalDateTimeSerializer base, Boolean useTimestamp, DateTimeFormatter f) {
super(base, useTimestamp, f);
}
在LocalDateTimeSerializer
但不`吨的序列化方法进入或反序列化
的[javadoc的(https://docs.jboss.org/resteasy /docs/3.0.9.Final/javadocs/javax/ws/rs/core/Configurable.html#register(java.lang.Object))说:注册扩展提供程序或功能元提供程序实例可用于这个范围的范围。 –