Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

skuber.json.base64format is fundamentally broken #402

Open
jroper opened this issue Oct 11, 2024 · 0 comments
Open

skuber.json.base64format is fundamentally broken #402

jroper opened this issue Oct 11, 2024 · 0 comments

Comments

@jroper
Copy link
Contributor

jroper commented Oct 11, 2024

This code:

  implicit val base64Format: Format[Array[Byte]] = (
      JsPath.format[String].inmap(s => Base64.decodeBase64(s), (bytes: Array[Byte]) => Base64.encodeBase64String(bytes))
  )

https://github.com/doriordan/skuber/blob/master/client/src/main/scala/skuber/json/package.scala#L1070-L1072

Is fundamentally broken. JsPath.format is used to read and produce JSON objects, but this formatter is producing a JsString. The result, when you attempt to serialise an object that uses this formatter, is this error:

java.lang.RuntimeException: when empty JsPath, expecting JsObject
	at play.api.libs.json.JsPath$.step$1(JsPath.scala:141)
	at play.api.libs.json.JsPath$.buildSubPath$1(JsPath.scala:156)
	at play.api.libs.json.JsPath$.$anonfun$createObj$2(JsPath.scala:173)
	at scala.collection.immutable.ArraySeq.foldLeft(ArraySeq.scala:222)
	at play.api.libs.json.JsPath$.createObj(JsPath.scala:172)
	at play.api.libs.json.PathWrites.$anonfun$at$3(JsConstraints.scala:188)
        ...

What it should be is this:

  implicit val base64Format: Format[Array[Byte]] = (
      implicitly[Format[String]].inmap(s => Base64.decodeBase64(s), (bytes: Array[Byte]) => Base64.encodeBase64String(bytes))
  )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant