LoginSignup
0
0

More than 1 year has passed since last update.

【JSON】jackson で JSON化したくないプロパティをプログラムで設定

Posted at

まえがき

・Jackson を使ってオブジェクトを JSON 形式に変換
・アノテーションを使わない(使えない)場合
・具体的には "beanClass" を除外したかった

環境

Java 8
jackson 2.6

ObjectMapper で設定

sample.java
            ObjectMapper mapper = new ObjectMapper()
            // ... 設定
            mapper.setAnnotationIntrospector(new JacksonAnnotationIntrospector() {
                private static final long serialVersionUID = -1L; // <- 適宜設定
                @Override
                public boolean hasIgnoreMarker(final AnnotatedMember m) {
                    List<String> exclusions = Arrays.asList("beanClass");
                    return exclusions.contains(m.getName()) || super.hasIgnoreMarker(m);
                }
            });

以上、お疲れさまでした!

0
0
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
0
0