in my crud application a post api receives the following body
@Data
@AllArgsConstructor
@NoArgsConstructor
public class BodyRequest {
private String description;
private List<Request> ListRequest;
}
when listRequest is not passed in the body of the request it becomes null is there any way to set an empty value for the listRequest list when it is null? I would like to know if there is the possibility to add an annotation on the list that allows such modification as @ value or @json
I tried to add @JsonDeserialize (using = OptimizedListDeserializer.class) to the list and to define the OptimizedListDeserializer class
@Data
@AllArgsConstructor
@NoArgsConstructor
public class BodyRequest {
private String description;
@JsonDeserialize (using = OptimizedListDeserializer.class)
private List<Request> ListRequest;
}
public class OptimizedListDeserializer extends StdDeserializer<List<Request> > {
protected OptimizedListDeserializer(StdDeserializer<?> src) {
super(src);
// TODO Auto-generated constructor stub
}
@Override
public List<Request> deserialize(JsonParser jp, DeserializationContext ctxt)
throws IOException {
return new ArrayList<>();
}
}
but when i try to call the service i get
"code": 415,
"error": "Content type 'application/json;charset=UTF-8' not supported"