title: Using Retrofit and RxJava, how do I deserialize JSON when it doesn't map directly to a model object?
body: <p>The API I'm working with returns objects (and their containing objects) in a "flat" format and I'm having trouble getting this to work elegantly with Retrofit and RxJava.</p>
  
  <p>Consider this JSON response for an <code>/employees/{id}</code> endpoint:</p>
  
  <pre><code>{
      "id": "123",
      "id_to_name": {
          "123" : "John Doe"
      },
      "id_to_age": {
          "123" : 30
      }
  }
  </code></pre>
  
  <p>Using Retrofit and RxJava, how do I deserialize this to a <code>Employee</code> object with fields for <code>name</code> and <code>age</code>?</p>
  
  <p>Ideally I'd like RxJava's <code>onNext</code> method to be called with an <code>Employee</code> object. Is this possible? Could this perhaps be done with some type of custom deserializer subclass (I'm using Gson at the moment)?</p>
  
  <p>I realize I could create an <code>EmployeeResponse</code> object that maps directly to the JSON response, but having to map the <code>EmployeeResponse</code> to the <code>Employee</code> object every time I use this in an activity seems kind of unfortunate. It also gets much more complicated when the flat response also contains other objects that need to get deserialized and set as fields on the <code>Employee</code>. </p>
  
  <p>Is there a better way?</p>