LoginSignup
3
3

More than 3 years have passed since last update.

Spring bootでjacksonを使った時にcom.fasterxml.jackson.databind.exc.InvalidDefinitionExceptionが出て対処したのでメモ

Last updated at Posted at 2019-06-16

環境

  • OS: macOS Mojave
  • Spring boot version: 2.1.4.RELEASE

例外発生と対処まで

Spring bootでRest Controllerを作成して、ブラウザのアドレスバーにURLを入力してリソースを取得しようとすると以下のような例外が発生しました。

com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class <エラーが出たクラス名> and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: <レスポンスのクラス名>["<対象の項目名>"]->java.util.ArrayList[0]-><エラーが出たクラス名>["<エラーが出た項目名>"])

エラーが発生したクラスでは、getterを用意していなかったので、これが怪しいと思い、getterを追加したら治りました。考えてみれば当たり前かもしれませんが、外部のクラスから取得できる形にしておかないとJSONに変換する時に変換対象項目を取得できずに例外が発生するみたいですね。

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3