-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathGsonTest.java
More file actions
43 lines (33 loc) · 1.22 KB
/
GsonTest.java
File metadata and controls
43 lines (33 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package com.sqltest.db;
import com.google.gson.*;
import com.sqltest.base.BaseTest;
import com.sqltest.model.UserInfo;
import com.sqltest.model.enums.*;
import io.github.cotide.dapper.Database;
import io.github.cotide.dapper.repository.inter.IRepository;
import org.junit.Test;
import sql2o.extensions.postgres.converters.JSONConverter;
import java.util.Date;
public class GsonTest extends BaseTest {
@Test
public void getByIdJson(){
Database db = getDatabase();
IRepository<UserInfo> userInfoIRepository = db.getRepository(UserInfo.class);
UserInfo userInfo = userInfoIRepository.getById(1);
System.out.println(new Gson().toJson(userInfo));
}
@Test
public void toJson(){
UserInfo domain = new UserInfo();
domain.setName("Test");
domain.setLogin(10086);
domain.setPwd("123456");
domain.setStatus(EnumUserStatus.NORMAL);
domain.setLevel(EnumVipLevel.VIP3);
domain.setGroup(EnumGroup.GROUP2);
domain.setCreateTime(new Date());
String json = JSONConverter.createGson().toJson(domain);
System.out.println(json);
UserInfo jsonObj = JSONConverter.createGson().fromJson(json,UserInfo.class);
}
}