title: converting logansqare json class to realm
body: <p>I am using <a href="http://square.github.io/retrofit/" rel="nofollow">Retrofit 2 </a>to call restful webservice and parsing the response using <a href="https://github.com/bluelinelabs/LoganSquare" rel="nofollow">LoganSqure JSON parser</a> and storing the date using <a href="https://realm.io/" rel="nofollow">Realm</a></p>
  
  <p>As realm does not support <code>List</code> data type i need to create two different models for same type response.</p>
  
  <p>for example,</p>
  
  <pre><code>@JsonObject
  public class Dealers {
  
      @JsonField
      private String status;
      @JsonField
      private String responseDateTime;
      @JsonField
      private String userName;
      @JsonField
      private String count;
      @JsonField
      private String error;
      @JsonField
      private List&lt;DealerList&gt; dealerList;
  
  
  }
  </code></pre>
  
  <p>in the above code i <strong>cant not use</strong> <code>RealmList&lt;DealerList&gt;</code> hence i am creating separate model for <code>Realm</code> as follows.</p>
  
  <pre><code>public class RDealers extends RealmObject{
  
  
      private String status;
  
      private String responseDateTime;
  
      private String userName;
  
      private String count;
  
      private String error;
  
       @JsonField( typeConverter = DealerListConverter.class)
      private RealmList&lt;DealerList&gt; dealerList;
  
  
  }
  </code></pre>
  
  <p>after that i need to serialize the response into Json String and convert it into realm.</p>
  
  <pre><code>    Dealers dealers = response.body();
  
  
        try {
  
              String jsonResponse =                       
  LoganSquare.serialize(dealers.getdealerList());
      Realm realm =getDB();
      realm.beginTransaction();
      realm.createAllFromJson(RDealer.class, jsonResponse);
      realm.commitTransaction();
  
            } catch (IOException e) {
               e.printStackTrace();
            } catch (JSONException e) {
              e.printStackTrace();
            }
  </code></pre>
  
  <p>is there any batter way to do this ? </p>
  
  <p>TypeConverter</p>
  
  <pre><code>public class DealerListConverter  implements TypeConverter&lt;RealmList&lt;DealerList&gt;&gt; {
  
  
      @Override
      public RealmList&lt;DealerList&gt; parse(JsonParser jsonParser) throws IOException {
  
          DealerList dealer = new DealerList();
  
  
          RealmList&lt;DealerList&gt; dealerLists = new RealmList&lt;DealerList&gt;() ;
          while(jsonParser.nextToken()  != JsonToken.END_OBJECT){
  
              String name = jsonParser.getCurrentName();
  
              if("dealerID".equals(name)){
  
                  jsonParser.nextToken();
                  Log.e(name, jsonParser.getText());
                  dealer.setDealerID(jsonParser.getText());
  
              }else if ("dealerName".equals(name)){
                  jsonParser.nextToken();
  
                  dealer.setDealerName(jsonParser.getText());
  
                  Log.e(name, jsonParser.getText() );
              }else if ("dealerAddress".equals(name)){
                  jsonParser.nextToken();
  
                  dealer.setDealerAddress(jsonParser.getText());
                  Log.e(name, jsonParser.getText() );
  
              }else if ("dealerAddress2".equals(name)){
                  jsonParser.nextToken();
                  dealer.setDealerAddress2(jsonParser.getText());
                  Log.e(name, jsonParser.getText() );
              }else if ("latitude".equals(name)) {
                  jsonParser.nextToken();
                  dealer.setLatitude(jsonParser.getText());
                  Log.e(name, jsonParser.getText() );
              }else if ("longitude".equals(name)){
  
                  jsonParser.nextToken();
                  dealer.setLongitude(jsonParser.getText());
                  Log.e(name, jsonParser.getText() );
              }else if ("email".equals(name)){
                  jsonParser.nextToken();
  
                  dealer.setEmail(jsonParser.getText());
                  Log.e(name, jsonParser.getText() );
              }else if ("city".equals(name)){
                  jsonParser.nextToken();
  
                  dealer.setCity(jsonParser.getText());
                  Log.e(name, jsonParser.getText() );
              }else if ("statecode".equals(name)){
                  jsonParser.nextToken();
                  Log.e(name, jsonParser.getText());
                  dealer.setStatecode(jsonParser.getText());
  
              }else if ("postcode".equals(name)){
                  jsonParser.nextToken();
                  Log.e(name, jsonParser.getText());
                  dealer.setPostcode(jsonParser.getText());
              }
  
          }
  
          dealerLists.add(dealer);
  
          return dealerLists;
      }
  
      @Override
      public void serialize(RealmList&lt;DealerList&gt; object, String fieldName, boolean writeFieldNameForObject, JsonGenerator jsonGenerator) throws IOException {
  
          Log.e("Converter" , "serialize");
      }
  }
  </code></pre>
  
  <p>i tried above code but i am not getting any response in <code>onResponse</code> function of retrofit</p>
  
  <pre><code> if (response.isSuccess()) {
  
  
          Dealers dealers = response.body();
          // following log is not getting printed
           Log.e("Data" , dealers.getDealerList().size()+" *********");
  
        }
  </code></pre>