Java Code Examples for com.google.gson.internal.bind.TypeAdapters#FLOAT

The following examples show how to use com.google.gson.internal.bind.TypeAdapters#FLOAT . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Gson.java    From letv with Apache License 2.0 6 votes vote down vote up
private TypeAdapter<Number> floatAdapter(boolean serializeSpecialFloatingPointValues) {
    if (serializeSpecialFloatingPointValues) {
        return TypeAdapters.FLOAT;
    }
    return new TypeAdapter<Number>() {
        public Float read(JsonReader in) throws IOException {
            if (in.peek() != JsonToken.NULL) {
                return Float.valueOf((float) in.nextDouble());
            }
            in.nextNull();
            return null;
        }

        public void write(JsonWriter out, Number value) throws IOException {
            if (value == null) {
                out.nullValue();
                return;
            }
            Gson.this.checkValidFloatingPoint((double) value.floatValue());
            out.value(value);
        }
    };
}
 
Example 2
Source File: Gson.java    From gson with Apache License 2.0 6 votes vote down vote up
private TypeAdapter<Number> floatAdapter(boolean serializeSpecialFloatingPointValues) {
  if (serializeSpecialFloatingPointValues) {
    return TypeAdapters.FLOAT;
  }
  return new TypeAdapter<Number>() {
    @Override public Float read(JsonReader in) throws IOException {
      if (in.peek() == JsonToken.NULL) {
        in.nextNull();
        return null;
      }
      return (float) in.nextDouble();
    }
    @Override public void write(JsonWriter out, Number value) throws IOException {
      if (value == null) {
        out.nullValue();
        return;
      }
      float floatValue = value.floatValue();
      checkValidFloatingPoint(floatValue);
      out.value(value);
    }
  };
}
 
Example 3
Source File: Gson.java    From framework with GNU Affero General Public License v3.0 6 votes vote down vote up
private TypeAdapter<Number> floatAdapter(boolean serializeSpecialFloatingPointValues) {
  if (serializeSpecialFloatingPointValues) {
    return TypeAdapters.FLOAT;
  }
  return new TypeAdapter<Number>() {
    @Override public Float read(JsonReader in) throws IOException {
      if (in.peek() == JsonToken.NULL) {
        in.nextNull();
        return null;
      }
      return (float) in.nextDouble();
    }
    @Override public void write(JsonWriter out, Number value) throws IOException {
      if (value == null) {
        out.nullValue();
        return;
      }
      float floatValue = value.floatValue();
      checkValidFloatingPoint(floatValue);
      out.value(value);
    }
  };
}
 
Example 4
Source File: Gson.java    From MiBandDecompiled with Apache License 2.0 5 votes vote down vote up
private TypeAdapter b(boolean flag)
{
    if (flag)
    {
        return TypeAdapters.FLOAT;
    } else
    {
        return new j(this);
    }
}