You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to define a model with an array of models inside it with the Android SDK and I'm struggling with a casting problem from HashMap to my model.
Let's take for example a model called Feed that contains an array of Posts (which is a model also) and a link to the next page (a simple string).
When I try to get a Feed object with a custom static method using the JsonObjectParser, it throws an exception that it can't cast HashMap to Post.
Right now, the only solution I came up with is to overload the setter of Posts with ArrayList<HasMap<String, ? extends Object>> as a parameter instead of ArrayList<Post>.
Until the feature gets added, I've found the potential temporary workaround. I haven't thoroughly tested it yet, but it seems to get me at least part of the way there:
By calling the repository createObject method it calls the same method stack used to initialize your model objects. For the first example I'm referencing a different type so I need to get an adapter (reusing the current repository's so don't use it to make additional API calls) and repository for that model type. For the list example I'm creating a recursive list of the same type as the parent model so I can just use its repository instance.
Activity
bajtos commentedon Jan 13, 2015
We should hopefully get this for free once we replace our hand-written JSON parser with a proper library supporting custom annotations - see #61.
firaskafri commentedon Dec 2, 2015
Any updates on this?
techscientist commentedon Dec 30, 2015
Any updates on this? this would be a crucial feature for many apps
jamesw6811 commentedon Jan 16, 2016
+1 -- This is absolutely essential to our use-case.
azubieta commentedon Apr 20, 2016
Any updates on this topic ? It's there another way of doing the same ?
jjhesk commentedon Jul 20, 2016
+1 when is this done?!!!!
Using gson ( "com.google.code.gson:gson:2.6.2") and it has done it.. Please let me know thxx
JoshDavisMP commentedon Jan 31, 2017
Until the feature gets added, I've found the potential temporary workaround. I haven't thoroughly tested it yet, but it seems to get me at least part of the way there:
By calling the repository
createObjectmethod it calls the same method stack used to initialize your model objects. For the first example I'm referencing a different type so I need to get an adapter (reusing the current repository's so don't use it to make additional API calls) and repository for that model type. For the list example I'm creating a recursive list of the same type as the parent model so I can just use its repository instance.