Skip to content

Commit f69d154

Browse files
BAEL-2412
New example showing that the empty string can be deserialized into a char.
1 parent 089162e commit f69d154

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

‎gson/src/test/java/org/baeldung/gson/primitives/UnitTest.java‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,21 @@ public class UnitTest {
143143
// @formatter:off
144144
String json = "{\"byteValue\": \"\", \"shortValue\": \"\", "
145145
+ "\"intValue\": \"\", " + "\"longValue\": \"\", \"floatValue\": \"\""
146-
+ ", \"doubleValue\": \"\"" + ", \"booleanValue\": \"\", \"charValue\": \"\"}";
146+
+ ", \"doubleValue\": \"\"" + ", \"booleanValue\": \"\"}";
147147
// @formatter:on
148148
gson.fromJson(json, PrimitiveBundleInitialized.class);
149149
}
150150

151+
@Test public void fromJsonEmptyStringToChar() {
152+
Gson gson = new Gson();
153+
// @formatter:off
154+
String json = "{\"charValue\": \"\"}";
155+
// @formatter:on
156+
CharExample model = gson.fromJson(json, CharExample.class);
157+
158+
assertEquals(Character.MIN_VALUE, model.value);
159+
}
160+
151161
@Test public void fromJsonValidValueWithinString() {
152162
Gson gson = new Gson();
153163
// @formatter:off

0 commit comments

Comments
 (0)