public void write(D datum, Encoder out) throws IOException {
    Objects.requireNonNull(out, "Encoder cannot be null");
    try {
      write(root, datum, out);
    } catch (TracingNullPointException | TracingClassCastException | TracingAvroTypeException e) {
      throw e.summarize(root);
    }
  }
@Test
  void allowWritingPrimitives() throws IOException {
    Schema doubleType = Schema.create(Schema.Type.DOUBLE);
    Schema.Field field = new Schema.Field("double", doubleType);
    List<Schema.Field> fields = Collections.singletonList(field);
    Schema schema = Schema.createRecord("test", "doc", "", false, fields);

    GenericRecord record = new GenericData.Record(schema);
    record.put("double", 456.4);
    record.put("double", 100000L);
    record.put("double", 444);

    ByteArrayOutputStream bao = new ByteArrayOutputStream();
    GenericDatumWriter<GenericRecord> writer = new GenericDatumWriter<>(schema);
    Encoder encoder = EncoderFactory.get().jsonEncoder(schema, bao);

    writer.write(record, encoder);
  }