-
Notifications
You must be signed in to change notification settings - Fork 115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ClassNotFoundException while deserializing Proxied objects #39
Comments
Likely the Proxy class is not what you want serialized. For example, if you were using Hibernate, that library proxies data model objects loaded from the database. It does this so it can intercept method calls and potentially fetch more of the object model graph upon access. In this example, you would not want the Proxy instances shipped to a front-end Android app. Instead, you would want to properly gather together the non-Proxied object model on the server, and send that to the client (using json-io). |
That's likely true, I doubt that we care to have the proxy data, however we are not in control of the objects that are being serialized. We just are just taking whatever comes through and trying to form it into something that we can pass through an IPC mechanism. Is there an easy way to ignore the Proxy objects? I looked into using a custom Writer that just wouldn't output anything for Proxies, but the problem is that I don't know how to match on the $Proxy1 class that java.lang.reflect.Proxy creates for these objects. Any idea how we could do this? |
Use an Class.isAssignableCheck(). Check it against java.lang.reflect.Proxy On Fri, May 22, 2015 at 9:05 AM, Kevin LaFlamme notifications@github.com
|
I understand how to check if the object is a Proxy, but how do I setup a custom Writer for any object that is proxied? I see how to set one up by adding the class to the writers map with JsonWriter.addWriter(), but I don't have a reference to the class object for $Proxy1, so is there a way to do this? |
Set one up for Object.class - I am pretty sure it supports inheritance. On Fri, May 22, 2015 at 9:34 AM, Kevin LaFlamme notifications@github.com
|
Couldn't find a way to do it with a custom writer, but we did find another way to remove the unnecessary Proxy stuff before the object gets passed to this library. Thanks so much for the quick responses. |
I'm using this library to serialize objects being passed between android applications. Since upgrading to Android 5, I'm now seeing a ClassNotFoundException when deserializing proxy objects. It makes sense that since the proxy object class is $Proxy1 it wouldn't be able to be instantiated by that name on the other side, but Proxy is a serializable class so there must be a way to do it.
Here is one example of a json payload that will cause the issue:
{
"@type":"android.os.Bundle",
"mAllowFds":true,
"mFdsKnown":true,
"mHasFds":false,
"mClassLoader":{
"@type":"java.lang.BootClassLoader",
"packages":{
"@type":"java.util.HashMap",
"com.android.org.conscrypt":{
"@type":"java.lang.Package",
"implTitle":"Unknown",
"implVendor":"Unknown",
"implVersion":"0.0",
"name":"com.android.org.conscrypt",
"sealBase":null,
"specTitle":"Unknown",
"specVendor":"Unknown",
"specVersion":"0.0"
}
},
"parent":null,
"proxyCache":{
"@type":"java.util.HashMap",
"@keys":[
{
"@type":"java.util.ArrayList",
"@Items":[
{
"@type":"class",
"value":"android.content.IContentProvider"
}
]
}
],
"@Items":[
{
"@type":"class",
"value":"$Proxy1"
}
]
}
},
"mMap":{
"invalidReason":"",
"areSecuritySettingsValid":true
},
"mParcelledData":null
}
The text was updated successfully, but these errors were encountered: