On Sat, Oct 17, 2009 at 7:54 AM, Joni Freeman <freeman.j...@gmail.com>wrote:

>
> I've been thinking this feature today a bit too. Marius raises an
> important point. Adding type information and more complex
> serialization scheme will introduce couplings, making it for instance
> more difficult to deserialize JSON using a different language or
> toolkit. On a positive side, we might get support for other
> parameterized types too (tuples for instance).
>
> I pushed an experimental branch (joni_issue_108) which contains
> serialization part of this feature (the easy part really). It adds
> 'jsonClass' field to objects.
>
>  case class Animals(animals: List[Animal])
>  trait Animal
>  case class Dog(name: String) extends Animal
>  case class Fish(weight: Double) extends Animal
>
>  scala> write(Animals(Dog("pluto") :: Fish(1.2) :: Dog("devil") ::
> Nil))
>  res0: String = {"jsonClass":"Animals","animals":
> [{"jsonClass":"Dog","name":"pluto"},{"jsonClass":"Fish","weight":1.2},
> {"jsonClass":"Dog","name":"devil"}]}
>
> Possible actions:
>
> * Do not support parameterized types (status quo)
>
>  + Simple scheme, easy to serialize in language agnostic way
>  - Limited
>

I like this option.  I'm not looking for a full Java serialization style
solution.  But having hints as to the type of the particular JSON object
would be helpful.  Being able to register a "jsonClass" -> Scala class
deserializer makes sense.  Being able to specify a Scala class -> class name
is a good thing (with the default being the actual class name without the
package).


>
> * Add full type information when serializing/deserializing
>
>  + Opens possibility to deserialize polymorphic types
>  + Deserialization can be done without any explicit type information
> (read(...) vs. read[ExpectedType](...))
>  - Introduces couplings
>  - This is still not a generic serialization solution, there's still
> a lot of Scala classes which can't be deserialized
>
> * Support both schemes
>
>  + Moar choice
>  - Choice it not necessarily a good thing (adds complexity etc.)
>
> Cheers Joni
>
> On 17 loka, 11:40, Marius <marius.dan...@gmail.com> wrote:
> > Hmmm ... I wonder if heterogeneous lists should be supported. I also
> > wonder if type knowledge in JSON is a good thing to do as it seems to
> > me that we're bringing knowledge from another domain creating
> > couplings. I'm not sure if there is a different way to solve this ...
> > it just doesn't feel completely right to me ... but this doesn't
> > necessarily mean it is not right :)
> >
> > Br's,
> > Marius
> >
> > On Oct 15, 1:47 am, David Pollak <feeder.of.the.be...@gmail.com>
> > wrote:
> >
> > > Folks,
> > > What are thoughts on including (perhaps optionally) the name of the
> case
> > > class in an additional JSON field so that one can reconstruct a list
> that
> > > contains many different types?
> >
> > > Thanks,
> >
> > > David
> >
> > > --
> > > Lift, the simply functional web frameworkhttp://liftweb.net
> > > Beginning Scalahttp://www.apress.com/book/view/1430219890
> > > Follow me:http://twitter.com/dpp
> > > Surf the harmonics
> >
>


-- 
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Surf the harmonics

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

Reply via email to