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
The text was updated successfully, but these errors were encountered:
plokhotnyuk
changed the title
DSL-JSON doesn't support scala.collection.immutable.IntMap and scala.collection.mutable.LongMap,
DSL-JSON doesn't support scala.collection.immutable.IntMap and scala.collection.mutable.LongMap
Apr 9, 2019
I see there are some missing arguments so this could be easily supported even from outside the lib, which I'll look to add for next version.
But I'm not sure where to draw the line between nice to have and stuff which must be supported.
Library was built to be extendable and for this example that would look like:
def primitiveMapWriter(manifest: Type, json: DslJson[_]) = {
manifest match {
case pt: ParameterizedType if pt.getRawType == classOf[IntMap[_]] =>
val valueWriter = json.tryFindWriter(pt.getActualTypeArguments.head)
val encoder = new ScalaMapEncoder[Int, Any](
json,
true,
Some(NumberConverter.INT_WRITER.asInstanceOf[JsonWriter.WriteObject[Int]]),
Some(valueWriter.asInstanceOf[JsonWriter.WriteObject[Any]]))
json.registerWriter(manifest, encoder)
encoder
case _ => null
}
}
dslJson.registerWriterFactory(primitiveMapWriter)
It isn't so easy to make it work properly for any types...
I have tried your implementation here, but it throws the following exception in runtime:
java.lang.ClassCastException: scala.Tuple2 cannot be cast to java.lang.Boolean
at com.dslplatform.json.BoolConverter$3.write(BoolConverter.java:25)
at com.dslplatform.json.runtime.IterableEncoder.write(IterableEncoder.scala:34)
at com.dslplatform.json.runtime.IterableEncoder.write(IterableEncoder.scala:6)
at com.github.plokhotnyuk.jsoniter_scala.benchmark.DslPlatformJson$.dslJsonEncode(DslPlatformJson.scala:96)
at com.github.plokhotnyuk.jsoniter_scala.benchmark.IntMapOfBooleansBenchmark.writeDslJsonScala(IntMapOfBooleansBenchmark.scala:68)
at com.github.plokhotnyuk.jsoniter_scala.benchmark.IntMapOfBooleansBenchmarkSpec.$anonfun$new$3(IntMapOfBooleansBenchmarkSpec.scala:26)
No description provided.
The text was updated successfully, but these errors were encountered: