Int/Str/List/Map... thay are no @Serializable facet. How to determine whether a type can be serialized.
rosarinjroyMon 25 Oct 2010
You can use type literal to get the Type object and then examine if the type has Serializable facet, like: echo(Int#.facets)
The output will look like: [sys::Serializable { simple=true collection=false }]
To specifically examine if the type has Serializable facet or not, you can use hasFacet method, like: echo("Serializable? " + Int#.hasFacet(Serializable#))
Most of the standard Fantom literals such as Bool, Int, Str are supported as well as the collections types List and Map.
So I presume that at the language level there is support for serialization of List and Map, by checking the provided object.
Still it would be nice to have the facets on List and Map so that anyone programmatically check if an object is serializable doesn't have to have any special code to handle these.
brianMon 25 Oct 2010
All the primitives, list, and map are handled specially by the encoder - so marking them as Serializable is just convention really. It was just an oversight that List and Map weren't marked correctly. I pushed a fix for that problem.
rosarinjroyTue 26 Oct 2010
Wow. Brian: I am new to the Fantom community and that was one of my first suggestions. Thanks a lot for the blazing fast fix.
go4 Sun 24 Oct 2010
Int/Str/List/Map... thay are no @Serializable facet. How to determine whether a type can be serialized.
rosarinjroy Mon 25 Oct 2010
You can use type literal to get the Type object and then examine if the type has Serializable facet, like:
echo(Int#.facets)
The output will look like:
[sys::Serializable { simple=true collection=false }]
To specifically examine if the type has Serializable facet or not, you can use hasFacet method, like:
echo("Serializable? " + Int#.hasFacet(Serializable#))
The output will look like:
Serializable? true
Hope that helps.
go4 Mon 25 Oct 2010
Yes,the Int has Serializable facet.but:
rosarinjroy Mon 25 Oct 2010
I didn't realize that. Except that this is what the Serialization documentation says:
So I presume that at the language level there is support for serialization of List and Map, by checking the provided object.
Still it would be nice to have the facets on List and Map so that anyone programmatically check if an object is serializable doesn't have to have any special code to handle these.
brian Mon 25 Oct 2010
All the primitives, list, and map are handled specially by the encoder - so marking them as Serializable is just convention really. It was just an oversight that List and Map weren't marked correctly. I pushed a fix for that problem.
rosarinjroy Tue 26 Oct 2010
Wow. Brian: I am new to the Fantom community and that was one of my first suggestions. Thanks a lot for the blazing fast fix.