content: package com.alibaba.fastjson2.writer;
  
  import com.alibaba.fastjson2.JSONException;
  import com.alibaba.fastjson2.JSONWriter;
  
  import java.lang.reflect.Field;
  
  import static com.alibaba.fastjson2.util.JDKUtils.UNSAFE;
  
  final class FieldWriterDoubleValField<T>
          extends FieldWriter<T> {
      FieldWriterDoubleValField(String name, int ordinal, String format, String label, Field field) {
          super(name, ordinal, 0, format, null, label, double.class, double.class, field, null);
      }
  
      @Override
      public Object getFieldValue(Object object) {
          return getFieldValueDouble(object);
      }
  
      public double getFieldValueDouble(Object object) {
          if (object == null) {
              throw new JSONException("field.get error, " + fieldName);
          }
  
          try {
              double value;
              if (fieldOffset != -1) {
                  value = UNSAFE.getDouble(object, fieldOffset);
              } else {
                  value = field.getDouble(object);
              }
              return value;
          } catch (IllegalArgumentException | IllegalAccessException e) {
              throw new JSONException("field.get error, " + fieldName, e);
          }
      }
  
      @Override
      public boolean write(JSONWriter jsonWriter, T object) {
          double value = getFieldValueDouble(object);
          writeDouble(jsonWriter, value);
          return true;
      }
  
      @Override
      public void writeValue(JSONWriter jsonWriter, T object) {
          double value = getFieldValueDouble(object);
          if (decimalFormat != null) {
              jsonWriter.writeDouble(value, decimalFormat);
          } else {
              jsonWriter.writeDouble(value);
          }
      }
  }
  