2009-12-10 17:13:07 UTC
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.
Remember these path changes extend to ClassLocators as well. You don't have to register on the null anymore. For example,
new JSONDeserizlier().use( "values", cl ).deserialize( json );
Why is it important that you use a ClassLocator rather than a simple class? 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'm not sure how you're using ClassLocator to overcome these in a easier way. If you can enlighten me then we can talk about changes.
There's one thing in your post that makes me wonder if we're not on the same page here. You mention registering a null ClassLocator as "Universal", which makes we think you believe this ClassLocator extends to the entire graph. While you might be able to see the entire graph, i.e by digging through that map object, the return type only allows one Class. And this ClassLocator isn't called for lower levels. It's only registered at that top level. It will not be used to resolve classes at lower levels.
That's why I'm not too worried about how complex your objects below the [ { "foo": "bar" } ] are because this ClassLocator doesn't factor into those complexities.
In the example ClassLocator you provided I don't see it dealing with anything below the array's members. It looked like it was just to handle the class loader issues. So, I'm not sure why you want to register the loader on the null instead of "values".
for a string [{"foo": "bar"}] I would expect JSONDeserializer to decide the "[]" automagically, but pass the {} part to ClassLocator to decide.
That might be possible, but I pause only because it's an exception to the rule. I'll have to give this careful consideration. I know now it's a design flaw, but I'm going to weigh that against future changes to see if that's a quick fix vs something more long term.
Thanks,
Charlie