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 #3491 from blindarcheology/add-test-cause-issue3479
Browse files Browse the repository at this point in the history
add test cause issue3479
  • Loading branch information
wenshao authored Nov 2, 2020
2 parents 9b0fa44 + 4af4b15 commit 07f1dd2
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*<p>
* Default value is "build".
*/
public String buildMethod() default "build";
String buildMethod() default "build";

/**
* Property used for (re)defining name prefix to use for
Expand All @@ -37,6 +37,6 @@
* would be used for binding JSON property "value" (using type
* indicated by the argument; or one defined with annotations.
*/
public String withPrefix() default "with";
String withPrefix() default "with";

}
1 change: 0 additions & 1 deletion src/main/java/com/alibaba/fastjson/asm/ClassReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ public void accept(final TypeCollector classVisitor) {

// visits the header
u = header;
v = items[readUnsignedShort(u + 4)];
int len = readUnsignedShort(u + 6);
u += 8;
for (i = 0; i < len; ++i) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package com.alibaba.fastjson.serializer.issue3479;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONType;
import com.alibaba.fastjson.serializer.SerializerFeature;

public class TestIssue3479 {

@JSONType(seeAlso = {Dog.class, Cat.class}, typeKey = "typeKey")
public static abstract class Animal {

private String typeKey;

public String getTypeKey() {
return typeKey;
}

public void setTypeKey(String typeKey) {
this.typeKey = typeKey;
}
}

@JSONType(typeName = "dog")
public static class Dog extends Animal {
private String dogName;

public String getDogName() {
return dogName;
}

public void setDogName(String dogName) {
this.dogName = dogName;
}

@Override
public String toString() {
return "Dog{" +
"dogName='" + dogName + '\'' +
'}';
}
}

@JSONType(typeName = "cat")
public static class Cat extends Animal {
private String catName;

public String getCatName() {
return catName;
}

public void setCatName(String catName) {
this.catName = catName;
}

@Override
public String toString() {
return "Cat{" +
"catName='" + catName + '\'' +
'}';
}
}


public static void main(String[] args) {
Dog dog = new Dog();
dog.dogName = "dog1001";

String text = JSON.toJSONString(dog, SerializerFeature.WriteClassName);
System.out.println(text);

Dog dog2 = (Dog) JSON.parseObject(text, Animal.class);

System.out.println(dog2);
}

}

0 comments on commit 07f1dd2

Please sign in to comment.