Announcement Announcement Module
Collapse
No announcement yet.
JSON Serialization Question Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • JSON Serialization Question

    Hey folks,

    I am quite new Spring for Android. This may be a beginners question but I hope you can provide me some advice. I am using Spring in combination with RoboSpice to make my App able to process some rest requests. The technique I am currently using is POJO. Now that the JSON response of the server is quite "complex" I am wondering if there is a more elegant way to handle it.

    Currently my response on a (login) POST is either (the REST Api isn't made by myself) on a failure:
    {
    "status" : {
    "status" : -20,
    "pmsg" : "WRONG_PASSWORD",
    "msg" : "Wrong password: "
    }
    }
    or on success something like this
    {
    "status" : {
    "status" : 0
    },
    "data" : {
    "rights" : {
    "8" : "Admin"
    },
    "lastname" : "XXX",
    "company" : {
    "active" : boolean,
    "phone" : "XXX",
    "longitude" : "XXX",
    "fax" : "XXX",
    "street" : "XXX",
    "city" : "XXX",
    [...]
    },
    "firstname" : "XXX",
    "username" : "
    [..]
    }
    }
    Now on my approche (using POJO) I would make some classes (main-template,status,data,company...) and build a template for both results.

    Question:
    * There are now two different templates needed (Success & Failure). How can I achieve this as I am using something like this: restTemplate.postForObject(URL,request, SomeTemplate.class).
    * How can I do this more elegant or what is the best practice?

    I am looking forward to any kind of comment.

    Thanks in advance,

    Jan1337z.
Working...
X