users@jersey.java.net

[Jersey] Fwd: pojo class problem in web mapping service (REDUCED)

From: Alberto Marqués <zerouno.dev_at_gmail.com>
Date: Tue, 2 Sep 2014 19:11:00 +0200

Nobody sees the error? or not done ?.

Can someone pass me an example of mapping a POJO class return an xml web
service in jersey.

Please follow and know I'm stuck with this.

---------- Forwarded message ----------
From: Alberto Marqués <zerouno.dev_at_gmail.com>
Date: 2014-08-31 13:42 GMT+02:00
Subject: pojo class problem in web mapping service (REDUCED)
To: users_at_jersey.java.net


Hi there,

It does not work the following service:



XML return

    <prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
    <order>
    <id>
    <![CDATA[ 1 ]]>
    </id>
    <date_add>
    <![CDATA[ 2014-08-22 16:26:15 ]]>
    </date_add>
    </order>
    </prestashop>

Class VO

    import org.eclipse.persistence.oxm.annotations.XmlCDATA;

    import javax.xml.bind.annotation.XmlRootElement;

    @XmlRootElement(name="prestashop")
    public class Pedido {

        @XmlCDATA public Integer id=null;
        @XmlCDATA public String date_add=null; //Fecha
creación

    }

Java client

    import java.net.URI;

    import javax.ws.rs.core.MediaType;
    import javax.ws.rs.core.UriBuilder;

    import com.sun.jersey.api.client.Client;
    import com.sun.jersey.api.client.ClientResponse;
    import com.sun.jersey.api.client.WebResource;
    import com.sun.jersey.api.client.config.ClientConfig;
    import com.sun.jersey.api.client.config.DefaultClientConfig;
    import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter;


    public class ClienteRest {
      public static void main(String[] args) {
        ClientConfig config = new DefaultClientConfig();
        Client client = Client.create(config);
        Pedido pedido = new Pedido();

        client.addFilter(new
HTTPBasicAuthFilter("WZWVR59997VL4BMKDV99C7GA1RBYGGBF", ""));

        WebResource service = client.resource(getBaseURI());
        // Get XML

System.out.println(service.path("orders").path("1").accept(MediaType.TEXT_XML).get(ClientResponse.class));
        ClientResponse response =
service.path("orders").path("1").accept(MediaType.TEXT_XML).get(ClientResponse.class);
        // Get XML for application
        Pedido oPedido = response.getEntity(pedido.getClass());

        System.out.println(oPedido.total_paid);

      }

      private static URI getBaseURI() {
        return UriBuilder.fromUri("
http://WZWVR59997VL4BMKDV99C7GA1RBYGGBF@example.com/api").build();
      }

    }

This is the output of java program

GET http://WZWVR59997VL4BMKDV99C7GA1RBYGGBF@example.com/api/orders/1
returned a response status of 200 OK
null

I want to recover the object class Order of XML does not work when
getEntity always returns null