Closed sacnl closed 7 years ago
The Android error message is:
Can not deserialize instance of .android.models.Contact$Array out of START_OBJECT token
Explicitly providing a ContextResolver such as the following produces the second kind of output, but also at /first
methods.
package de.wwu.md2.contacts.backend.ws;
import javax.ws.rs.Produces;
import javax.ws.rs.ext.ContextResolver;
import javax.ws.rs.ext.Provider;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import com.sun.jersey.api.json.JSONConfiguration;
import com.sun.jersey.api.json.JSONJAXBContext;
import de.wwu.md2.contacts.backend.models.Contact;
@Provider
@Produces("application/json")
public class JsonJaxbResolver implements ContextResolver<JAXBContext> {
@Override
public JAXBContext getContext(Class<?> type) {
JSONConfiguration.MappedBuilder b = JSONConfiguration.mapped();
b.arrays("contact");
try {
return new JSONJAXBContext(b.build(), Contact.class);
} catch (JAXBException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
}
This might be expected by clients of /first, but the Android ManyContentProvider is surprised and cannot parse the result, for example
{"contact":{"__internalId":"1","familyName":"Mustermann","givenName":"Max","phone":{"__internalId":"2","number":"012345-45321","kind":"0"},"dateOfBirth":"1985-01-01T00:00:00+01:00"}}
A client expecting a multi-valued return type (with an arbitrary number of entries, possibly also one), would expect the following:{"contact":[{"__internalId":"1","familyName":"Mustermann","givenName":"Max","phone":{"__internalId":"2","number":"012345-45321","kind":"0"},"dateOfBirth":"1985-01-01T00:00:00+01:00"}]}