Git Product home page Git Product logo

jacks's People

Contributors

wg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jacks's Issues

Missing ScalaTypeSig type mapping (scala.Any)

The ScalaTypeSig object has no mapping for the "Scala.Any" type.
For instance when a Map[String,Any] is used in a case class, an exception is thrown during deserizalization:
Exception in thread "main" java.lang.ClassNotFoundException: scala.Any
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at com.lambdaworks.jacks.ScalaTypeSig$.findClass(module.scala:326)

I think the following mapping should be added:
"scala.Any" -> classOf[Any],

@JsonProperty set on case classes methods is ignored

The serialization of case classes includes only fields declared in the primary constructor
However it is sometimes interesting to add some extra fields (that could be used by the JsonCreator in the deserialization phase) in the resulting JSON string.

One solution to do that with Jackson is to add the @JsonProperty annotation on the method one want to serialiaze the result (see http://stackoverflow.com/questions/14362247/jackson-adding-extra-fields-to-an-object-in-serialization).

But it seems it is not supported by the current implementation of Jacks.

Serializing case classes defined in Scala REPL doesn't work

Jacks 2.1.4, 2.1.2, reproducible with both Scala 2.9.2 and 2.10

scala> case class MySchema(bigBucketSecs: Int, groupingField: String, timeWindowIndexes: String)
defined class MySchema

scala> JacksMapper.writeValueAsString(MySchema(864,"guid","300"))
res5: java.lang.String = {}

scala> JacksMapper.readValue[MySchema]("{}")
com.fasterxml.jackson.databind.JsonMappingException: No suitable constructor found for type [simple type, class MySchema]: can not instantiate from JSON object (need to add/enable type information?)
 at [Source: java.io.StringReader@66c17c; line: 1, column: 2]
    at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:164)
    at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObjectUsingNonDefault(BeanDeserializer.java:400)
    at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:289)
    at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:121)
    at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:2793)
    at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:1957)

However, the unit tests in Jacks themselves clearly run, and it seems the serialization works for classes actually defined in code, which I bring into the REPL via "sbt console".
Strange.

Not work on simple example

Result of this code is empty.

import com.lambdaworks.jacks.JacksMapper

class First (val num: Int, val str: String) {}
class Second (val firstClass: First, val num: Int, val str: String) {}
class Third (val firstClass: First, val secondClass: Second, val num: Int, val str: String) {}

object Program extends App{
    val first = new First(1, "first")
    val second = new Second(first, 11, "second")
    val third = new Third(first, second, 111, "third")

    println(JacksMapper.writeValueAsString(third))
}

@JsonSnakeCase annotation

Is there a way to automatically "snake case" field names as the @JsonSnakeCase annotation does in the jerkson library ?

JsonMappingException try trying to use jacks test methods

(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?

Case classes with companions are not always recognized

Case classes with companion objects are sometimes not recognized by Jacks. It seems that the problem is in ScalaTypeSig.cls computation โ€” it selects the first available ClassSymbol, but the first one is something synthetic generated by a companion object. Here is a list of class symbols I have:

[info] ClassSymbol(CaseClass, owner=com.my.package, flags=400, info=25 ,None)
[info] ClassSymbol(CaseClass, owner=com.my.package, flags=40, info=43 ,None)

I use scala 2.10.4, jacks 2.3.3.

ScalaSig parse results not cached

It turned out that ScalaSig parsing takes too long time, and because of per-serializer context creation class is being parsed each time message processed. Is there any reasons for not caching ScalaSig results?

JsonProperty ignored in case class even for a constructor field

I have case class like this:

case class Parameter(val name:String, val value:String, @(JsonProperty@field)("type") val aType:String, val restriction:String, val defaultValue:String, val required:Boolean, val description:String)

The output Json should have a 'type' field which is a keyword in Scala. hence, I use @JsonProperty to convert it to 'type' field.

Running this line of code:

val p = Parameter("name", "value", "string", "restricted", "myDefault", true, "desc")
println(JacksMapper.writeValueAsString(p))

prints:

{"name":"name","value":"value","aType":"string","restriction":"restricted","defaultValue":"myDefault","required":true,"description":"desc"}

Looks like the @JsonProperty is ignored.

Is this a bug?

Play Framework 2.1 compatiblity

Trying to convert a simple case class structure to Json:
jsonResponse: String = writeValueAsString(ListView(myList))
I get a ClassNotFoundException model.Item a class in the model package

Perhaps it's similar to the issue mentioned here, the exception seems the same. They fixed it by using a more dynamic way of class loading (I think)
sorm/sorm#10

In its current state the library is unusable in Play 2.1 for me.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.