How to properly use `PlayJsonCodecs.JsValueCodec`?
@velvia
I tried a super simple App using play.api.libs.json.Json:
import org.velvia.msgpack
import org.velvia.msgpack.PlayJsonCodecs.JsValueCodec
import play.api.libs.json.{JsValue, Json}
object Velvia extends App {
val js: JsValue = Json.parse("""{"amount":40,"currency":"USD","label":"$40.00"}""")
val p: Array[Byte] = msgpack.pack(js)
println(java.util.Arrays.toString(p))
val u = msgpack.unpack[JsValue](p)
}
is returning:
[-125, -90, 97, 109, 111, 117, 110, 116, -110, 0, -60, 1, 40, -88, 99, 117, 114, 114, 101, 110, 99, 121, -93, 85, 83, 68, -91, 108, 97, 98, 101, 108, -90, 36, 52, 48, 46, 48, 48]
Exception in thread "main" org.velvia.InvalidMsgPackDataException: Input contains invalid type value 0
at org.velvia.msgpack.Codec$$anonfun$defaultUnpackFunc$1.apply(Codecs.scala:30)
at org.velvia.msgpack.Codec$$anonfun$defaultUnpackFunc$1.apply(Codecs.scala:30)
at org.velvia.msgpack.Codec$class.unpack(Codecs.scala:20)
at org.velvia.msgpack.PlayJsonCodecs$JsValueCodec$.unpack(PlayJsonCodecs.scala:49)
at org.velvia.msgpack.Format$.unpackSeq(Format.scala:205)
at org.velvia.msgpack.CollectionCodecs$SeqCodec$$anonfun$3$$anonfun$apply$1.apply(CollectionCodecs.scala:17)
at org.velvia.msgpack.CollectionCodecs$SeqCodec$$anonfun$3$$anonfun$apply$1.apply(CollectionCodecs.scala:17)
at scala.Function1$$anonfun$andThen$1.apply(Function1.scala:52)
at org.velvia.msgpack.Codec$class.unpack(Codecs.scala:20)
at org.velvia.msgpack.PlayJsonCodecs$JsValueCodec$.unpack(PlayJsonCodecs.scala:49)
at org.velvia.msgpack.Format$$anonfun$unpackMap$1.apply(Format.scala:218)
at org.velvia.msgpack.Format$$anonfun$unpackMap$1.apply(Format.scala:217)
at scala.collection.immutable.Range.foreach(Range.scala:160)
at org.velvia.msgpack.Format$.unpackMap(Format.scala:217)
at org.velvia.msgpack.CollectionCodecs$CMapCodec$$anonfun$9$$anonfun$apply$3.apply(CollectionCodecs.scala:46)
at org.velvia.msgpack.CollectionCodecs$CMapCodec$$anonfun$9$$anonfun$apply$3.apply(CollectionCodecs.scala:46)
at scala.Function1$$anonfun$andThen$1.apply(Function1.scala:52)
at org.velvia.msgpack.Codec$class.unpack(Codecs.scala:20)
at org.velvia.msgpack.PlayJsonCodecs$JsValueCodec$.unpack(PlayJsonCodecs.scala:49)
at org.velvia.msgpack.package$.unpack(package.scala:12)
at org.velvia.msgpack.package$.unpack(package.scala:53)
at Velvia$.delayedEndpoint$Velvia$1(Velvia.scala:14)
at Velvia$delayedInit$body.apply(Velvia.scala:7)
at scala.Function0$class.apply$mcV$sp(Function0.scala:34)
at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
at scala.App$$anonfun$main$1.apply(App.scala:76)
at scala.App$$anonfun$main$1.apply(App.scala:76)
at scala.collection.immutable.List.foreach(List.scala:392)
at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:35)
at scala.App$class.main(App.scala:76)
at Velvia$.main(Velvia.scala:7)
at Velvia.main(Velvia.scala)
I am using
libraryDependencies += "com.typesafe.play" %% "play-json" % "2.6.6"
libraryDependencies += "org.velvia" %% "msgpack4s" % "0.6.0"
What am I doing wrong?
Hmm… I think this is likely because there are some formatting upgrades that need to be done for newer Messagepack formats.
On Oct 5, 2017, at 2:32 PM, Jean Logeart [email protected] wrote:
I tried a super simple App using play.api.libs.json.Json:
import org.velvia.msgpack import org.velvia.msgpack.PlayJsonCodecs.JsValueCodec import play.api.libs.json.{JsValue, Json}
object Velvia extends App { val js: JsValue = Json.parse("""{"amount":40,"currency":"USD","label":"$40.00"}""") val p: Array[Byte] = msgpack.pack(js)
println(java.util.Arrays.toString(p))
val u = msgpack.unpackJsValue } is returning:
[-125, -90, 97, 109, 111, 117, 110, 116, -110, 0, -60, 1, 40, -88, 99, 117, 114, 114, 101, 110, 99, 121, -93, 85, 83, 68, -91, 108, 97, 98, 101, 108, -90, 36, 52, 48, 46, 48, 48] Exception in thread "main" org.velvia.InvalidMsgPackDataException: Input contains invalid type value 0 at org.velvia.msgpack.Codec$$anonfun$defaultUnpackFunc$1.apply(Codecs.scala:30) at org.velvia.msgpack.Codec$$anonfun$defaultUnpackFunc$1.apply(Codecs.scala:30) at org.velvia.msgpack.Codec$class.unpack(Codecs.scala:20) at org.velvia.msgpack.PlayJsonCodecs$JsValueCodec$.unpack(PlayJsonCodecs.scala:49) at org.velvia.msgpack.Format$.unpackSeq(Format.scala:205) at org.velvia.msgpack.CollectionCodecs$SeqCodec$$anonfun$3$$anonfun$apply$1.apply(CollectionCodecs.scala:17) at org.velvia.msgpack.CollectionCodecs$SeqCodec$$anonfun$3$$anonfun$apply$1.apply(CollectionCodecs.scala:17) at scala.Function1$$anonfun$andThen$1.apply(Function1.scala:52) at org.velvia.msgpack.Codec$class.unpack(Codecs.scala:20) at org.velvia.msgpack.PlayJsonCodecs$JsValueCodec$.unpack(PlayJsonCodecs.scala:49) at org.velvia.msgpack.Format$$anonfun$unpackMap$1.apply(Format.scala:218) at org.velvia.msgpack.Format$$anonfun$unpackMap$1.apply(Format.scala:217) at scala.collection.immutable.Range.foreach(Range.scala:160) at org.velvia.msgpack.Format$.unpackMap(Format.scala:217) at org.velvia.msgpack.CollectionCodecs$CMapCodec$$anonfun$9$$anonfun$apply$3.apply(CollectionCodecs.scala:46) at org.velvia.msgpack.CollectionCodecs$CMapCodec$$anonfun$9$$anonfun$apply$3.apply(CollectionCodecs.scala:46) at scala.Function1$$anonfun$andThen$1.apply(Function1.scala:52) at org.velvia.msgpack.Codec$class.unpack(Codecs.scala:20) at org.velvia.msgpack.PlayJsonCodecs$JsValueCodec$.unpack(PlayJsonCodecs.scala:49) at org.velvia.msgpack.package$.unpack(package.scala:12) at org.velvia.msgpack.package$.unpack(package.scala:53) at Velvia$.delayedEndpoint$Velvia$1(Velvia.scala:14) at Velvia$delayedInit$body.apply(Velvia.scala:7) at scala.Function0$class.apply$mcV$sp(Function0.scala:34) at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12) at scala.App$$anonfun$main$1.apply(App.scala:76) at scala.App$$anonfun$main$1.apply(App.scala:76) at scala.collection.immutable.List.foreach(List.scala:392) at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:35) at scala.App$class.main(App.scala:76) at Velvia$.main(Velvia.scala:7) at Velvia.main(Velvia.scala) I am using
libraryDependencies += "com.typesafe.play" %% "play-json" % "2.6.6" libraryDependencies += "org.velvia" %% "msgpack4s" % "0.6.0" What am I doing wrong?
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/velvia/msgpack4s/issues/15, or mute the thread https://github.com/notifications/unsubscribe-auth/ABA32w-IVfDt6zoMdni9mHvEWdGhUbTAks5spUrQgaJpZM4Pvusy.
How can I get it to work?
I'd like to reuse all my Writes and Reads to serialize and deserialize to MsgPack.
In practice, I am mostly interested in the deserialization.