-
> You mentioned classloader problems earlier, but now it seems your complaint is object complexity and not wanting to use the path mechanisms provided to specify your class types.
I mentioned both class loading issues AND using the additional features ClassLocator provides, see message 8 of this thread.
My "complaint" is that ClassLocator doesn't work well with arrays.
> You mention...
2009-12-10 17:52:58 UTC in Flexjson
-
In your case it would be as easy as:
new JSONDeserializer().use( "values", Foo.class ).deserialize( json );
Duh. Of course it wouldn't. Foo is just an example I made up, in a real life I have a complex tree with different types of leafs.
> But you admitted just above you aren't sure you even need this.
I don't need ClassLocator to provide different kind of arrays, but I need Clas.
2009-12-10 16:43:49 UTC in Flexjson
-
> How do this not fix your problem?
ClassLocator still can't be used with arrays.
> Or how does this "complicate things unnecessarily"?
Using a universal ClassLocator with "use (null, cl)" is simpler then trying to match paths for various JSON strings.
2009-12-10 16:28:05 UTC in Flexjson
-
I *can* use this and that to *workaround* the problem of using ClassLocator with arrays, but it will complicate things unnecessarily and doesn't fix the present issue.
2009-12-10 15:58:13 UTC in Flexjson
-
"use (null, cl)" enables ClassLocator for the whole hierarchy of objects present in the JSON string. We might not need the ClassLocator for arrays specifically, but we might very well need it for other objects located therein.
For example, my current ClassLocator contains this additional string:
if (map.containsKey ("actLevStart")) classOf[DenormalizedRating]
From that point of...
2009-12-10 15:32:31 UTC in Flexjson
-
The problem is handling arrays with ClassLocator.
Here is an example ClassLocator:
def cl = new flexjson.ClassLocator {
val classLoader = Thread.currentThread.getContextClassLoader
override def locate (map: java.util.Map[_,_], path: flexjson.Path): Class[_] = {
val clazz = map.get ("class") // Flexjson class signature.
if (clazz.isInstanceOf[String]...
2009-12-10 15:06:59 UTC in Flexjson
-
Thanks! I've tried the deserialization in the new version and it now works as expected!
I'm still using the ClassLocator in my real code though, because I'm not sure about the class-loaded issues (I use Thread.currentThread.getContextClassLoader to obtain the ClassLoader, and I suspect Flexjson uses the default ClassLoader which usually doesn't work for Servlet Containers) and using it allows...
2009-12-10 14:43:59 UTC in Flexjson
-
> The rule of thumb of using Map
> whenever nothing is specified for a
> path is a good one, but you'd still
> need to specify Foo either in a use()
> or ClassLocators.
That's right. And also using the "class" field emitted by the Serializer.
2009-11-04 16:12:41 UTC in Flexjson
-
Charlie, have you missed the two problems I mention?
1) There is {\"class\":\"Foo\"} in the JSON string, however, I see no way to deserialize it into Foo using default Deserializer.
2) ClassLocator have no way to differentiate maps from arrays.
> So the idiomatic solution you proposed
> doesn't tell the deserializer what
> classes it's binding into.
Wrong...
2009-11-04 16:01:56 UTC in Flexjson
-
I solved it for now by using a ClassLocator, see
http://www.gulic.org/pastebin/77
- however it only works with maps and breaks with arrays.
2009-11-01 02:29:04 UTC in Flexjson