Felipe Diogo
Felipe Diogo

Reputation: 307

dynamic notation serializedname

I have several services that return three fields (json). FailureMessage (string, in case something wrong happens) Success (boolean) [Custom] (object of return) Examples below:

1)

{
    "FailureMessage": "",
    "Success": true,
    "Cities": []
}

2)

{
    "FailureMessage": "",
    "Success": true,
    "Regions": []
}

Is there a way to map then in a generic way?

Now, I have the first 2 properties mapped to a GenericResponse, and other classes extending GenericResponse and creating the third attribute in each one.

Thanks in advance

Upvotes: 0

Views: 3260

Answers (1)

Jonas Köritz
Jonas Köritz

Reputation: 2644

This should be usable as a solution to your problem.

You will have to provide gson with a method of parsing your specific structure.

Upvotes: 3

Related Questions