serialization docs out of date for JSON format

39 views
Skip to first unread message

Eckart Hertzler

unread,
Feb 16, 2010, 11:52:02 AM2/16/10
to akka...@googlegroups.com
hmm...

while playing with wicket and akka (and cassandra), I noticed that the serialization doc is somewhat out of date.

the docs (http://doc.akkasource.org/serialization) tell me that:
------------------------------------------------------------------------
If you are sending messages to a remote Actor/Active Object and these messages are implementing one of the predefined interfaces/traits in the 'se.scalablesolutions.akka.serialization.Serialization.*' object, then Akka will transparently detect which serialization format it should use as wire protocol and will automatically serialize and deserialize the message according to this protocol.

Each serialization interface/trait in

* se.scalablesolutions.akka.serialization.Serialization.*
has a matching serializer in
* se.scalablesolutions.akka.serialization.Serializer.*.
------------------------------------------------------------------------

But It seems that se.scalablesolutions.akka.serialization.Serialization.* is no more...
------------------------------------------------------------------------
scala> import se.scalablesolutions.akka.serialization.Serialization._
<console>:4: error: value Serialization is not a member of package se.scalablesolutions.akka.serialization
import se.scalablesolutions.akka.serialization.Serialization._
^

scala> import se.scalablesolutions.akka.serialization.Serializer
import se.scalablesolutions.akka.serialization.Serializer
----------------------------------------------------------------------

Furthermore the example for JSON: Scala does not work:

-----------
scala> import se.scalablesolutions.akka.serialization.Serializable.ScalaJSON
import se.scalablesolutions.akka.serialization.Serializable.ScalaJSON

scala> case class MyMessage(val id: String, val value: Tuple2[String, Int]) extends ScalaJSON
defined class MyMessage

scala> val message = MyMessage("id", ("hello", 34))
message: MyMessage = MyMessage(id,(hello,34))

scala> val json = message.toJSON
java.lang.UnsupportedOperationException: Class class MyMessage not supported for conversion
at sjson.json.JsBean$class.toJSON(JsBean.scala:193)
at sjson.json.Serializer$SJSON$.toJSON(Serializer.scala:107)
at sjson.json.Serializer$SJSON$class.out(Serializer.scala:37)
at sjson.json.Serializer$SJSON$.out(Serializer.scala:107)
at se.scalablesolutions.akka.serialization.Serializable$S...
scala>
----------------
I can fix this by adding the @BeanInfo annotation.

but the deserialization in the second example yields this:

-----------------------------------------------
scala> @BeanInfo case class Foo()
defined class Foo

scala> val foo = new Foo()
foo: Foo = Foo()

scala> val json = Serializer.ScalaJSON.out(foo)
java.lang.UnsupportedOperationException: Class class Foo not supported for conversion
at sjson.json.JsBean$class.toJSON(JsBean.scala:193)
at sjson.json.Serializer$SJSON$.toJSON(Serializer.scala:107)
at sjson.json.Serializer$SJSON$class.out(Serializer.scala:37)
at sjson.json.Serializer$SJSON$.out(Serializer.scala:107)
at se.scalablesolutions.akka.serialization.Serializer$ScalaJSON...

-----------------------

ok, it seems the case class needs at least one attribute:

------------------------
scala> @BeanInfo case class Foo(name: String)
defined class Foo

scala> val foo = new Foo("foo")
foo: Foo = Foo(foo)

scala> val json = Serializer.ScalaJSON.out(foo)
json: Array[Byte] = Array(123, 34, 110, 97, 109, 101, 34, 58, 34, 102, 111, 111, 34, 125)

scala> val fooCopy = Serializer.ScalaJSON.in(json).asInstanceOf[Foo]
<console>:10: error: type mismatch;
found : Array[Byte]
required: String
val fooCopy = Serializer.ScalaJSON.in(json).asInstanceOf[Foo]
^
---------------------------
ok, so I give it a string.

But then...

--------------------------

scala> val fooCopy = Serializer.ScalaJSON.in(new String(json)).asInstanceOf[Foo]
java.lang.ClassCastException: dispatch.json.JsObject cannot be cast to Foo
at .<init>(<console>:10)
at .<clinit>(<console>)
at RequestResult$.<init>(<console>:3)
at RequestResult$.<clinit>(<console>)
at RequestResult$result(<console>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
...
scala>

-------------------------

Now, I could fix the sample code (in a way), but I don't know enough to fix the bit about the missing Serialization class.

- Eckart


Debasish Ghosh

unread,
Feb 16, 2010, 12:04:19 PM2/16/10
to akka...@googlegroups.com
Hi -

Regarding the JSON problem that you faced, could you pls try the current trunk version from Akka Github. I got the same problem reported sometime back and fixed it in the trunk.

Thanks.
- Debasish




--
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To post to this group, send email to akka...@googlegroups.com.
To unsubscribe from this group, send email to akka-user+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/akka-user?hl=en.




--
Debasish Ghosh
http://manning.com/ghosh

Twttr: @debasishg
Blog: http://debasishg.blogspot.com
Code: http://github.com/debasishg

Jonas Bonér

unread,
Feb 16, 2010, 12:30:58 PM2/16/10
to akka...@googlegroups.com
Thanks for the report. I'll fix the docs tomorrow. 

--
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To post to this group, send email to akka...@googlegroups.com.
To unsubscribe from this group, send email to akka-user+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/akka-user?hl=en.




--
Jonas Bonér

twitter: @jboner
blog:    http://jonasboner.com
work:   http://scalablesolutions.se
code:   http://github.com/jboner
code:   http://akkasource.org
also:    http://letitcrash.com




Eckart Hertzler

unread,
Feb 16, 2010, 12:41:37 PM2/16/10
to akka...@googlegroups.com
Am Dienstag, 16. Februar 2010 18:04:19 schrieb Debasish Ghosh:
> Hi -
>
> Regarding the JSON problem that you faced, could you pls try the current
> trunk version from Akka Github. I got the same problem reported sometime
> back and fixed it in the trunk.
>

That was the current trunk version. So, alas, the problem does not go away ...

Anyhow, I can see the problem in the source..

1. the Serialization class does not exist
2. sjson.json.Serializer.in does have a type parameter that returns a properly constructed Foo,
but se.scalablesolutions.akka.serialization.Serializer.ScalaJSON does not.

Otherwise its just minor inconsistencies in the documentation.

> > akka-user+...@googlegroups.com<akka-user%2Bunsu...@googlegroups.com>

Eckart Hertzler

unread,
Feb 16, 2010, 12:43:06 PM2/16/10
to akka...@googlegroups.com
Am Dienstag, 16. Februar 2010 18:30:58 schrieb Jonas Bonér:
> Thanks for the report. I'll fix the docs tomorrow.

no problem.

I can fix the sample code myself, if you like...

> > akka-user+...@googlegroups.com<akka-user%2Bunsu...@googlegroups.com>

Debasish Ghosh

unread,
Feb 16, 2010, 12:45:51 PM2/16/10
to akka...@googlegroups.com
Let me have a look tomorrow. I will fix the trunk. The last problem was reported on sjson serializer. Let me check the issue with Serialization class .. Thanks for reporting.

Thanks.
- Debasish

To unsubscribe from this group, send email to akka-user+...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/akka-user?hl=en.

Jonas Bonér

unread,
Feb 16, 2010, 2:34:08 PM2/16/10
to akka...@googlegroups.com
Please fix it thanks.

----
Jonas Bonér

Debasish Ghosh

unread,
Feb 17, 2010, 3:30:10 AM2/17/10
to akka...@googlegroups.com
I have fixed the issue with Serializer.scala in se.scalablesolutions.akka.serializer. I will check it in the master later today.

Also I need to fix a bug in sjson which I detected in de-serialization of Tuple2, which I plan to do later. Erasure is turning out to be a serious problem now. Plus deserializing from a narrower language (JSON) into one with a large range of types (Scala) is also creating lots of problems. And workarounds are not pleasing either.

Thanks.
- Debasish

sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)



--

Jonas Bonér

unread,
Feb 17, 2010, 3:53:49 AM2/17/10
to akka...@googlegroups.com
Thanks a lot Debasish. 

Eckhart, did you change the docs? 

Eckart Hertzler

unread,
Feb 17, 2010, 4:02:33 AM2/17/10
to akka...@googlegroups.com
Am Mittwoch, 17. Februar 2010 09:53:49 schrieb Jonas Bonér:
> Thanks a lot Debasish.
>
> Eckhart, did you change the docs?
>

Yep.

Just now.

> > Debasish Ghosh
> > http://manning.com/ghosh
> >
> > Twttr: @debasishg
> > Blog: http://debasishg.blogspot.com
> > Code: http://github.com/debasishg
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Akka User List" group.
> > To post to this group, send email to akka...@googlegroups.com.
> > To unsubscribe from this group, send email to

Eckart Hertzler

unread,
Feb 17, 2010, 4:03:06 AM2/17/10
to akka...@googlegroups.com
Am Mittwoch, 17. Februar 2010 09:30:10 schrieb Debasish Ghosh:
> I have fixed the issue with Serializer.scala in
> se.scalablesolutions.akka.serializer. I will check it in the master later
> today.
>

sounds good. I am looking forward to it.

Eckart

Jonas Bonér

unread,
Feb 17, 2010, 4:03:57 AM2/17/10
to akka...@googlegroups.com
Thanks Eckhart. 

To unsubscribe from this group, send email to akka-user+...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/akka-user?hl=en.




--

Eckart Hertzler

unread,
Feb 17, 2010, 4:06:31 AM2/17/10
to akka...@googlegroups.com
Am Mittwoch, 17. Februar 2010 10:03:57 schrieb Jonas Bonér:
> Thanks Eckhart.
>

my pleasure

:-)

