-
1. Re: ClassCastException: java.util.HashMap cannot be cast to mypackage.MyLinkedHashMap
jfuerth Aug 29, 2012 12:36 PM (in response to navigateur)Unfortunately, this is the way the aliasing facility works in Errai Marshalling: "aliases do not inherit functionality."
The Map marshaller always produces an instance of HashMap when it's demarshalling. Since you have aliased MyLinkedHashMap to Map, you will always get back a HashMap when demarshalling. Not what you want, I know.
If you can do away with the custom subclass, that would be easiest. Errai Marshalling preserves map ordering for field types java.util.LinkedHashMap and java.util.SortedMap.
Otherwise, you will have to create a custom marshaller for MyLinkedHashMap. It's not so bad, because you can extend MapMarshaller. Use LinkedMapMarshaller as your guide:
Hope that helps,
Jonathan
-
2. Re: ClassCastException: java.util.HashMap cannot be cast to mypackage.MyLinkedHashMap
navigateur Sep 9, 2012 11:01 AM (in response to jfuerth)I'll try that out.
Are there any plans to make this unnecessary? I like subclassing as I've other related functionality & variables. And there are quite a few so I'd have to bloat my code a tiny bit, maybe, with a custom marshaller for each, right? Ideally I'd just be able to do @Portable class MyLinkedHashSet extends LinkedHashSet but I don't know if that'll ever be possible.
-
3. Re: ClassCastException: java.util.HashMap cannot be cast to mypackage.MyLinkedHashMap
navigateur Jan 12, 2014 3:06 PM (in response to jfuerth)Hi, subclassing MapMarshaller wasn't possible for my custom LinkedHashMap since MapMarshaller is type-bound to a Map<Object, Object>, and my custom one had specified key & value types. Otherwise, where would I need to place the custom marshaller to make it work? Anywhere in my project? Has errai been updated to allow direct marshalling of subclasses of LinkedHashMap since I first asked this?