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
Can CustomSerializer perform deserialization of one field based on the value in another field? In all the examples I've seen, each field is deserialized independently without any context.
Currently the CustomSerializer for StateCode looks like this
class StateCodeSerializer
extends CustomSerializer[StateCode](
implicit formats =>
({
case JString(s) =>
StateCode(s).getOrElse(
throw new IllegalArgumentException(s"Invalid state code: $s")
)
case JInt(i) =>
StateCode(i.toInt).getOrElse(
throw new IllegalArgumentException(s"Invalid state code: $i")
)
}, {
case x: StateCode =>
JString(x.toString)
})
)
The deserializer for StateCode needs to know the CountryCode as well because states across several countries can share the same StateCode string. Ex: "CA" is California in US as well as Cadiz in Spain.
Is it possible for StateCodeSerializer to be aware of what the value of country is in the JSON?
The text was updated successfully, but these errors were encountered:
json4s version
3.6.7
scala version
2.12
jdk version
11
Can
CustomSerializer
perform deserialization of one field based on the value in another field? In all the examples I've seen, each field is deserialized independently without any context.Consider a case class for StreetAddress
Currently the
CustomSerializer
forStateCode
looks like thisThe deserializer for
StateCode
needs to know theCountryCode
as well because states across several countries can share the same StateCode string. Ex: "CA" isCalifornia
in US as well asCadiz
in Spain.Is it possible for
StateCodeSerializer
to be aware of what the value ofcountry
is in the JSON?The text was updated successfully, but these errors were encountered: