title: jackson - json encoding of doubles with controlled precision
body: <p>I'm encoding a complex Map structure with arrays of double values.
  High precision is not important and output size is, so I'm trying to get the JSON tool (Jackson in this case) to serialize the double values using a provided DecimalFormat.</p>
  
  <p>The following is my best shot, but this fails as the serializer is not picked by the object mapper to encode the array:</p>
  
  <pre><code>class MyTest
  {
    public class MyDoubleSerializer extends JsonSerializer&lt;double[]&gt;
    {
      public void serialize(double[] value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException
      {
        for (double d : value)
        {
          jgen.writeStartArray();
          jgen.writeRaw( df.format( d ) );
          jgen.writeEndArray();
        }
      }
    }
  
    @Test
    public void test1() throws Exception
    {
      ObjectMapper mapper = new ObjectMapper();
      SimpleModule module = new SimpleModule("MyModule", new Version(0, 1, 0, "alpha"));
      module.addSerializer(double[].class, new MyDoubleSerializer());
      mapper.registerModule(module);
  
      Map&lt;String, Object&gt; data = new HashMap&lt;String, Object&gt;();
      double[] doubleList = { 1.1111111111D, (double) (System.currentTimeMillis()) };
      data.put( "test", doubleList );
      System.out.print( mapper.writeValueAsString( data ));
    }
  }
  </code></pre>
  
  <p>The output is: </p>
  
  <blockquote>
    <p>{"test":[1.1111111111,1.315143204964E12}</p>
  </blockquote>
  
  <p>What I was looking for: </p>
  
  <blockquote>
    <p>{"test":[1.32E12, 1.11E0]}</p>
  </blockquote>
  
  <p>Any ideas?</p>
  
  <p>Also, I don't like having to generate a String and write is as raw - is there I could feed a StringBuffer into into DecimalFormat to do this?</p>
  
  <p>Thanks</p>