title: Contextual deserialization of a field based on multiple fields?
body: <p>Can <code>CustomSerializer</code> 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.</p>
  <p>Consider a case class for StreetAddress</p>
  <pre><code>case class StreetAddress(
      addressLine1: Option[String] = None,
      addressLine2: Option[String] = None,
      city: Option[String] = None,
      state: Option[StateCode] = None,
      zipcode: Option[String] = None,
      country: Option[CountryCode] = None
  )
  </code></pre>
  <p>Currently the <code>CustomSerializer</code> for <code>StateCode</code> looks like this</p>
  <pre><code>class StateCodeSerializer
      extends CustomSerializer[StateCode](
          implicit formats =&gt;
              ({
                  case JString(s) =&gt;
                      StateCode(s).getOrElse(
                      throw new IllegalArgumentException(s&quot;Invalid state code: $s&quot;)
                )
              case JInt(i) =&gt;
                StateCode(i.toInt).getOrElse(
                  throw new IllegalArgumentException(s&quot;Invalid state code: $i&quot;)
                )
            }, {
              case x: StateCode =&gt;
                  JString(x.toString)
          })
      )
  </code></pre>
  <p>The deserializer for <code>StateCode</code> needs to know the <code>CountryCode</code> as well because states across several countries can share the same StateCode string. Ex: &quot;CA&quot; is California in US as well Cadiz in Spain.</p>
  <p>Is it possible for <code>StateCodeSerializer</code> to be aware of what the value of <code>country</code> is in the JSON?</p>