This repository has been archived by the owner on Oct 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3491 from blindarcheology/add-test-cause-issue3479
add test cause issue3479
- Loading branch information
Showing
3 changed files
with
78 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
src/test/java/com/alibaba/fastjson/serializer/issue3479/TestIssue3479.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |