我使用springboot返回一个LocalDateTime和LocalDate参数,所以在我的背后我把:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-java8</artifactId>
<version>5.0.12.Final</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.8.2</version>
</dependency>
并在应用程序属性中:
spring.jackson.serialization.write_dates_as_timestamps=false
所以我现在回来了这两种类型:
entrada": "2017-01-01T22:00:00", // LocalDateTime
"previsao": "2017-01-01",//LocalDate
在我的面前,我使用:
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-parameter-names</artifactId>
<version>2.8.6</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jdk8</artifactId>
<version>2.8.6</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.8.6</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>
<version>3.1.2.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jackson-provider</artifactId>
<version>3.1.2.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-client</artifactId>
<version>3.1.2.Final</version>
</dependency>
在我班上:
ResteasyClient client;
ProtocoloClient protocoloClient;
public ProtocoloClientImpl() {
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new JavaTimeModule())
;
client = new ResteasyClientBuilder().register(mapper).build();
ResteasyWebTarget target = client.target("http://localhost:8181/");
protocoloClient = target.proxy(ProtocoloClient.class);
}
所以,当我打电话给我时,我得到了错误:
javax.ws.rs.client.ResponseProcessingException:javax.ws.rs.ProcessingException:org.codehaus.jackson.map.JsonMappingException:无法从JSON实例化类型[simple type,class java.time.LocalDateTime]的值串;没有单字符串构造函数/工厂方法(通过参考链:br.com.exmart.indicadorRTDPJ.service.rest.vo.ProtocoloVO [&#34; entrada&#34;])
我想尝试放入我的
public class ProtocoloVO {
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss")
private LocalDateTime entrada;
但得到了同样的错误
我想尝试把
@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
private LocalDateTime entrada;