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

Commit

Permalink
bug fixed for Feature.SupportNonPublicField. for issue #1494
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed Oct 6, 2017
1 parent 8f8a0f7 commit 569d7ec
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/main/java/com/alibaba/fastjson/parser/JavaBeanDeserializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -961,17 +961,19 @@ private boolean parseField(DefaultJSONParser parser, String key, Object object,
|| (this.beanInfo.parserFeatures & mask) != 0)) {
if (this.extraFieldDeserializers == null) {
ConcurrentHashMap extraFieldDeserializers = new ConcurrentHashMap<String, Object>(1, 0.75f, 1);
Field[] fields = this.clazz.getDeclaredFields();
for (Field field : fields) {
String fieldName = field.getName();
if (this.getFieldDeserializer(fieldName) != null) {
continue;
}
int fieldModifiers = field.getModifiers();
if ((fieldModifiers & Modifier.FINAL) != 0 || (fieldModifiers & Modifier.STATIC) != 0) {
continue;
for (Class c = this.clazz; c != null && c != Object.class; c = c.getSuperclass()) {
Field[] fields = c.getDeclaredFields();
for (Field field : fields) {
String fieldName = field.getName();
if (this.getFieldDeserializer(fieldName) != null) {
continue;
}
int fieldModifiers = field.getModifiers();
if ((fieldModifiers & Modifier.FINAL) != 0 || (fieldModifiers & Modifier.STATIC) != 0) {
continue;
}
extraFieldDeserializers.put(fieldName, field);
}
extraFieldDeserializers.put(fieldName, field);
}
this.extraFieldDeserializers = extraFieldDeserializers;
}
Expand Down
31 changes: 31 additions & 0 deletions src/test/java/com/alibaba/json/bvt/issue_1400/Issue1494.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.alibaba.json.bvt.issue_1400;

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

public class Issue1494 extends TestCase {
public void test_for_issue() throws Exception {
String json = "{\"id\":1001,\"name\":\"wenshao\"}";
B b = JSON.parseObject(json, B.class);
assertEquals("{\"id\":1001,\"name\":\"wenshao\"}", JSON.toJSONString(b));
}

public static class A {
private int id;

public int getId() {
return id;
}
}

@JSONType(parseFeatures = Feature.SupportNonPublicField)
public static class B extends A {
private String name;

public String getName() {
return name;
}
}
}

0 comments on commit 569d7ec

Please sign in to comment.