@@ -235,8 +235,8 @@ public void write(JsonWriter out, Vector2d value) throws IOException {
235235 }
236236
237237 out .beginObject ();
238- out .name ("x" ); out . value ( value .getX ());
239- out .name (useZ ? "z" : "y" ); out . value ( value .getY ());
238+ out .name ("x" ); writeRounded ( out , value .getX ());
239+ out .name (useZ ? "z" : "y" ); writeRounded ( out , value .getY ());
240240 out .endObject ();
241241 }
242242
@@ -262,6 +262,13 @@ public Vector2d read(JsonReader in) throws IOException {
262262 return new Vector2d (x , y );
263263 }
264264
265+ private void writeRounded (JsonWriter json , double value ) throws IOException {
266+ // rounding and remove ".0" to save string space
267+ double d = Math .round (value * 10000d ) / 10000d ;
268+ if (d == (long ) d ) json .value ((long ) d );
269+ else json .value (d );
270+ }
271+
265272 }
266273
267274 static class Vector3dAdapter extends TypeAdapter <Vector3d > {
@@ -274,9 +281,9 @@ public void write(JsonWriter out, Vector3d value) throws IOException {
274281 }
275282
276283 out .beginObject ();
277- out .name ("x" ); out . value ( value .getX ());
278- out .name ("y" ); out . value ( value .getY ());
279- out .name ("z" ); out . value ( value .getZ ());
284+ out .name ("x" ); writeRounded ( out , value .getX ());
285+ out .name ("y" ); writeRounded ( out , value .getY ());
286+ out .name ("z" ); writeRounded ( out , value .getZ ());
280287 out .endObject ();
281288 }
282289
@@ -302,6 +309,13 @@ public Vector3d read(JsonReader in) throws IOException {
302309 return new Vector3d (x , y , z );
303310 }
304311
312+ private void writeRounded (JsonWriter json , double value ) throws IOException {
313+ // rounding and remove ".0" to save string space
314+ double d = Math .round (value * 10000d ) / 10000d ;
315+ if (d == (long ) d ) json .value ((long ) d );
316+ else json .value (d );
317+ }
318+
305319 }
306320
307321 static class Vector2iAdapter extends TypeAdapter <Vector2i > {
0 commit comments