-
Notifications
You must be signed in to change notification settings - Fork 440
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
Issues deserializing scala collections #38
Comments
getGenericReturnType type returns: List vs.: List so getReturnType() can’t be used. -- On August 20, 2014 at 7:26:57 PM, stuz5000 ([email protected]) wrote: I'm providing a scala-aware mapper to JSON RPC but finding that its impossible to deserialize return values (via JsonRpcHttpClient) if method returns scala collection types. I've checked and found that the same mapper object can deserialize JSON into the same scala list type. So... I did some digging and found that using method.getReturnType() as the type parameter to mapper instead of method.getGenericReturnType() Seems to solve this issue. i.e. use ProxyUtil::createClientProxy() ... JsonRpcClient::readResponse() ... instead of ProxyUtil::createClientProxy() ... Is there any reason to prefer using getGenericReturnType? Or can a pull request be submitted to replace Type with Class<?> wherever return types are used? NB. I thought I could fix this by simply providing my own client proxy to use method.getReturnType() (which returns a class). However, although there's a JsonRpcClient::invoke method that takes a Class<?>, this is downcast to a Type, and, I think, by then its not possible to get mapper to instantiate the scala collection class using either: mapper.readValue(returnJsonParser, ); mapper.readValue(returnJsonParser, ); :( So... better to pass around Class than Type. Any reason not to? — |
Hmmm... if I do:
the above successfully deserializes a List[User] from a method.getReturnType(). Though if print...
it seems somehow that
carries all the required information. |
Ahh... looks like you were right. In this case, the mapper successfully returns a List[User], but the User object data are actual Map objects -- thanks to type erasure.... :( |
NB. I'm still blocked on deserializing scala Lists though, even though my ObjectMapper supports this. Here is the real culprit. In creatClientProxy, I believe
ignores the supplied ObjectMapper. See the discussion here: FasterXML/jackson-module-scala#107 Should prefer to call:
|
I'm providing a scala-aware mapper to JSON RPC but finding that its impossible to deserialize return values (via JsonRpcHttpClient) if method returns scala collection types. I've checked and found that the same mapper object can deserialize JSON into the same scala list type.
So... I did some digging and found that using
as the type parameter to mapper instead of
Seems to solve this issue. i.e. use
instead of
Is there any reason to prefer using getGenericReturnType? Or can a pull request be submitted to replace Type with Class<?> wherever return types are used?
NB. I thought I could fix this by simply providing my own client proxy to use method.getReturnType() (which returns a class). However, although there's a JsonRpcClient::invoke method that takes a Class<?>, this is downcast to a Type, and, I think, by then its not possible to get mapper to instantiate the scala collection class using either:
mapper.readValue(returnJsonParser, );
mapper.readValue(returnJsonParser, <Class[] >);
:( So... better to pass around Class than Type. Any reason not to?
The text was updated successfully, but these errors were encountered: