I'm doing a test client in java.
My workbook class looks like this:
public class Livro {
private Long id;
private String nome;
@JsonFormat(shape = JsonFormat.Shape.STRING,pattern="dd/MM/yyyy")
private LocalDate publicacao;
private String editora;
private String resumo;
private List<Comentario> comentarios;
private Autor autor;
// get and sets
}
I get the json seginte.
[
{
"id": 1,
"nome": "Livro de teste 2",
"publicacao": "20/05/2014",
"editora": "teste",
"resumo": "teste de resumo"
}
]
If you use the publicacao
field as Date
it works perfectly.
But I would like to use as Localdate
as defined in Class
However the following error occurs.
Caused by: java.time.format.DateTimeParseException: Text '20 / 05/2014 ' could not be parsed at index 0 at java.time.format.DateTimeFormatter.parseResolved0 (DateTimeFormatter.java:1949) at java.time.format.DateTimeFormatter.parse (DateTimeFormatter.java:1851) at java.time.LocalDate.parse (LocalDate.java:400) at java.time.LocalDate.parse (LocalDate.java:385) at com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer.deserialize (LocalDateDeserializer.java:67) at com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer.deserialize (LocalDateDeserializer.java:32) at com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize (SettableBeanProperty.java:490) at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet (MethodProperty.java:95) at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject (BeanDeserializer.java:341) ... 14 more
In other words, how do I parse a field json "publicacao": "20/05/2014"
for a Localdate
field?
To make the client I am using the following dependencies in maven.
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.2.5.RELEASE</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.7.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.4.0</version>
</dependency>
</dependencies>