使用fastjson
导包
implementation 'com.alibaba:fastjson:1.2.78'
代码
@Test
void dtoEntityTest() {
UserDTO user = new UserDTO("1", new Date(System.currentTimeMillis()), "REMORK");
// dto转entity
UserEntity userEntity = JSON.parseObject(JSON.toJSONString(user), UserEntity.class);
// entity转dto
UserDTO userDTO = JSON.parseObject(JSON.toJSONString(userEntity), UserDTO.class);
}