java - Using Gson to elegantly handle nested json objects? -


I am using GSS to parse responses from a server on Android. In every response I have some useless data (for me) that makes my GSN model complicated. Here's back in the general hierarchy of Jason:

  Feedback: {date: 1406253006807, other users1: "This is some useless data", other Useladata 2: "This is some useless data ", Useful JasonObject: {& lt; ---- It really is the object that I care about}}   

Everything could be done without the usefulJsonObject at the same or the same level. The waste data is returned for every request, and the actual response is given as useful JasonObject , this will not be a big problem, but it is actually closing down my GSN model objects is.

For example: Let's say I have 3 requests that I can do: A, B and C for each response me less Need to create less than 3 custom squares.

  Public class ResponseA {@SerializedName ("response") ResponseObjectA responseObject; Public Static Class Answer ResponseObjectA {@SerializedName ("usefulJsonObject") Useful Object A useful object; } Public Stabilized Class UsefulObjectA {}}   

I have tried some solutions, but I have not found anything beautiful which will not be able to add an additional step in my process. I am using retrofit for my HTTP requests and it is very good that it gives me completely parsed GSN objects. I have thought of other solutions like useful objects are just a JasonElement and for the first time After coming back, call the second Jason. Again, not ideal.

I just wanted to know if I was missing something or not. Of course I'm not the only one who has faced something like this, and I thought I would ask how other people could handle something like this.

This is the initialization example value, not NULL Value. See my example.

Address. Java

  Public category address {public address} () {}}   

person.java

  public class person {private string name; Private string NRC; Private address addresses; Public person (string name, string NRC, address address) {this.name = name; This.nrc = nrc; This.address = Address; }}   

The following is the Json string

  person = person new ("zo than oo", "11111 ", tap); {"Name": "Jow Than oo", "NRC": "11111"}   

The following is Jason

  person = new person ("zo than oo", "11111", new address ()); {"Name": "Jau Thanh Oo", "NRC": "11111", "Address": {}   

Even if you do not create a new example , other lib / api < / Code> reflection .

Under the dot

  {... "xxx": {} -> New examples of data / value ...} {... - & gt; Zero value ...}    

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -