fastjson 在一个Pojo类中有两个date属性,JSON.toJSONString方法只能转换其中一个?

vq8itlhq  于 2021-11-27  发布在  Java
关注(0)|答案(3)|浏览(219)

Pojo类 User.java

public class User implements  Serializable{
    private static final long serialVersionUID = 1L; 

    private Long id; 

    private String username; 

    private String password; 

    private String phone; 

    private String email; 

    private Date created; 

    private Date updated; 

...(省略掉相关getter setter方法);

测试方法:

@Test
    public void getByTokenKeyTest(){
        String token="d9c37f9c-303b-4e42-895c-b9b97ff44cea";
        User user=userCache.getByTokenKey(token);
        System.out.println(user.toString());
        System.out.println(JSON.toJSONString(user));
    }

输出

//System.out.println(user.toString()) 输出 
User{id=222, username='Test', password='sdfafafaf', phone='135864545322', email='AAAA@AAAAA.AAAA', created=Tue Jul 18 10:43:31 CST 2017, updated=Tue Jul 18 10:43:31 CST 2017}

// System.out.println(JSON.toJSONString(user));
{"email":"AAAA@AAAAA.AAAA","id":222,"password":"sdfafafaf","phone":"135864545322","updated":1500345811648,"username":"Test"}

pom.xml

<dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
           <version>1.2.35</version>
        </dependency>
i86rm4rw

i86rm4rw1#

是不是只有一个有getter?

bvk5enib

bvk5enib2#

谢谢,经提醒检查了通过MyBatis自动代码生成的Getter,Setter的相关方法,发现created的getter方法错了。该方法被错误的声明为public Date getCreated(Date created)。

相关问题