Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

revert support 'size 1 list<map> as map'. for issue #3656 #3659

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import java.util.concurrent.ConcurrentMap;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.parser.*;
Expand Down Expand Up @@ -100,18 +99,6 @@ public static Map parseMap(DefaultJSONParser parser, Map<String, Object> map, Ty
msg += ", ";
msg += lexer.info();

if (token != JSONToken.LITERAL_STRING) {
JSONArray array = new JSONArray();
parser.parseArray(array, fieldName);

if (array.size() == 1) {
Object first = array.get(0);
if (first instanceof JSONObject) {
return (JSONObject) first;
}
}
}

throw new JSONException(msg);
}

Expand Down
3 changes: 1 addition & 2 deletions src/test/java/com/alibaba/json/bvt/issue_1100/Issue1189.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.alibaba.json.bvt.issue_1100;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONException;
import junit.framework.TestCase;

import java.util.Map;
Expand All @@ -11,7 +10,7 @@
*/
public class Issue1189 extends TestCase {
public void test_for_issue() throws Exception {
String str = new String("{\"headernotificationType\": \"PUSH\",\"headertemplateNo\": \"99\",\"headerdestination\": [{\"target\": \"all\",\"targetvalue\": \"all\"}],\"body\": [{\"title\": \"预约超时\",\"body\": \"您的预约已经超时\"}]}");
String str = "{\"headernotificationType\": \"PUSH\",\"headertemplateNo\": \"99\",\"headerdestination\": {\"target\": \"all\",\"targetvalue\": \"all\"},\"body\": {\"title\": \"预约超时\",\"body\": \"您的预约已经超时\"}}";

JsonBean objeclt = JSON.parseObject(str, JsonBean.class);
Map<String, String> list = objeclt.getBody();
Expand Down
88 changes: 88 additions & 0 deletions src/test/java/com/alibaba/json/bvt/issue_3600/Issue3656.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package com.alibaba.json.bvt.issue_3600;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONException;
import org.junit.Test;

import java.util.List;
import java.util.Map;

/**
* @Author :Nanqi
* @Date :Created in 21:43 2021/02/25
*/
public class Issue3656 {
@Test(expected = JSONException.class)
public void test_for_issue() {
String jsonStr = "{" +
" \"serviceType\":\"dubbo\"," +
" \"types\":[" +
" {" +
" \"enums\":[" +
"" +
" ]," +
" \"typeBuilderName\":\"DefaultTypeBuilder\"," +
" \"type\":\"int\"," +
" \"items\":[" +
"" +
" ]," +
" \"properties\":{" +
"" +
" }" +
" }" +
" ]" +
"}";
Metadata m = JSON.parseObject(jsonStr, Metadata.class);
}

public static class Type {
private List<String> enums;
private String typeBuilderName;
private String type;

public List<String> getEnums() {
return enums;
}

public void setEnums(List<String> enums) {
this.enums = enums;
}

public String getTypeBuilderName() {
return typeBuilderName;
}

public void setTypeBuilderName(String typeBuilderName) {
this.typeBuilderName = typeBuilderName;
}

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}
}

public static class Metadata {
private String serviceType;
private Map<String, Type> types;

public String getServiceType() {
return serviceType;
}

public void setServiceType(String serviceType) {
this.serviceType = serviceType;
}

public Map<String, Type> getTypes() {
return types;
}

public void setTypes(Map<String, Type> types) {
this.types = types;
}
}
}