MessageBodyReaderSupport for DTO Classes?

8 views
Skip to first unread message

confile

unread,
Nov 30, 2013, 9:57:42 AM11/30/13
to grails-jax...@googlegroups.com

I want to use the Grails-jaxrs plugin to implement a custom MessageBodyReaderSupport to read a UserDto class from a client.

How do I have to implement the UserDtoReader in order to get an instance of the UserDto?

This is my UserDto class:

public class UserDto {
    private String firstName;
    private String lastName;

    public UserDto() {
        firstName = "";
        lastName = "";
    }

    public UserDto(String firstName,
                   String lastName) {

        this.firstName = firstName;
        this.lastName = lastName;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }


    @Override
    public String toString() {
        String s = " { User ";
        s += "id=" + id + " ";
        s += "firstName=" + firstName + " ";
        s += "lastName=" + lastName + " ";
        s += " User } ";
        return s;
    }
}

This is my UserDtoReader class:

@Consumes("application/json")
class UserDtoReader extends MessageBodyReaderSupport<UserDto> {

    @Override
    public UserDto readFrom(MultivaluedMap<String, String> httpHeaders,
            InputStream entityStream) throws IOException,
            WebApplicationException {
        // TODO Auto-generated method stub
        return null;
    }
}
Reply all
Reply to author
Forward
0 new messages