Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I believe there a two bugs here one related to Map the other to Seq(tuple) </p> <p>1) Maps not exporting the type information on serialization</p> <p>2) Seq(Tuple) ignores type information on De-Serialization </p> <p>Workround: - Use a wrapper class to replace tuple.</p> <pre><code>@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXTERNAL_PROPERTY, property = "type") @JsonSubTypes(Array( new Type(value = classOf[B], name = "B"), new Type(value = classOf[C], name = "C"))) trait A{} case class B(value : Double) extends A case class C(value : String) extends A case class ContainerWithMap( results: Map[String, A]) case class ContainerWithTupleSeq( results: Seq[(String, A)]) case class ContainerWithWrappedSeq( results: Seq[WrapperClass]) case class WrapperClass(s : String, a : A) class ATest extends FlatSpec with ShouldMatchers { behavior of "A" val map: Map[String, A] = Map("ExampleB" -&gt; B(1.0), "ExampleC" -&gt; C("One")) val seq: Seq[WrapperClass] = Seq(WrapperClass("ExampleB", B(1.0)), WrapperClass( "ExampleC",C("One"))) it should "fail not supporting reciprocal serialize de-serialize behaviour for maps" in { val owner : ContainerWithMap = ContainerWithMap(map) val serialize: String = JsonMarshall.serialize(owner) println(serialize) // types not exported on serialization val thrown = evaluating{JsonMarshall.deserialize[ContainerWithMap](serialize)} should produce [JsonMappingException] thrown.getMessage should startWith("Unexpected token (END_OBJECT), expected FIELD_NAME: missing property 'type' that is to contain type id") } it should "fail not supporting reciprocal serialize de-serialize behaviour for sequence of tuples" in { val owner : ContainerWithTupleSeq = ContainerWithTupleSeq(map.toSeq) val serialize: String = JsonMarshall.serialize(owner) println(serialize) // types ignored on de-Serialization val thrown = evaluating{JsonMarshall.deserialize[ContainerWithTupleSeq](serialize)} should produce [JsonMappingException] thrown.getMessage should startWith("Can not construct instance of com.egc.ost.pricing.contracts.response.A, problem: " + "abstract types either need to be mapped to concrete types, have custom deserializer, or be instantiated with additional type information") } it should "work if using a wrapper class" in { val owner : ContainerWithWrappedSeq = ContainerWithWrappedSeq(seq) val serialize: String = JsonMarshall.serialize(owner) println(serialize) val deserialize: ContainerWithWrappedSeq = JsonMarshall.deserialize[ContainerWithWrappedSeq](serialize) println(deserialize) deserialize should be(owner) } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload