You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm not sure if there's a solution built-in to jackson that would treat a missing entry as an empty list. Technically a null object, empty list, and non-empty list are different scenarios one might want to detect based on the inputted json.
Work arounds you can try (I'm not sure if all will work):
rename cars to _cars for the variable and add a getter that converts null's to empty Seq's
use a JsonCreator that does this once at construction time
convert the Seq[String] to an Option[Seq[String]] so you know it is optionally provided.
I have the exact same issue.
It seems strange to want to handle null values in Scala immutable collections.
Anyway, as workaround I used a var instead of a val:
case class Person(
...
@JsonProperty("phones") var phones: Seq[String],
...
) {
phones = if(phones == null) Nil else phones
}
I have the following demo codes:
In the parsed
person
instance,cars
field is a Javanull
, is there any way to convert it intoNil
directly?The text was updated successfully, but these errors were encountered: