forked from alibaba/fastjson2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/alibaba/fastjson2 into main
- Loading branch information
Showing
20 changed files
with
417 additions
and
24 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
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
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
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
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
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
50 changes: 50 additions & 0 deletions
50
core/src/test/java/com/alibaba/fastjson2/annotation/UsingTest.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,50 @@ | ||
package com.alibaba.fastjson2.annotation; | ||
|
||
import com.alibaba.fastjson2.JSON; | ||
import com.alibaba.fastjson2.JSONReader; | ||
import com.alibaba.fastjson2.JSONWriter; | ||
import com.alibaba.fastjson2.reader.ObjectReader; | ||
import com.alibaba.fastjson2.writer.ObjectWriter; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.lang.reflect.Type; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class UsingTest { | ||
@Test | ||
public void test() { | ||
Bean bean = new Bean(); | ||
bean.id = 123; | ||
|
||
String str = JSON.toJSONString(bean); | ||
assertEquals("{\"id\":\"123元\"}", str); | ||
|
||
Bean bean1 = JSON.parseObject(str, Bean.class); | ||
assertEquals(bean.id, bean1.id); | ||
} | ||
|
||
public static class Bean { | ||
@JSONField(serializeUsing = IdCodec.class, deserializeUsing = IdCodec.class) | ||
public int id; | ||
} | ||
|
||
public static class IdCodec | ||
implements ObjectReader, ObjectWriter { | ||
public long getFeatures() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public Object readObject(JSONReader jsonReader, long features) { | ||
String str = jsonReader.readString(); | ||
str = str.replace("元", ""); | ||
return Integer.parseInt(str); | ||
} | ||
|
||
@Override | ||
public void write(JSONWriter jsonWriter, Object object, Object fieldName, Type fieldType, long features) { | ||
jsonWriter.writeString(object.toString() + "元"); | ||
} | ||
} | ||
} |
Oops, something went wrong.