Bear Bibeault wrote:I'd say to simply define more members in the results class to match the JSON keys, but because you have keys such as "A-B" which aren't valid identifiers, that's a problem.
Why do you have these keys? Are they defined elsewhere, or do you have control over them?
Steve Dyke wrote:So should I change the results class from a string to list(array)?
Bear Bibeault wrote:
Steve Dyke wrote:So should I change the results class from a string to list(array)?
I really have no idea how you got to that from what I posted.
Once the keys are valid identifiers, you just need to add members to the class in addition to status to receive the other properties.
Naming things so that Gson can apply its automatic mapping rules is the easiest way to go. Gson allows you to create custom mappers, but you really don't want to go there unless you absolutely have to.
Bear Bibeault wrote:What do you mean by "return multiple values"?
Bear Bibeault wrote:From the toString() method? I'm not sure what that has to do with anything. Are you wanting toString() to return the JSON serialization of the class?
Steve Dyke wrote:It worked great for one single value but now I need to get several values.
Bear Bibeault wrote:
Steve Dyke wrote:It worked great for one single value but now I need to get several values.
From what? You still haven't explained that.
Bear Bibeault wrote:You may want to read the Gson documentation regarding returning a Map if the keys vary so much that you cannot capture the results in a bean.
Bear Bibeault wrote:Is that actually working? If so, you can get a list of the keys just like any other java.util.Map (⇐ see javadoc).
Consider Paul's rocket mass heater. |