Skip to content

Commit 60090a7

Browse files
committed
add a test case for an enum implementing JSONString
(cherry picked from commit d17bbbd)
1 parent 0c5cf18 commit 60090a7

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

src/test/java/org/json/junit/JSONStringTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,22 @@ public void testNullStringValue() throws Exception {
319319
}
320320
}
321321

322+
@Test
323+
public void testEnumJSONString() {
324+
JSONObject jsonObject = new JSONObject();
325+
jsonObject.put("key", MyEnum.MY_ENUM);
326+
assertEquals("{\"key\":\"myJsonString\"}", jsonObject.toString());
327+
}
328+
329+
private enum MyEnum implements JSONString {
330+
MY_ENUM;
331+
332+
@Override
333+
public String toJSONString() {
334+
return "\"myJsonString\"";
335+
}
336+
}
337+
322338
/**
323339
* A JSONString that returns a valid JSON string value.
324340
*/

0 commit comments

Comments
 (0)