-
Notifications
You must be signed in to change notification settings - Fork 477
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
1,976 additions
and
161 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
...test/src/test/java/com/alibaba/fastjson2/internal/processor/annotation/JSONFieldTest.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,27 @@ | ||
package com.alibaba.fastjson2.internal.processor.annotation; | ||
|
||
import com.alibaba.fastjson2.JSON; | ||
import com.alibaba.fastjson2.annotation.JSONCompiled; | ||
import com.alibaba.fastjson2.annotation.JSONField; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class JSONFieldTest { | ||
@Test | ||
public void test() { | ||
Bean bean = new Bean(); | ||
bean.id = 123; | ||
|
||
String str = JSON.toJSONString(bean); | ||
|
||
Bean bean1 = JSON.parseObject(str, Bean.class); | ||
assertEquals(bean.id, bean1.id); | ||
} | ||
|
||
@JSONCompiled | ||
public static class Bean { | ||
@JSONField(name = "userId") | ||
public int id; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...st/src/test/java/com/alibaba/fastjson2/internal/processor/collections/CollectionTest.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,42 @@ | ||
package com.alibaba.fastjson2.internal.processor.collections; | ||
|
||
import com.alibaba.fastjson2.JSON; | ||
import com.alibaba.fastjson2.annotation.JSONCompiled; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.*; | ||
import java.util.concurrent.CopyOnWriteArrayList; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class CollectionTest { | ||
@Test | ||
public void test() { | ||
Bean bean = new Bean(); | ||
bean.v01 = new ArrayList(); | ||
bean.v02 = new ArrayList(); | ||
bean.v03 = new ArrayList(); | ||
bean.v04 = new ArrayList(); | ||
bean.v05 = new LinkedList(); | ||
bean.v06 = new CopyOnWriteArrayList(); | ||
|
||
String str = JSON.toJSONString(bean); | ||
Bean bean1 = JSON.parseObject(str, Bean.class); | ||
assertEquals(bean.v01, bean1.v01); | ||
assertEquals(bean.v02, bean1.v02); | ||
assertEquals(bean.v03, bean1.v03); | ||
assertEquals(bean.v04, bean1.v04); | ||
assertEquals(bean.v05, bean1.v05); | ||
assertEquals(bean.v06, bean1.v06); | ||
} | ||
|
||
@JSONCompiled | ||
public static class Bean { | ||
public Iterable v01; | ||
public Collection v02; | ||
public List v03; | ||
public ArrayList v04; | ||
public LinkedList v05; | ||
public CopyOnWriteArrayList v06; | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...est/src/test/java/com/alibaba/fastjson2/internal/processor/collections/JSONArrayTest.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,40 @@ | ||
package com.alibaba.fastjson2.internal.processor.collections; | ||
|
||
import com.alibaba.fastjson2.JSON; | ||
import com.alibaba.fastjson2.JSONArray; | ||
import com.alibaba.fastjson2.annotation.JSONCompiled; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class JSONArrayTest { | ||
@Test | ||
public void test() { | ||
Bean bean = new Bean(); | ||
bean.v01 = new JSONArray(); | ||
|
||
String str = JSON.toJSONString(bean); | ||
Bean bean1 = JSON.parseObject(str, Bean.class); | ||
assertEquals(bean.v01, bean1.v01); | ||
} | ||
|
||
@JSONCompiled | ||
public static class Bean { | ||
public JSONArray v01; | ||
} | ||
|
||
@Test | ||
public void test1() { | ||
Bean1 bean = new Bean1(); | ||
bean.v01 = new JSONArray(); | ||
|
||
String str = JSON.toJSONString(bean); | ||
Bean1 bean1 = JSON.parseObject(str, Bean1.class); | ||
assertEquals(bean.v01, bean1.v01); | ||
} | ||
|
||
@JSONCompiled(referenceDetect = false) | ||
public static class Bean1 { | ||
public JSONArray v01; | ||
} | ||
} |
89 changes: 89 additions & 0 deletions
89
codegen-test/src/test/java/com/alibaba/fastjson2/internal/processor/eishay/Image.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,89 @@ | ||
package com.alibaba.fastjson2.internal.processor.eishay; | ||
|
||
import com.alibaba.fastjson2.annotation.JSONCompiled; | ||
|
||
import java.util.Objects; | ||
|
||
@JSONCompiled(referenceDetect = false) | ||
public class Image | ||
implements java.io.Serializable { | ||
private static final long serialVersionUID = 1L; | ||
|
||
public enum Size { | ||
SMALL, LARGE | ||
} | ||
|
||
private int height; | ||
private Size size; | ||
private String title; // Can be null | ||
private String uri; | ||
private int width; | ||
|
||
public Image() { | ||
} | ||
|
||
public Image(String uri, String title, int width, int height, Size size) { | ||
this.height = height; | ||
this.title = title; | ||
this.uri = uri; | ||
this.width = width; | ||
this.size = size; | ||
} | ||
|
||
public void setUri(String uri) { | ||
this.uri = uri; | ||
} | ||
|
||
public void setTitle(String title) { | ||
this.title = title; | ||
} | ||
|
||
public void setWidth(int width) { | ||
this.width = width; | ||
} | ||
|
||
public void setHeight(int height) { | ||
this.height = height; | ||
} | ||
|
||
public void setSize(Size size) { | ||
this.size = size; | ||
} | ||
|
||
public String getUri() { | ||
return uri; | ||
} | ||
|
||
public String getTitle() { | ||
return title; | ||
} | ||
|
||
public int getWidth() { | ||
return width; | ||
} | ||
|
||
public int getHeight() { | ||
return height; | ||
} | ||
|
||
public Size getSize() { | ||
return size; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
Image image = (Image) o; | ||
return height == image.height && width == image.width && size == image.size && Objects.equals(title, image.title) && Objects.equals(uri, image.uri); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(height, size, title, uri, width); | ||
} | ||
} |
160 changes: 160 additions & 0 deletions
160
codegen-test/src/test/java/com/alibaba/fastjson2/internal/processor/eishay/Media.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,160 @@ | ||
package com.alibaba.fastjson2.internal.processor.eishay; | ||
|
||
import com.alibaba.fastjson2.annotation.JSONCompiled; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
@JSONCompiled(referenceDetect = false) | ||
public class Media | ||
implements java.io.Serializable { | ||
public enum Player { | ||
JAVA, FLASH | ||
} | ||
|
||
private int bitrate; | ||
private long duration; | ||
private String format; | ||
private int height; | ||
private List<String> persons; | ||
private Player player; | ||
private long size; | ||
private String title; | ||
private String uri; | ||
private int width; | ||
private String copyright; | ||
|
||
public Media() { | ||
} | ||
|
||
public Media( | ||
String uri, | ||
String title, | ||
int width, | ||
int height, | ||
String format, | ||
long duration, | ||
long size, | ||
int bitrate, | ||
List<String> persons, | ||
Player player, | ||
String copyright | ||
) { | ||
this.uri = uri; | ||
this.title = title; | ||
this.width = width; | ||
this.height = height; | ||
this.format = format; | ||
this.duration = duration; | ||
this.size = size; | ||
this.bitrate = bitrate; | ||
this.persons = persons; | ||
this.player = player; | ||
this.copyright = copyright; | ||
} | ||
|
||
public String getUri() { | ||
return uri; | ||
} | ||
|
||
public void setUri(String uri) { | ||
this.uri = uri; | ||
} | ||
|
||
public String getTitle() { | ||
return title; | ||
} | ||
|
||
public void setTitle(String title) { | ||
this.title = title; | ||
} | ||
|
||
public int getWidth() { | ||
return width; | ||
} | ||
|
||
public void setWidth(int width) { | ||
this.width = width; | ||
} | ||
|
||
public int getHeight() { | ||
return height; | ||
} | ||
|
||
public void setHeight(int height) { | ||
this.height = height; | ||
} | ||
|
||
public String getFormat() { | ||
return format; | ||
} | ||
|
||
public void setFormat(String format) { | ||
this.format = format; | ||
} | ||
|
||
public long getDuration() { | ||
return duration; | ||
} | ||
|
||
public void setDuration(long duration) { | ||
this.duration = duration; | ||
} | ||
|
||
public long getSize() { | ||
return size; | ||
} | ||
|
||
public void setSize(long size) { | ||
this.size = size; | ||
} | ||
|
||
public int getBitrate() { | ||
return bitrate; | ||
} | ||
|
||
public void setBitrate(int bitrate) { | ||
this.bitrate = bitrate; | ||
} | ||
|
||
public List<String> getPersons() { | ||
return persons; | ||
} | ||
|
||
public void setPersons(List<String> persons) { | ||
this.persons = persons; | ||
} | ||
|
||
public Player getPlayer() { | ||
return player; | ||
} | ||
|
||
public void setPlayer(Player player) { | ||
this.player = player; | ||
} | ||
|
||
public String getCopyright() { | ||
return copyright; | ||
} | ||
|
||
public void setCopyright(String copyright) { | ||
this.copyright = copyright; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
Media media = (Media) o; | ||
return bitrate == media.bitrate && duration == media.duration && height == media.height && size == media.size && width == media.width && Objects.equals(format, media.format) && Objects.equals(persons, media.persons) && player == media.player && Objects.equals(title, media.title) && Objects.equals(uri, media.uri) && Objects.equals(copyright, media.copyright); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(bitrate, duration, format, height, persons, player, size, title, uri, width, copyright); | ||
} | ||
} |
Oops, something went wrong.