http-api: encode json Colors as ARGB hex codes

This commit is contained in:
Max Weber
2021-02-24 10:20:52 -07:00
committed by Adam
parent 48ea01dd28
commit 463b0d73ba
2 changed files with 25 additions and 9 deletions

View File

@@ -43,10 +43,7 @@ public class ColorTypeAdapter extends TypeAdapter<Color>
}
int rgba = value.getRGB();
out.beginObject()
.name("value")
.value(rgba)
.endObject();
out.value(String.format("#%08X", rgba));
}
@Override
@@ -57,7 +54,18 @@ public class ColorTypeAdapter extends TypeAdapter<Color>
case NULL:
in.nextNull();
return null;
case STRING:
{
String value = in.nextString();
if (value.charAt(0) == '#')
{
value = value.substring(1);
}
int intValue = Integer.parseUnsignedInt(value, 16);
return new Color(intValue, true);
}
case BEGIN_OBJECT:
{
in.beginObject();
double value = 0;
while (in.peek() != JsonToken.END_OBJECT)
@@ -74,6 +82,7 @@ public class ColorTypeAdapter extends TypeAdapter<Color>
}
in.endObject();
return new Color((int) value, true);
}
}
return null; // throws
}