How to get a JsonProcessingException using Jackson

后端 未结 8 1211
醉梦人生
醉梦人生 2021-01-07 16:35

Might be a strange question but indeed I would like to achieve a a bit more coverage on my tests and although I coded against a JsonProcessingException I can\'t

8条回答
  •  旧时难觅i
    2021-01-07 17:18

    You could use something like this:

    private static class ClassThatJacksonCannotSerialize {
        private final ClassThatJacksonCannotSerialize self = this;
    
        @Override
        public String toString() {
            return self.getClass().getName();
       }
    }
    

    Which results in a JsonProcessingException with message Direct self-reference leading to cycle (through reference chain: ClassThatJacksonCannotSerialize["self"])

提交回复
热议问题