Skip to content
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

Closed
lamflam opened this issue May 21, 2015 · 6 comments
Closed

ClassNotFoundException while deserializing Proxied objects #39

lamflam opened this issue May 21, 2015 · 6 comments
Labels

Comments

@lamflam
Copy link

lamflam commented May 21, 2015

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
}

@jdereg
Copy link
Owner

jdereg commented May 22, 2015

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).

@lamflam
Copy link
Author

lamflam commented May 22, 2015

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?

@jdereg
Copy link
Owner

jdereg commented May 22, 2015

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
wrote:

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?


Reply to this email directly or view it on GitHub
#39 (comment).

@lamflam
Copy link
Author

lamflam commented May 22, 2015

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?

@jdereg
Copy link
Owner

jdereg commented May 22, 2015

Set one up for Object.class - I am pretty sure it supports inheritance.
This CustomWriter would be called for all classes if associated to
Object.class. Give it a try.

On Fri, May 22, 2015 at 9:34 AM, Kevin LaFlamme notifications@github.com
wrote:

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?


Reply to this email directly or view it on GitHub
#39 (comment).

@lamflam
Copy link
Author

lamflam commented May 22, 2015

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants