I have inherited a certain bit code that has the @JsonProperty annotation on getter/setters. The purpose is so that when the object is serialized using the Jackson library, the fields have that specific name.
Current code:
private String fileName;
@JsonProperty("FILENAME")
public String getFileName()
{
return fileName;
}
@JsonProperty("FILENAME")
public void setFileName(String fileName)
{
this.fileName = fileName;
}
Now for another tool, I need to annotate the field with JsonProperty as well. So this will be my changed code:
@JsonProperty("FILENAME")
private String fileName;
@JsonProperty("FILENAME")
public String getFileName()
{
return fileName;
}
@JsonProperty("FILENAME")
public void setFileName(String fileName)
{
this.fileName = fileName;
}
Has anyone used this same annotation on both - the field as well as the getter/setters? I looked around on the net but didn't see anything.
I have compiled & run the code but I'm not sure if this would this cause any problems down the road. Any thoughts on this?
See Question&Answers more detail:os