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

Commit

Permalink
Merge pull request #3269 from alibaba/issue/#3138
Browse files Browse the repository at this point in the history
English FAQ revisions
  • Loading branch information
wenshao authored Jun 25, 2020
2 parents 2ea933b + f753aa5 commit a015da6
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/main/java/com/alibaba/fastjson/parser/JSONLexer.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,5 @@ public interface JSONLexer {
String info();

int getFeatures();
void setFeatures(int features);
}
4 changes: 4 additions & 0 deletions src/main/java/com/alibaba/fastjson/parser/JSONLexerBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -5340,4 +5340,8 @@ public boolean matchField2(char[] fieldName) {
public int getFeatures() {
return this.features;
}

public void setFeatures(int features) {
this.features = features;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ public void parseField(DefaultJSONParser parser, Object object, Type objectType,
JavaBeanDeserializer javaBeanDeser = (JavaBeanDeserializer) fieldValueDeserilizer;
value = javaBeanDeser.deserialze(parser, fieldType, fieldInfo.name, fieldInfo.parserFeatures);
} else {
if (this.fieldInfo.format != null && fieldValueDeserilizer instanceof ContextObjectDeserializer) {
if ((this.fieldInfo.format != null || this.fieldInfo.parserFeatures != 0)
&& fieldValueDeserilizer instanceof ContextObjectDeserializer) {
value = ((ContextObjectDeserializer) fieldValueDeserilizer) //
.deserialze(parser,
fieldType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
import com.alibaba.fastjson.parser.*;
import com.alibaba.fastjson.parser.DefaultJSONParser.ResolveTask;

public class MapDeserializer implements ObjectDeserializer {
public class MapDeserializer extends ContextObjectDeserializer implements ObjectDeserializer {
public static MapDeserializer instance = new MapDeserializer();



@SuppressWarnings("unchecked")
public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName, String format, int features)
{
if (type == JSONObject.class && parser.getFieldTypeResolver() == null) {
return (T) parser.parseObject();
}
Expand All @@ -40,7 +40,7 @@ public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {

try {
parser.setContext(context, map, fieldName);
T t = (T) deserialze(parser, type, fieldName, map);
T t = (T) deserialze(parser, type, fieldName, map, features);
if (unmodifiableMap) {
t = (T) Collections.unmodifiableMap((Map) t);
}
Expand All @@ -50,8 +50,12 @@ public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
}
}

@SuppressWarnings({ "rawtypes", "unchecked" })
protected Object deserialze(DefaultJSONParser parser, Type type, Object fieldName, Map map) {
return deserialze(parser, type, fieldName, map, 0);
}

@SuppressWarnings({ "rawtypes", "unchecked" })
protected Object deserialze(DefaultJSONParser parser, Type type, Object fieldName, Map map, int features) {
if (type instanceof ParameterizedType) {
ParameterizedType parameterizedType = (ParameterizedType) type;
Type keyType = parameterizedType.getActualTypeArguments()[0];
Expand All @@ -62,17 +66,21 @@ protected Object deserialze(DefaultJSONParser parser, Type type, Object fieldNam
valueType = parameterizedType.getActualTypeArguments()[1];
}
if (String.class == keyType) {
return parseMap(parser, (Map<String, Object>) map, valueType, fieldName);
return parseMap(parser, (Map<String, Object>) map, valueType, fieldName, features);
} else {
return parseMap(parser, map, keyType, valueType, fieldName);
}
} else {
return parser.parseObject(map, fieldName);
}
}

public static Map parseMap(DefaultJSONParser parser, Map<String, Object> map, Type valueType, Object fieldName) {
return parseMap(parser, map, valueType, fieldName, 0);
}

@SuppressWarnings("rawtypes")
public static Map parseMap(DefaultJSONParser parser, Map<String, Object> map, Type valueType, Object fieldName) {
public static Map parseMap(DefaultJSONParser parser, Map<String, Object> map, Type valueType, Object fieldName, int features) {
JSONLexer lexer = parser.lexer;

int token = lexer.token();
Expand Down Expand Up @@ -156,7 +164,10 @@ public static Map parseMap(DefaultJSONParser parser, Map<String, Object> map, Ty

lexer.resetStringPosition();

if (key == JSON.DEFAULT_TYPE_KEY && !lexer.isEnabled(Feature.DisableSpecialKeyDetect)) {
if (key == JSON.DEFAULT_TYPE_KEY
&& !lexer.isEnabled(Feature.DisableSpecialKeyDetect)
&& !Feature.isEnabled(features, Feature.DisableSpecialKeyDetect)
) {
String typeName = lexer.scanSymbol(parser.getSymbolTable(), '"');
final ParserConfig config = parser.getConfig();

Expand Down
19 changes: 19 additions & 0 deletions src/test/java/com/alibaba/json/bvt/issue_3000/Issue3138.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.alibaba.json.bvt.issue_3000;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;
import com.alibaba.fastjson.parser.Feature;
import junit.framework.TestCase;

import java.util.Map;

public class Issue3138 extends TestCase {
public void test_0() throws Exception {
VO vo = JSON.parseObject("{\"value\":{\"@type\":\"aa\"}}", VO.class);
}

public static class VO {
@JSONField(parseFeatures = Feature.DisableSpecialKeyDetect)
public Map<String, Object> value;
}
}

0 comments on commit a015da6

Please sign in to comment.