diff --git a/src/main/java/com/alibaba/fastjson/JSON.java b/src/main/java/com/alibaba/fastjson/JSON.java index 2bcff3a5dd..f33ed9787a 100755 --- a/src/main/java/com/alibaba/fastjson/JSON.java +++ b/src/main/java/com/alibaba/fastjson/JSON.java @@ -130,12 +130,24 @@ public static Object parse(String text) { return parse(text, DEFAULT_PARSER_FEATURE); } - public static Object parse(String text, int features) { + /** + * + * @since 1.2.38 + */ + public static Object parse(String text, ParserConfig config) { + return parse(text, config, DEFAULT_PARSER_FEATURE); + } + + /** + * + * @since 1.2.38 + */ + public static Object parse(String text, ParserConfig config, int features) { if (text == null) { return null; } - DefaultJSONParser parser = new DefaultJSONParser(text, ParserConfig.getGlobalInstance(), features); + DefaultJSONParser parser = new DefaultJSONParser(text, config, features); Object value = parser.parse(); parser.handleResovleTask(value); @@ -145,6 +157,10 @@ public static Object parse(String text, int features) { return value; } + public static Object parse(String text, int features) { + return parse(text, ParserConfig.getGlobalInstance(), features); + } + public static Object parse(byte[] input, Feature... features) { char[] chars = allocateChars(input.length); int len = IOUtils.decodeUTF8(input, 0, input.length, chars); diff --git a/src/main/java/com/alibaba/fastjson/parser/DefaultJSONParser.java b/src/main/java/com/alibaba/fastjson/parser/DefaultJSONParser.java index bacc821cff..525441e798 100755 --- a/src/main/java/com/alibaba/fastjson/parser/DefaultJSONParser.java +++ b/src/main/java/com/alibaba/fastjson/parser/DefaultJSONParser.java @@ -527,8 +527,10 @@ public final Object parseObject(final Map object, Object fieldName) { ctxLocal.object = object; } - checkMapResolve(object, key.toString()); - + if (key != null) { + checkMapResolve(object, key.toString()); + } + map.put(key, obj); if (parentIsArray) { diff --git a/src/test/java/com/alibaba/json/bvt/issue_1500/Issue1503.java b/src/test/java/com/alibaba/json/bvt/issue_1500/Issue1503.java new file mode 100644 index 0000000000..881e8f19b4 --- /dev/null +++ b/src/test/java/com/alibaba/json/bvt/issue_1500/Issue1503.java @@ -0,0 +1,24 @@ +package com.alibaba.json.bvt.issue_1500; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.parser.ParserConfig; +import com.alibaba.fastjson.serializer.SerializerFeature; +import junit.framework.TestCase; + +import java.util.HashMap; +import java.util.Map; + +public class Issue1503 extends TestCase { + public void test_for_issue() throws Exception { + ParserConfig config = new ParserConfig(); + config.setAutoTypeSupport(true); + Map map = new HashMap(); + map.put(null, new Bean()); + Map rmap = (Map) JSON.parse(JSON.toJSONString(map, SerializerFeature.WriteClassName), config); + System.out.println(rmap); + } + + public static class Bean { + + } +}