Setting Default value to a variable when deserializing using gson

后端 未结 3 1835
南旧
南旧 2020-12-03 20:40

I am trying to convert JSON to Java object. When a certain value of a pair is null, it should be set with some default value.

Here is my POJO:



        
3条回答
  •  时光说笑
    2020-12-03 21:20

    You can simply make a universal function that checks for null

    model.SchoolName= stringNullChecker(model.SchoolName);
    
    public static String stringNullChecker(String val) {
            if (null == val) val = "";
            return val;
    }
    

提交回复
热议问题