3 Replies Latest reply on Jan 6, 2014 1:28 PM by Matt Parker

    Problem creating object after JAX-RS web service call

    Matt Parker Newbie

      I'm trying to call an Errai endpoint from a external process. While the service is triggered, the JSON data is not mapped to a object and the object is null within the service call.

       

      I was wondering if someone might point me in the right direction. I'm not sure what I doing wrong. Whether the JSON is formatted wrong or whether I don't have the right JAX-RS annotations.

       

      I'm make the JSON call with the following data and settings through Firefox's Poster plugin.

       

      [{"id":0, "unit":"Test Unit", "location":"Middle of no where", "jobRole":"Tester", "homeStation":"Town", "functionalAreas":"Test Development", "phoneNumber":"555-555-5555", "emailAddress":"test@test.com", "username":"noone", "latitude":32.4, "longitude":32.4}]

       

      I set the header parameter : Content:Type : application/json

      Specified the Content Type as: application/json

       

      Posted the data to http://localhost:8080/app/rest/persons

       

      I created a PersonObject to pass the data

       

      package com.gxm.servo.client.shared;


      import org.jboss.errai.common.client.api.annotations.Portable;

      import org.jboss.errai.databinding.client.api.Bindable;

      import org.jboss.errai.marshalling.client.api.annotations.MapsTo;

       

      @Portable

      @Bindable

      public class PersonDTO {

       

        long id;

        String fullName;

        String unit;

        String location;

        String jobRole;

        String homeStation;

        String functionalAreas;

        String imageUrl;

        String phoneNumber;

        String emailAddress;

        String username = "";

        double latitude;

        double longitude;

       

        public PersonDTO(

        @MapsTo("id") long id,

        @MapsTo("unit") String unit,

        @MapsTo("location") String location,

        @MapsTo("jobRole") String jobRole,

        @MapsTo("homeStation") String homeStation,

        @MapsTo("functionalAreas") String functionalAreas,

        @MapsTo("phoneNumber") String phoneNumber,

        @MapsTo("emailAddress") String emailAddress,

        @MapsTo("username") String username,

        @MapsTo("latitude") double latitude,

        @MapsTo("longitude") double longitude) {

       

        this.id = id;

        this.unit = unit;

        this.location = location;

        this.jobRole = jobRole;

        this.homeStation = homeStation;

        this.functionalAreas = functionalAreas;

        this.phoneNumber = phoneNumber;

        this.emailAddress = emailAddress;

        this.username = username;

        this.latitude = latitude;

        this.longitude = longitude;

       

        }

       

       

      [ public get/set methods here].....

       

      }

       

      I declared and implemented the Endpoint:

       

      @Path("/persons")

      public interface PersonEndpoint {

       

        @POST

        @Consumes(MediaType.APPLICATION_JSON)

        public Response create( PersonDTO entity);

       

        @PUT

        @Path("/{id:[0-9][0-9]*}")

        @Consumes(MediaType.APPLICATION_JSON)

        public Response update(@PathParam("id") Long id, PersonDTO entity);

       

        @DELETE

        @Path("/{id:[0-9][0-9]*}")

        public Response delete(@PathParam("id") Long id);

       

        @GET

        @Path("/{id}")

        @Produces(MediaType.APPLICATION_JSON)

        public Response retrieveById(@PathParam("id") long id);

       

      }

       

      TIA,

       

      Matt