http-api: encode json Colors as ARGB hex codes
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user