Hard to be sure from what you've described, but it looks as though the
entity doesn't contain anything. Try getting the raw contents of the entity
in two places (1) before you post it and and (2) after you receive it but
before you parse it by passing it to the JacksonRepresentation constructor.
Does it look like valid JSON in both cases?

--tim


On Fri, Aug 8, 2014 at 5:13 PM, Alex Harvey <a...@9poundhammer.com> wrote:

> Hi,
>
> I'd like to be able to write some tests using JUnit to rest server
> resource classes. I'm encountering a problem when I try to pass a
> JacksonRepresentation in. My test class looks something a little like this:
>
> {
>         TransactionResource resource = new MyResource();
>         MyData data = new MyData(etc);
>
>         Representation entity = new JacksonRepresentation<MyData>(myData);
>
>         entity.setMediaType(MediaType.APPLICATION_JSON);
>
>         Representation response = resource.post(entity);
> }
>
> This is all fine as far as I know. But I receive an error in my
> ServerResource derived class when I try and deserialize the object using
> Jackson:
>
>             MyData myData = new JacksonRepresentation<>(entity,
> MyData.class)
>                     .getObject();
>
> com.fasterxml.jackson.databind.JsonMappingException: No content to map due
> to end-of-input
>  at [Source: UNKNOWN; line: 1, column: 1]
>         at
> com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:164)
>         at
> com.fasterxml.jackson.databind.ObjectReader._initForReading(ObjectReader.java:1298)
>         at
> com.fasterxml.jackson.databind.ObjectReader._bindAndClose(ObjectReader.java:1199)
>         at
> com.fasterxml.jackson.databind.ObjectReader.readValue(ObjectReader.java:798)
>         at
> org.restlet.ext.jackson.JacksonRepresentation.getObject(JacksonRepresentation.java:309)
>
> Is this the correct approach? Am I doing something wrong in my test case
> in setting up the call to my resource class?
>
> Thanks
>
> ------------------------------------------------------
>
> http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3086450
>

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3086540

Reply via email to