> > <akka-user%2Bunsu...@googlegroups.com<akka-user%252Buns...@googlegroups.com>
> > >
> > > >>>>> <akka-user%2Bunsu...@googlegroups.com<akka-user%252Buns...@googlegroups.com>


> > >
> > > >>>>> .
> > > >>>>> For more options, visit this group at
> > > >>>>> http://groups.google.com/group/akka-user?hl=en.
> > > >>>>>
> > > >>>>>
> > > >>>>>
> > > >>>>
> > > >>>>
> > > >>>>
> > > >>> --
> > > >>> You received this message because you are subscribed to the Google
> > Groups
> > > >>> "Akka User List" group.
> > > >>> To post to this group, send email to akka...@googlegroups.com.
> > > >>> To unsubscribe from this group, send email to
> > > >>> akka-user+...@googlegroups.com<akka-user%2Bunsu...@googlegroups.com>

> > <akka-user%2Bunsu...@googlegroups.com<akka-user%252Buns...@googlegroups.com>


> > >
> > > >>> .
> > > >>> For more options, visit this group at
> > > >>> http://groups.google.com/group/akka-user?hl=en.
> > > >>>
> > > >>>
> > > >> --
> > > >> You received this message because you are subscribed to the Google
> > Groups
> > > >> "Akka User List" group.
> > > >> To post to this group, send email to akka...@googlegroups.com.
> > > >> To unsubscribe from this group, send email to
> > > >> akka-user+...@googlegroups.com<akka-user%2Bunsu...@googlegroups.com>

> > <akka-user%2Bunsu...@googlegroups.com<akka-user%252Buns...@googlegroups.com>


> > >
> > > >> .
> > > >> For more options, visit this group at
> > > >> http://groups.google.com/group/akka-user?hl=en.
> > > >>
> > > >>
> > > >
> > > >
> > > > --
> > > > Debasish Ghosh
> > > > http://manning.com/ghosh
> > > >
> > > > Twttr: @debasishg
> > > > Blog: http://debasishg.blogspot.com
> > > > Code: http://github.com/debasishg
> > > >
> > > > --
> > > > You received this message because you are subscribed to the Google
> > Groups
> > > > "Akka User List" group.
> > > > To post to this group, send email to akka...@googlegroups.com.
> > > > To unsubscribe from this group, send email to
> > > > akka-user+...@googlegroups.com<akka-user%2Bunsu...@googlegroups.com>

> > <akka-user%2Bunsu...@googlegroups.com<akka-user%252Buns...@googlegroups.com>

Reply all
Reply to author
Forward
0 new messages