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

Custom key mappings get NPE error #2067

Open
imperio-wxm opened this issue Dec 8, 2022 · 0 comments
Open

Custom key mappings get NPE error #2067

imperio-wxm opened this issue Dec 8, 2022 · 0 comments

Comments

@imperio-wxm
Copy link

circe-core veresion: 2.12_0.14.1

case class AIRequest(requestId: String, height: Int, width: Int, inputs: List[InputData])
case class InputData(base64Array: String, dataType: String, shape: List[Int], layout: String)

implicit val requestBar: Encoder[AIRequest] = 
    Encoder.forProduct4("id", "width", "height", "inputs")(b => (b.requestId, b.width, b.height, b.inputs))
implicit val dataEncoder: Encoder[InputData] = 
    Encoder.forProduct4("array", "dtype", "shape", "layout")(b => (b.base64Array, b.dataType, b.shape, b.layout))

describe("json test") {
  it("bean to json") {
    val inputData = InputData("aaa", "uint8", List(3, 256, 256), "test")
    val aIRequest = AIRequest("bbb", 256, 256, List(inputData))
    println(aIRequest.asJson.noSpaces)
  }
}

Error:

java.lang.NullPointerException was thrown.
java.lang.NullPointerException
	at io.circe.MidPriorityEncoders$IterableAsArrayEncoder.encodeArray(Encoder.scala:919)
	at io.circe.Encoder$AsArray.apply(Encoder.scala:744)
	at io.circe.Encoder$AsArray.apply$(Encoder.scala:744)
	at io.circe.MidPriorityEncoders$IterableAsArrayEncoder.apply(Encoder.scala:911)
	at io.circe.ProductEncoders$$anon$4.encodeObject(ProductEncoders.scala:50)
	at io.circe.Encoder$AsObject.apply(Encoder.scala:824)
	at io.circe.Encoder$AsObject.apply$(Encoder.scala:824)
	at io.circe.ProductEncoders$$anon$4.apply(ProductEncoders.scala:47)
	at io.circe.syntax.package$EncoderOps$.asJson$extension(package.scala:8)
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