mirror of
https://github.com/ZSCNetSupportDept/WechatTicketSystem.git
synced 2025-10-29 16:14:16 +08:00
fix json date format
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
package love.sola.netsupport.wechat;
|
||||
|
||||
import com.google.gson.*;
|
||||
import love.sola.netsupport.config.Lang;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* ***********************************************
|
||||
* Created by Sola on 2015/12/2.
|
||||
@@ -16,4 +19,14 @@ public class TestMessageFormat {
|
||||
assert Lang.messages != null;
|
||||
}
|
||||
|
||||
@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()))
|
||||
.create();
|
||||
Date date = new Date();
|
||||
assert gson.fromJson(gson.toJson(date), Date.class).compareTo(date) == 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user