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

Value class does not deserialize json #58

Closed
searler opened this issue Aug 24, 2016 · 5 comments
Closed

Value class does not deserialize json #58

searler opened this issue Aug 24, 2016 · 5 comments

Comments

@searler
Copy link

searler commented Aug 24, 2016

Thank you for implementing #50

Unfortunately there appears to be a defect in AvroInputStream for both binary and json

package com.sksamuel.avro4s.examples


import com.sksamuel.avro4s.AvroSchema
import org.scalatest.{Matchers, WordSpec}

case class Wrapper(val underlying: Int) extends AnyVal
case class Test(i:Int,w:Wrapper)

class ValueClassExamples extends WordSpec with Matchers {
  import java.io.{ByteArrayInputStream, ByteArrayOutputStream}
  import com.sksamuel.avro4s.{AvroInputStream, AvroOutputStream}

  "AvroStream json serialization" should {

    "round trip the value class " in {
      val baos = new ByteArrayOutputStream()
      val output = AvroOutputStream.json[Test](baos)
      output.write(Test(2,Wrapper(10)))
      output.close()

      val json = baos.toString("UTF-8")

      json shouldBe ("""{"i":2,"w":10}""") // as expected

      val in = new ByteArrayInputStream(json.getBytes("UTF-8"))
      val input = AvroInputStream.json[Test](in) //  <=== fails
      val result = input.iterator.toSeq
      result shouldBe Vector("")
    }
  }

}

The stack trace is

10 (of class java.lang.Integer)
scala.MatchError: 10 (of class java.lang.Integer)
    at com.sksamuel.avro4s.LowPriorityFromValue$$anon$1.apply(FromRecord.scala:22)
@sksamuel
Copy link
Owner

Is this a new test case you'd like me to add, and then get working?

@sksamuel
Copy link
Owner

I've got all it working now, new tests for binary / json value classes

@sksamuel
Copy link
Owner

sksamuel commented Aug 24, 2016

d7ceecf

@sksamuel
Copy link
Owner

I'll release this and coproducts as 1.6.0

@searler
Copy link
Author

searler commented Aug 24, 2016

Confirmed my tests pass

Thank you

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

2 participants