【Spock】LocalDate型をJSONに変換
862 ワード
問題
controllerのテストコードを書いていたら、LocalDate型がJSONにうまく変換できなかった。
原因
変換後よくわからない複雑なJSONオブジェクトになっていた。これは、JacksonがLocalDate型のJavaインスタンスをそのままJSON形式に変換しているから。変な文字列じゃなくて、読みやすい"YYYY-MM-DD"で統一したい!
@JsonSerialize で解決!!
model のLocalDate型のオブジェクトに@JsonSerializeアノテーションをつければ良い!
@JsonSerialize(using = LocalDateSerializer.class)
@JsonProperty("created_at")
private LocalDate createdAt;
詳細は後日追記
Author And Source
この問題について(【Spock】LocalDate型をJSONに変換), 我々は、より多くの情報をここで見つけました https://qiita.com/oden141/items/ad37a5f7392bfe62cc41著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .