Class cast exception encountered with manually mapped nested classes
pnakaska Jan 5, 2015 5:53 PMEncountering a ClassCastException when Deserializing an external class (Facet) from a Donor project.
The Donor project provides a (nested) class that needs to be marshalled between client and server.
The donor project 'Provider' defines a 'Facet' class.
The nested Facet class (nested within the SearchResult class) is returned by the search service (SearchService.search()), and the
client is attempting to deserialize the nested Facet class, but hitting a class cast exception.
The test project 'erraiexample' includes configuration to manually add the external classes from 'Provider' project.
(mapped through resources/com/kdm/provider/Searchprovider.gwt.xml)
The classes that have to be added cannot be marked @Portable, so instead they are made Serializable and have default constructors.
When the default page is loaded. the ErraiExampleApp.init() calls a server side search service and receives a response in a ResponseCallback.
The ResponseCallback uses MarshallingWrapper.fromJSON() to create the local unmarshalled object. (we have RestClient.setJacksonMarshallingActive(true))
this part is successful, and referencing other nested classes in the SearchResult works fine, such as for the 'Detail' class, and geoShape (Geoshape uses a custom Marshaller successfully).
However when trying to reference the ArrayList<Facet> entries list, (via iterator) a ClassCastException is encountered.
Below is the browser console output of the ResponseCallback, Facets:1 is just before the CCE. This shows successful receipt of the Detail instance, and the failure of the Facet creation.
...
15:20:43 INFO [ErraiExampleApp] searchResultCallback: de-marshalled! ConsoleLogHandler.java:77
15:20:43 INFO [ErraiExampleApp] searchResultCallback: detail.value:'hello111 GET' ConsoleLogHandler.java:77
15:20:43 INFO [ErraiExampleApp] searchResultCallback: detail.value:'hello222 GET' ConsoleLogHandler.java:77
15:20:43 INFO [ErraiExampleApp] searchResultCallback: numGeometries=1 ConsoleLogHandler.java:77
15:20:43 INFO [ErraiExampleApp] searchResultCallback: about to reference Facets: ConsoleLogHandler.java:77
15:20:43 INFO [ErraiExampleApp] searchResultCallback: Facets:1 ConsoleLogHandler.java:77
15:20:49 SEVERE [LogConfiguration] null
...
Attached are the Donor project 'Provider' and the test project 'ErraiExample'
-
provider.tar.gz 21.8 KB
-
erraiexample.tar.gz 31.5 KB