title: How can I prevent gson from converting integers to doubles
body: <p>I've got integers in my json, and I do not want gson to convert them to doubles. The following does not work:</p>
  
  <pre><code>@Test
  public void keepsIntsAsIs(){
      String json="[{\"id\":1,\"quantity\":2,\"name\":\"apple\"},{\"id\":3,\"quantity\":4,\"name\":\"orange\"}]";
      GsonBuilder gsonBuilder = new GsonBuilder();
      gsonBuilder.registerTypeAdapter(Double.class,  new DoubleSerializerAsInt());
      Gson gson = gsonBuilder.create();
      List&lt;Map&lt;String, Object&gt;&gt; l = gson.fromJson(json, List.class);
      for(Map&lt;String, Object&gt; item : l){
          System.out.println(item);
      }
  }
  
  private static class DoubleSerializerAsInt implements JsonSerializer&lt;Double&gt;{
  
      @Override
      public JsonElement serialize(Double aDouble, Type type, JsonSerializationContext jsonSerializationContext) {
          int value = (int)Math.round(aDouble);
          return new JsonPrimitive(value);
      }
  }
  </code></pre>
  
  <p>The output is not what I want:</p>
  
  <pre><code>{id=1.0, quantity=2.0, name=apple}
  {id=3.0, quantity=4.0, name=orange}
  </code></pre>
  
  <p>Is there a way to have Integers instead of Doubles in my Map?</p>
  
  <pre><code>{id=1, quantity=2, name=apple}
  {id=3, quantity=4, name=orange}
  </code></pre>
  
  <p><strong>Edit:</strong> not all my fields are integer. I've modified my example accordingly.
  I've read quite a few examples online, including some answers on this site, but it does not work in this particular case. </p>