Closed GoogleCodeExporter closed 9 years ago
The quoted numbers are supported to defend against precision loss. In
particular, for double-precision floating point values in JavaScript. There's
no equivalent problem with booleans.
Original comment by limpbizkit
on 9 Aug 2014 at 10:30
Additionally, you can do this with a custom TypeAdapter.
public final class BooleanAdapter extends TypeAdapter<Boolean> {
@Override
public void write(JsonWriter out, Boolean value) throws IOException {
if (value != null) {
out.value(value);
} else {
out.nullValue();
}
}
@Override
public Boolean read(JsonReader in) throws IOException {
JsonToken peek = in.peek();
switch (peek) {
case BOOLEAN:
return in.nextBoolean();
case STRING:
return Boolean.parseBoolean(in.nextString());
case NULL:
in.nextNull();
return null;
default:
throw new IllegalStateException("Expected BOOLEAN or STRING but was " + peek);
}
}
}
Original comment by j...@squareup.com
on 10 Aug 2014 at 1:42
Original issue reported on code.google.com by
o...@fleaflicker.com
on 20 May 2014 at 9:43