Skip to content

Commit 85588b8

Browse files
authored
feat: Deserialize char from number (libgdx#7570)
1 parent 091d211 commit 85588b8

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

gdx/src/com/badlogic/gdx/utils/Json.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,6 +1144,7 @@ protected boolean ignoreUnknownField (Class type, String fieldName) {
11441144
if (type == String.class) return (T)jsonData.asString();
11451145
if (type == short.class || type == Short.class) return (T)(Short)jsonData.asShort();
11461146
if (type == byte.class || type == Byte.class) return (T)(Byte)jsonData.asByte();
1147+
if (type == char.class || type == Character.class) return (T)(Character)jsonData.asChar();
11471148
} catch (NumberFormatException ignored) {
11481149
}
11491150
jsonData = new JsonValue(jsonData.asString());

gdx/test/com/badlogic/gdx/utils/JsonTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ public void testFromJsonArray () {
2222
assertEquals("value2", value.get(1));
2323
}
2424

25+
@Test
26+
public void testCharFromNumber () {
27+
Json json = new Json();
28+
char value = json.fromJson(char.class, "90");
29+
assertEquals('Z', value);
30+
}
31+
2532
@Test
2633
public void testReuseReader () {
2734
Json json = new Json();

0 commit comments

Comments
 (0)