Ignore missing properties during Jackson JSON deserialization in Java

前端 未结 6 1484
时光说笑
时光说笑 2020-12-03 06:14

In the example

class Person {
   String name;
   int age;
}

If the JSON object has a missing property \'age\',

{
  name :          


        
6条回答
  •  甜味超标
    2020-12-03 07:04

    You could also change your class to use an Integer instead of an int, in which case Jackson will handle null/missing "age" values properly. Just adding this answer for those looking for an alternative that doesn't involve using annotations.

    class Person {
       String name;
       Integer age;
    }
    

提交回复
热议问题