ダメ人間オンライン

あまり信用しないほうがいい技術メモとか備忘録とかその他雑記

Spring Framework で空JSONを返したい

{}

やんごとなき事情でこういう空っぽのJSONを返す必要がある場合には空っぽの response 用の class を用意して JsonSerialize annotaion をつけてやるのが楽。

@JsonSerialize
public class NantokaResponse {
}
@RestController
public class NantokaController {
    @GetMapping("/wei")
    public NantokaResponse wei() {
        return new NantokaResponse();
    }
}