title: gson flat json to nested objects needs serializer/deserializer?
body: <p>I have some JSON coming in (I don't have any control or ability to change the structure and/or naming within the JSON...important to keep in mind in this question) that has a "flat" structure similar to this:</p>
  
  <pre><code>{
    "name": "...",
    "email": "...",
    "box_background_color": "...",
    "box_border_color": "...",
    "box_text_color": "...",
    ...
  }
  </code></pre>
  
  <p><br/></p>
  
  <p>Now, I can just create a simple object that keeps everything flat, like so:</p>
  
  <pre><code>public class Settings {
  
    @SerializedName("name")
    private String _name;
  
    @SerializedName("email")
    private String _emailAddress;
  
    @SerializedName("box_background_color")
    private String _boxBackgroundColor;
  
    @SerializedName("box_border_color")
    private String _boxBorderColor;
  
    @SerializedName("box_text_color")
    private String _boxTextColor;
  
    ...
  }
  </code></pre>
  
  <p><br/></p>
  
  <p>However, I want everything associated with <code>box</code> settings to be in it's own class (<code>BoxSettings</code>). This is more like what I want:</p>
  
  <pre><code>public class Settings {
  
    @SerializedName("name")
    private String _name;
  
    @SerializedName("email")
    private String _emailAddress;
  
    private BoxSettings _boxSettings
  
    ...
  }
  
  public class BoxSettings {
  
    @SerializedName("box_background_color")
    private String _boxBackgroundColor;
  
    @SerializedName("box_border_color")
    private String _boxBorderColor;
  
    @SerializedName("box_text_color")
    private String _boxTextColor;
  
    ...
  }
  </code></pre>
  
  <p><br/></p>
  
  <p>I know that if the JSON was structured such that the box settings were nested then it would be easy to accomplish what I want, however, I don't have the ability to change the structure of the JSON, so please don't suggest that (I would do it if I could).</p>
  
  <p>My question is this: <strong>Is creating an entire TypeAdapter <em>the only way</em> to accomplish what I want or can I still accomplish most of this with annotations? If it is not the only way, how else can I accomplish this without changing the JSON at all?</strong></p>
  
  <p>The following is an example of what I mean by "creating an entire TypeAdapter":</p>
  
  <pre><code>public class SettingsTypeAdapter implements JsonDeserializer&lt;Settings&gt;, JsonSerializer&lt;Settings&gt; {
  
    @Override
    public JsonElement serialize(Settings src, Type typeOfSrc, JsonSerializationContext context) {
      // Add _name
      // Add _emailAddress
      // Add BoxSettings._boxBackgroundColor
      // Add BoxSettings._boxBorderColor
      // Add BoxSettings._boxTextColor
      return jsonElement;
    }
  
    @Override
    public Settings deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
      // Read _name
      // Read _emailAddress
      // Read BoxSettings._boxBackgroundColor
      // Read BoxSettings._boxBorderColor
      // Read BoxSettings._boxTextColor
      return settings;
    }
  }
  </code></pre>