Reputation: 7650
public class UrlTemplate extends AbstractBeanDefinition implements Serializable {
private List<HeaderField> header = new ArrayList<>();
@Tag("header")
public List<HeaderField> getHeader() {
return this.header;
}
@Node("header/header-field")
public void setHeader(HeaderField headerField) {
this.header.add(headerField);
}
public void setHeader(List<HeaderField> header) {
this.header = header;
}
}
Tag
and Node
annotation are used by other library, and I can't change method setHeader(HeaderField headerField)
.
I define a valid setter setHeader(List<HeaderField> header)
for serializing, but when I try to serialize UrlTemplate
to String and deserialize String to UrlTemplate
, throw exception:
com.fasterxml.jackson.databind.JsonMappingException:
Conflicting setter definitions for property "header":
com.enniu.crawler.encreeper.core.domain.config.search.UrlTemplate#setHeader(1 params) vs
com.enniu.crawler.encreeper.core.domain.config.search.UrlTemplate#setHeader(1 params)
I think I may declare setHeader(List<HeaderField> header)
to be the setter that Jackson take to deserialize, but I have no idea about how to do it with the Jackson.
Could any one give me some hint?
Upvotes: 0
Views: 377
Reputation: 1386
Try using JsonProperty
annotation from jackson
@JsonProperty("header")
private Object headerJson;
public Object getHeaderJson() {
return status;
}
public void setHeaderJson(Object headerJson) {
this.headerJson= headerJson;
}
headerJson
will be mapped to json header
so it should resolve the conflict issue.
Upvotes: 1