JsonMappingException try trying to use jacks test methods #15

Open
simbo1905 opened this Issue Sep 1, 2013 · 0 comments

Projects

None yet

1 participant

@simbo1905

(My apologies if this is just a simple mistake on my part as I am new to scala)

I checkout and build jacks and added two of my own classes into the file test.scala:

abstract class Message
case class CardDrawn(player: Long, card: Int, mType: String = "CardDrawn") extends Message
case class CardSet(cards: List[CardDrawn], mType: String = "CardSet") extends Message

And then added in a test to check that they roundtrip fine.

test("cardset works"){
    rw(CardSet(List(CardDrawn(1L,2),CardDrawn(3L,4)))) should equal (CardSet(List(CardDrawn(1L,2),CardDrawn(3L,4))))

    val cs = CardSet(List(CardDrawn(1L,2),CardDrawn(3L,4)))
    val json = write(cs)
    val obj = read(json)
    cs should equal (obj)
  }

The firs call to "rw()" works suggesting that all is very well indeed. The following lines where I try to explicitly to the read and write (the same operations as the rw call) gets an exception:

Can not instantiate abstract type [simple type, class scala.runtime.Nothing$] (need to add/enable type information?)
 at [Source: java.io.StringReader@76d26a; line: 1, column: 2]
com.fasterxml.jackson.databind.JsonMappingException: Can not instantiate abstract type [simple type, class scala.runtime.Nothing$] (need to add/enable type information?)
 at [Source: java.io.StringReader@76d26a; line: 1, column: 2]
    at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:164)
    at com.fasterxml.jackson.databind.deser.std.ThrowableDeserializer.deserializeFromObject(ThrowableDeserializer.java:77)
    at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:121)
    at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:2888)
    at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2048)
    at com.lambdaworks.jacks.JacksMapper$class.readValue(jacks.scala:20)
    at com.lambdaworks.jacks.JacksMapper$.readValue(jacks.scala:40)
    at com.lambdaworks.jacks.JacksTestSuite$class.read(test.scala:287)
    at com.lambdaworks.jacks.CaseClassSuite.read(test.scala:91)

Whats the correct way to roundtrip such a structured class and is there something wrong with the rw method which is masking an issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment