1

Is there any way to assign default value when a property is missing in Json file while deserializing JSon using Jackson

@NoArgsConstructor
@Getter
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(NON_NULL)
@AllArgsConstructor
public class Sample {

    private String value = "hai";

   /* public Sample(String value) {
       this.value = value; // when I remove @AllArgsConstructor and  uncomment this constructor ,the default value is assigned if the property is missing in Json file
    }*/ 
 }
Priya
  • 1,096
  • 4
  • 15
  • 32

1 Answers1

0

You need not do anything for this,

class Student {
  public String course = "MATH";
}

If course value is missing from the JSON, the value in the bean will by default set to MATH.

Neeraj Jain
  • 7,643
  • 6
  • 34
  • 62