Skip to content

Commit

Permalink
JSONObject.get support Boolean & Character & UUID, fix #3356
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed Jul 21, 2020
1 parent 38070ca commit fc52ad0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/main/java/com/alibaba/fastjson/JSONObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,14 @@ public boolean containsValue(Object value) {
public Object get(Object key) {
Object val = map.get(key);

if (val == null && key instanceof Number) {
val = map.get(key.toString());
if (val == null) {
if (key instanceof Number
|| key instanceof Character
|| key instanceof Boolean
|| key instanceof UUID
) {
val = map.get(key.toString());
}
}

return val;
Expand Down
21 changes: 21 additions & 0 deletions src/test/java/com/alibaba/json/bvt/issue_3300/Issue3356.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.alibaba.json.bvt.issue_3300;

import com.alibaba.fastjson.JSONObject;
import junit.framework.TestCase;

import java.util.UUID;

public class Issue3356 extends TestCase {
public void test_for_issue() throws Exception {
UUID uuid = UUID.randomUUID();

JSONObject object = new JSONObject();
object.put("1", "1");
object.put(uuid.toString(), uuid.toString());
object.put("A", "A");
object.put("true", "true");
assertEquals("1", object.get(1));
assertEquals("true", object.get(true));
assertEquals("A", object.get('A'));
}
}

0 comments on commit fc52ad0

Please sign in to comment.