Skip to content

Commit

Permalink
bug fixed for issue #1503
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed Oct 1, 2017
1 parent b55cdd4 commit 736cd86
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
20 changes: 18 additions & 2 deletions src/main/java/com/alibaba/fastjson/JSON.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
24 changes: 24 additions & 0 deletions src/test/java/com/alibaba/json/bvt/issue_1500/Issue1503.java
Original file line number Diff line number Diff line change
@@ -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<Long, Bean> map = new HashMap<Long, Bean>();
map.put(null, new Bean());
Map<Long, Bean> rmap = (Map<Long, Bean>) JSON.parse(JSON.toJSONString(map, SerializerFeature.WriteClassName), config);
System.out.println(rmap);
}

public static class Bean {

}
}

0 comments on commit 736cd86

Please sign in to comment.