Skip to content

Commit

Permalink
bug fixed for issue 555
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed May 21, 2016
1 parent 6af506c commit 3339419
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/main/java/com/alibaba/fastjson/util/JavaBeanInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,10 @@ public static JavaBeanInfo build(Class<?> clazz, Type type) {
fieldAnnotation = field.getAnnotation(JSONField.class);

if (fieldAnnotation != null) {
if (!fieldAnnotation.deserialize()) {
continue;
}

ordinal = fieldAnnotation.ordinal();
serialzeFeatures = SerializerFeature.of(fieldAnnotation.serialzeFeatures());
parserFeatures = Feature.of(fieldAnnotation.parseFeatures());
Expand Down Expand Up @@ -444,6 +448,10 @@ public static JavaBeanInfo build(Class<?> clazz, Type type) {
JSONField fieldAnnotation = field.getAnnotation(JSONField.class);

if (fieldAnnotation != null) {
if (!fieldAnnotation.deserialize()) {
continue;
}

ordinal = fieldAnnotation.ordinal();
serialzeFeatures = SerializerFeature.of(fieldAnnotation.serialzeFeatures());
parserFeatures = Feature.of(fieldAnnotation.parseFeatures());
Expand Down Expand Up @@ -480,12 +488,16 @@ public static JavaBeanInfo build(Class<?> clazz, Type type) {
String propertyName;

JSONField annotation = method.getAnnotation(JSONField.class);
if (annotation != null && annotation.deserialize()) {
continue;
}

if (annotation != null && annotation.name().length() > 0) {
propertyName = annotation.name();
} else {
propertyName = Character.toLowerCase(methodName.charAt(3)) + methodName.substring(4);
}

FieldInfo fieldInfo = getField(fieldList, propertyName);
if (fieldInfo != null) {
continue;
Expand Down
34 changes: 34 additions & 0 deletions src/test/java/com/alibaba/json/bvt/bug/Bug_for_issue_555.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.alibaba.json.bvt.bug;

import java.util.List;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;

import junit.framework.TestCase;

public class Bug_for_issue_555 extends TestCase {

public void test_for_issue() throws Exception {
JSON.parseObject("{\"list\":[{\"spec\":{}}]}", A.class);
}

public static class A {

public List<B> list;
}

public static class B {

@JSONField(serialize = true, deserialize = false)
public Spec spec;
}

public static class Spec {
private int id;

public Spec(int id) {
this.id = id;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.alibaba.json.bvt.bug;

import java.util.List;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;

import junit.framework.TestCase;

public class Bug_for_issue_555_setter extends TestCase {

public void test_for_issue() throws Exception {
JSON.parseObject("{\"list\":[{\"spec\":{}}]}", A.class);
}

public static class A {

public List<B> list;
}

public static class B {

@JSONField(serialize = true, deserialize = false)
private Spec spec;

public Spec getSpec() {
return spec;
}

public void setSpec(Spec spec) {
this.spec = spec;
}

}

public static class Spec {

private int id;

public Spec(int id){
this.id = id;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.alibaba.json.bvt.bug;

import java.util.List;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;

import junit.framework.TestCase;

public class Bug_for_issue_555_setter2 extends TestCase {

public void test_for_issue() throws Exception {
JSON.parseObject("{\"list\":[{\"spec\":{}}]}", A.class);
}

public static class A {

public List<B> list;
}

public static class B {

private Spec spec;

@JSONField(serialize = true, deserialize = false)
public Spec getSpec() {
return spec;
}

@JSONField(serialize = true, deserialize = false)
public void setSpec(Spec spec) {
this.spec = spec;
}

}

public static class Spec {

private int id;

public Spec(int id){
this.id = id;
}
}
}

0 comments on commit 3339419

Please sign in to comment.