title: Spring + Jackson, require trailing 0 on serialisation of double
body: <p>I have a requirement to leave 1 decimal place on numbers returned from a Spring-boot application using Jackson.</p>
  <p>For example, a double with the value <code>9</code> should be returned as <code>9.0</code> and the value <code>9.5</code> should be returned as <code>9.5</code>.</p>
  <p>These should fit into the json type 'number', not 'string' (They do not have quotation marks around them, so not <code>&quot;9.0&quot;</code>, but instead I'm after <code>9.0</code>.</p>
  <p>I have tried writing a custom serialiser using JsonGenerator's  <a href="https://fasterxml.github.io/jackson-core/javadoc/2.2.0/com/fasterxml/jackson/core/JsonGenerator.html#writeRaw(java.lang.String)" rel="nofollow noreferrer">writeRaw(String)</a> and <a href="https://fasterxml.github.io/jackson-core/javadoc/2.2.0/com/fasterxml/jackson/core/JsonGenerator.html#writeRawValue(java.lang.String)" rel="nofollow noreferrer">writeRawValue</a>, as well as various <a href="https://fasterxml.github.io/jackson-core/javadoc/2.2.0/com/fasterxml/jackson/core/JsonGenerator.html#writeNumber(java.math.BigDecimal)" rel="nofollow noreferrer">writeNumber</a> methods.</p>
  <p>The writeRawValue suggests it will write the value:</p>
  <blockquote>
  <p>without any modifications, but assuming it must constitute a single
  legal JSON value (number, string, boolean, null, Array or List)</p>
  </blockquote>
  <p>However it is removing the <code>.0</code>, or at least that <code>.0</code> is gone by the time it makes it's way out of spring boot. There is nothing that I can see in the <a href="https://www.rfc-editor.org/rfc/rfc7159" rel="nofollow noreferrer">Json spec</a> which suggests trimming trailing 0's is required, and there is actually an example with <code>-122.026020</code> in the spec itself.</p>
  <p>How can I get the <code>.0</code> to show up in my responses? Here is what i've tried:</p>
  <pre><code>import com.fasterxml.jackson.core.JsonGenerator;
  import com.fasterxml.jackson.databind.JsonSerializer;
  import com.fasterxml.jackson.databind.SerializerProvider;
  
  import java.io.IOException;
  
  public class MyCustomSerialiser extends JsonSerializer&lt;Double&gt; {
  
    @Override
    public void serialize(Double value, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {   
      jsonGenerator.writeRawValue(&quot;123.450&quot;);
    }
  }
  </code></pre>