I am running a jersey server which when it receives a POST request of curl -X POST \
http://localhost:8080/ca/accountSettings \
-H 'Content-Type: application/json' \
-d '{
"socialAccountTypeId":"adqasocialaccount",
"imgUrl":"https://test.com/logo.png",
"descriptionDefault":"TEST Account",
"descriptionLangId":"EN",
"nameDefault":"Social Account",
"nameLangId":"en",
"types":["test"],
"credentialsType":"OAUTH_20",
"marketAssociation":[]
}'
the marketAssociation field is being unmarshalled as "marketAssociation:[""] and not an empty array as expected. Everything else is being umarshalled correctly.
I have tried initializing the marketAssociation array in the class to an empty array to no success.
API Route
@POST
@Path("/ca/accountSettings")
public Response addAccountSettings(SocialAccountType socialAccountType)
{
String endpoint = "POST /ca/accountSettings";
Response response = null;
try
{
WCResponse wcResponse = this.sssApi.addSocialAccountType(socialAccountType);
catch (Exception e)
{
TestApi.log.error("Exception in " + endpoint, e.getMessage());
response = response.error(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
}
}
The SocialAccountType class
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "SocialAccountType", propOrder = {
"socialAccountTypeId",
"imgUrl",
"descriptionDefault",
"descriptionLangId",
"nameDefault",
"nameLangId",
"types",
"credentialsType",
"marketAssociation",
"creationTime"
})
@XmlRootElement(name = "SocialAccountType")
public class SocialAccountType {
@XmlElement(required = true)
protected String socialAccountTypeId;
@XmlElement(required = true)
protected String imgUrl;
@XmlElement(required = true)
protected String descriptionDefault;
@XmlElement(required = true)
protected String descriptionLangId;
@XmlElement(required = true)
protected String nameDefault;
@XmlElement(required = true)
protected String nameLangId;
protected List<String> types;
@XmlElement(required = true)
protected CredentialsType credentialsType;
protected List<String> marketAssociation;
protected String creationTime;
}
There are getter and setter for the class but they are generic and I dont think are relevant.
I expect that the marketAssociation should simply be an empty array marketAssociation: [] and not marketAssociation:[""]
This is the custom JAXB context resolver I am using
@Provider
@Singleton
public class JAXBContextResolver implements ContextResolver<JAXBContext>
{
private JAXBContext context;
@SuppressWarnings("rawtypes")
private Class[] types = { Device.class, EndUser.class, SocialAccountType.class, SocialAccountTypeList.class };
public JAXBContextResolver() throws Exception
{
this.context = new JSONJAXBContext(JSONConfiguration
.mapped()
.arrays("userList", "deviceList", "roles", "socialAccountType", "marketAssociation", "types")
.build(), types);
}
@Override
@SuppressWarnings("rawtypes")
public JAXBContext getContext(Class<?> objectType)
{
for (Class c : types)
{
if (c.equals(objectType))
return (context);
}
return (null);
}
}