mirror of
https://github.com/ZSCNetSupportDept/WechatTicketSystem.git
synced 2025-10-31 02:16:18 +08:00
oauth2 v2 update
This commit is contained in:
31
src/test/java/love/sola/netsupport/util/GsonTest.java
Normal file
31
src/test/java/love/sola/netsupport/util/GsonTest.java
Normal file
@@ -0,0 +1,31 @@
|
||||
package love.sola.netsupport.util;
|
||||
|
||||
import com.google.gson.*;
|
||||
import love.sola.netsupport.enums.ISP;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* ***********************************************
|
||||
* Created by Sola on 2015/12/2.
|
||||
* Don't modify this source without my agreement
|
||||
* ***********************************************
|
||||
*/
|
||||
public class GsonTest {
|
||||
|
||||
@Test
|
||||
public void testJsonDate() {
|
||||
Gson gson = new GsonBuilder()
|
||||
.registerTypeAdapter(Date.class, (JsonDeserializer<Date>) (json, typeOfT, context) -> new Date(json.getAsJsonPrimitive().getAsLong()))
|
||||
.registerTypeAdapter(Date.class, (JsonSerializer<Date>) (src, typeOfSrc, context) -> new JsonPrimitive(src.getTime()))
|
||||
.registerTypeAdapter(ISP.class, (JsonDeserializer<ISP>) (json, typeOfT, context) -> ISP.fromId(json.getAsJsonPrimitive().getAsInt()))
|
||||
.registerTypeAdapter(ISP.class, (JsonSerializer<ISP>) (src, typeOfSrc, context) -> new JsonPrimitive(src.id))
|
||||
.create();
|
||||
Date date = new Date();
|
||||
assert gson.fromJson(gson.toJson(date), Date.class).compareTo(date) == 0;
|
||||
assert gson.fromJson(gson.toJson(ISP.TELECOM), ISP.class) == ISP.TELECOM;
|
||||
assert gson.toJson(ISP.TELECOM).equals("1");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user