fastjson toJsonString will invoke the target object method named "get*" with no args

pvabu6sv  于 2021-11-27  发布在  Java
关注(0)|答案(0)|浏览(206)

Fastjson version: 1.2.56

Description: When invoking the toJsonString method, the Fastjson will invoke the method named "get*" and with no args. I think the fastjson mistake the method as field get method.

For instance, I create two class,

`package com.shopee.idata;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**

  • @author john.geng
  • @Date 2019-04-10
  • @time 10:47

**/

@builder
@DaTa
@NoArgsConstructor
@AllArgsConstructor
public class TestGetMethod {

private Long id;

private String info;

public Long getAllInfo() {
return null;
}

public Long abc(){
return null;
}

public Long getInfo(Long id) {
return id;
}
}
`

`package com.shopee.idata;

import com.alibaba.fastjson.JSON;

/**

  • @author john.geng
  • @Date 2019-04-10
  • @time 10:48

**/

public class TestFastJsonMethodAsField {

public static void main(String[] args) {
TestGetMethod testGetMethod = new TestGetMethod();
testGetMethod.setId(10L);
System.out.println(JSON.toJSONString(testGetMethod));
}

}
`

when I run the main method, we can see,

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题