Вопрос

I have designed the needed REST Service with JERSEY 1.5, using declared interface like:

@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public IMyDTO doIt(ICustomer customer) {
    return MySupport.createDTO(customer);
}

If i trying to call this service, using JERSEY 1.5 Client API, the following error occured:

Can not construct instance of test.ICustomer, problem: abstract types either need to be mapped to concrete types, have custom deserializer, or be instantiated with additional type information

Currently i specify such parameter by client:

ClientConfig clientConfig = new DefaultClientConfig();
clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, 
                                                               Boolean.TRUE);
Client client = Client.create(clientConfig);
WebResource webResource = client.resource(restResource);
ClientResponse response = webResource.path(restResourcePath)
                    .type(MediaType.APPLICATION_JSON)
                    .accept(MediaType.APPLICATION_JSON)
                    .post(ClientResponse.class, customer);
if (response != null) {
if (response.hasEntity()) {
result = response.getEntity(IMytDTO.class);
}
....

. The ICustomer and IMyDTO are java interfaces without any jackson annotation. The implementations have no jackson annotations too.

My Question: how to (de) serialize the objects , if REST Service (Client) are used?

I would not change the java interfaces and use the implementations on service and client side...

Нет правильного решения

Другие советы

If you're not willing to use a concrete class instead of an abstract class, I think you'll have to create a custom serializer and deserializer. A Jackson example is at:

http://blog.palominolabs.com/2012/06/05/writing-a-custom-jackson-serializer-and-deserializer/

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top