Skip to content

Commit

Permalink
feat: Deserialize char from number (libgdx#7570)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonIT authored Feb 6, 2025
1 parent 091d211 commit 85588b8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions gdx/src/com/badlogic/gdx/utils/Json.java
Original file line number Diff line number Diff line change
Expand Up @@ -1144,6 +1144,7 @@ protected boolean ignoreUnknownField (Class type, String fieldName) {
if (type == String.class) return (T)jsonData.asString();
if (type == short.class || type == Short.class) return (T)(Short)jsonData.asShort();
if (type == byte.class || type == Byte.class) return (T)(Byte)jsonData.asByte();
if (type == char.class || type == Character.class) return (T)(Character)jsonData.asChar();
} catch (NumberFormatException ignored) {
}
jsonData = new JsonValue(jsonData.asString());
Expand Down
7 changes: 7 additions & 0 deletions gdx/test/com/badlogic/gdx/utils/JsonTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ public void testFromJsonArray () {
assertEquals("value2", value.get(1));
}

@Test
public void testCharFromNumber () {
Json json = new Json();
char value = json.fromJson(char.class, "90");
assertEquals('Z', value);
}

@Test
public void testReuseReader () {
Json json = new Json();
Expand Down

0 comments on commit 85588b8

Please sign in to comment.