Hi all,
I tested (just for the fun) VC+type info JSonization in
SerializableType like this :
public void toJSON( Object value, JSONWriter json ) throws
JSONException
{
...
else if( value instanceof ValueComposite )
{
// Serialize ValueComposite JSON instead
final InvocationHandler invocationHandler =
Proxy.getInvocationHandler(value);
CompositeInstance instance = (CompositeInstance)
invocationHandler;
ValueDescriptor descriptor = (ValueDescriptor)
instance.descriptor();
ValueType valueType = descriptor.valueType();
try
{
json.object();
json.key("type");
json.value(valueType.type().name());
json.key("content");
valueType.toJSON( value, json );
json.endObject();
} catch (JSONException e)
{
throw new IllegalStateException("Could not JSON
serialize value", e);
}
return;
}
...
}
public Object fromJSON( Object json, Module module ) throws
JSONException
{
try
{
if (json instanceof JSONObject)
{
// ValueComposite deserialization
String jsonType = ((JSONObject) json).getString("type");
ValueDescriptor valueDescriptor = ((ModuleSPI)
module).valueDescriptor(jsonType);
return valueDescriptor.valueType().fromJSON
(((JSONObject) json).getJSONObject("content"), module);
} else
{
...
}
And it works quite well BUT I spent the last 3 hours on what seems to
be a bug.
I have a VC with a side-effect.
This side-effect creates an entity with a property containing this
same VC.
After the side effect, I apply() the changes... and guess what, the
property containing the VC references a
ProxyReferenceInvocationHandler, the same that was used during the
MethodSideEffectsInstance.invokeSideEffects call :
private void invokeSideEffects( Object proxy, Method method,
Object[] params, Object result, Throwable throwable )
throws Throwable
{
proxyHandler.setProxy( proxy );
resultInvocationHandler.setResult( result, throwable );
try
{
for( InvocationHandler sideEffect : sideEffects )
{
invokeSideEffect( proxy, method, params, throwable,
sideEffect );
}
}
finally
{
----->>>>>>>> proxyHandler.clearProxy();
resultInvocationHandler.setResult( null, null );
}
}
So instead of a value instance I get a proxy to ... null, since it was
cleared in proxyHandler.clearProxy().
And I cannot JSonize a proxy a null ValueComposite... Is this an
isolated problem ?
What did I miss ?
Phil
_______________________________________________
qi4j-dev mailing list
[email protected]
http://lists.ops4j.org/mailman/listinfo/qi4j-dev