Java中的getIdentifier()方法是否创建标识符字段?
在Java中,我有一个类,其中有一个公共的Java中的getIdentifier()方法是否创建标识符字段?,java,json,jackson,getter,Java,Json,Jackson,Getter,在Java中,我有一个类,其中有一个公共的getIdentifier()方法,该方法返回一个字符串。当我使用jackson序列化这个类的实例时,结果json字符串中会出现一个标识符字段。我的类中没有声明的identifier字段——只有getIdentifier函数。在Java中使用get@#%%()函数会自动创建名为@#%%的字段吗?还是Jackson可能在序列化对象时创建字段本身?有没有办法绕过这个问题 在Java中使用get@#%%函数会自动创建名为@#%%的字段吗?还是Jackson在序
getIdentifier()
方法,该方法返回一个字符串。当我使用jackson序列化这个类的实例时,结果json字符串中会出现一个标识符字段。我的类中没有声明的identifier
字段——只有getIdentifier
函数。在Java中使用get@#%%()
函数会自动创建名为@#%%的字段吗?还是Jackson可能在序列化对象时创建字段本身?有没有办法绕过这个问题
在Java中使用get@#%%函数会自动创建名为@#%%的字段吗?还是Jackson在序列化对象时可能会创建字段本身?有没有办法绕过这个问题
我可以保证,这不是Java的工作。Jackson是罪魁祸首,它将使用所有getter方法将对象序列化为JSON字符串。如果你不想要这个,你应该使用Jackson注释
public class Foo {
//my fields go here...
//getters for each field go here as well...
//now this method will be ignored for Jackson JSON serialization
@JsonIgnore
public String getIdentifier() {
//fancy code that returns an identifier
}
}