I have a json webservice I'm calling with a spring rest template. One of the request parameters is an interface. I'm looking for the right combination of annotations (either Jackson or Jaxb) that will create my json request.
My request needs to look like this:
{
"request": {
"specificAccountIdentifier": {
"field1" : "value",
"field2" : "value"
}
}
}
However, right now, it's marshaling as this:
{
"request": {
"accountIdentifier": {
"field1" : "value",
"field2" : "value"
}
}
}
Request Class:
@XmlRootElement
@XmlType
@XmlAccessorType(XmlAccessType.FIELD)
public class Request {
@XmlAnyElement
@XmlElementRefs({@XmlElementRef(type = SpecificAccountIdentifier.class)})
private AccountIdentifier accountIdentifier;
public Request() {
}
}
AccountIdentifier:
@XmlSeeAlso(SpecificAccountIdentifier.class)
public interface AccountIdentifier extends Serializable {
}
SpecificAccountIdentifier:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement
@XmlType
public class SpecificAccountIdentifier implements AccountIdentifier {
private static final long serialVersionUID = 8894475816041559L;
private Long field1;
private Long field2;
...class details...
}
I've tried a few different combinations of @JsonTypeInfo, but can't get anything to work right.
UPDATE:
Even after looking into the answer below, I still could not get anything to work, so I ended up just writing my own custom Serializer.