Java 8 LocalDate Jackson 格式 - Java 8 LocalDate Jackson format

問題:

For java.util.Date when I do對於java.util.Date當我這樣做時

@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd/MM/yyyy")  
  private Date dateOfBirth;

then in JSON request when I send然後在我發送時在 JSON 請求中

{ {"dateOfBirth":"01/01/2000"} }  

it works.有用。

How should I do this for Java 8's LocalDate field??我應該如何爲Java 8 的 LocalDate字段執行此操作?

I tried having我試過

@JsonDeserialize(using = LocalDateDeserializer.class)  
@JsonSerialize(using = LocalDateSerializer.class)  
private LocalDate dateOfBirth;  

It didn't work.它沒有用。

Can someone please let me know what's the right way to do this..有人可以讓我知道這樣做的正確方法是什麼..

Below are dependencies下面是依賴

<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>jaxrs-api</artifactId>
     <version>3.0.9.Final</version>
</dependency>
<dependency>
    <groupId>com.fasterxml.jackson.jaxrs</groupId>
    <artifactId>jackson-jaxrs-json-provider</artifactId>
    <version>2.4.2</version>
</dependency>
<dependency>
    <groupId>com.wordnik</groupId>
    <artifactId>swagger-annotations</artifactId>
    <version>1.3.10</version>
</dependency>

解決方案:

參考一: https://en.stackoom.com/question/1wqrA
參考二: https://stackoom.com/question/1wqrA
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章