scala / pickling

Fast, customizable, boilerplate-free pickling support for Scala
lampwww.epfl.ch/~hmiller/pickling
BSD 3-Clause "New" or "Revised" License
831 stars 79 forks source link

Check if a FastTypeTag is a collection #344

Open filosganga opened 9 years ago

filosganga commented 9 years ago

Hi, I am working on a more natural Json serialization format. I need to know if a given FastTypeTag is subclass of specific class/trait (Like scala.Seq). Is it possible to do with FastTypeTag? Is it possible to make it static?

Thanks

jsuereth commented 9 years ago

What do you mean make it static?

Also, if it helps, sbt has a JSON serialization format that we quite like, based on the JAWN parser and json4s. Feel free to take a look/use for guidance: https://github.com/sbt/serialization

jsuereth commented 9 years ago

Oh, also to help answer the question about whether you can staticall know if something is a scala.Seq, the answer is "only from one half".

The FastTypeTag is something that is serialized. It's meant to act as a hash, of sorts, for the type. We use a full string here, but you could imagine instead using a number. THe idea is that when we serialize a known type over the wire, we can get this tag on the other side, where we don't know what it is.

SO, if you want any kind of "subclass" information, that means you're now in the realm of runtime reflection.

I'd recommend just avoiding that completely and using the build in notion of collection on PBuilder for ALL collection types, where FastTypeTag an just be used to grab the appropriate builder on the other side.

filosganga commented 9 years ago

Hi Josh, I see now, thanks for the help.

On 28 July 2015 at 14:03, Josh Suereth notifications@github.com wrote:

Oh, also to help answer the question about whether you can staticall know if something is a scala.Seq, the answer is "only from one half".

The FastTypeTag is something that is serialized. It's meant to act as a hash, of sorts, for the type. We use a full string here, but you could imagine instead using a number. THe idea is that when we serialize a known type over the wire, we can get this tag on the other side, where we don't know what it is.

SO, if you want any kind of "subclass" information, that means you're now in the realm of runtime reflection.

I'd recommend just avoiding that completely and using the build in notion of collection on PBuilder for ALL collection types, where FastTypeTag an just be used to grab the appropriate builder on the other side.

— Reply to this email directly or view it on GitHub https://github.com/scala/pickling/issues/344#issuecomment-125599408.

[image: --] Filippo De Luca [image: http://]about.me/FilippoDeLuca http://about.me/FilippoDeLuca?promo=email_sig