I have an Order class and OrderDetail model as described below.  

class Order {
   long id;
   String description;
   Collection<OrderDetail> details;

   public Collection<OrderDetail> getDetails() {
         return details;
   }
  .... other methods
}

class OrderDetail {
    long id;
    String productId;
    String qty;

   ... methods here...
}

And I have a JSON string of one Order with nested collection of OrderDetail. 
And I am trying to de-serialize this json string into Order object and 
expecting that the Order object will now contain the OrderDetail collection 
also as expected. But it is not working as expected.

Here is the code snippet I have:

JacksonRepresentation<Order> jsonRepresentation = new 
JacksonRepresentation<Order>(representation, Order.class);
System.out.println(jsonRepresentation.getText()); // HERE IS THE CULPRIT
Order order = jsonRepresentation.getObject();  
Collection<OrderDetail> details = order.getDetails();

1) When I do jsonRepresentation.getObject(), it is throwing an exception.

 (java.io.EOFException) java.io.EOFException: No content to map to Object due 
to end of input

Why is that jsonRepresentation.getText(), causing the subsequent getObject to 
fail?

2) I have an extended Collection class called ForeignCollection, which is 
simply a subclass of Collection. In order to use ForeignCollection instead of 
Collection, what do I have to do in Restlet? I am getting the following error 
when I change Collection to ForeignCollection in the above two classes - Order 
and OrderDetail:

 (org.codehaus.jackson.map.JsonMappingException) 
org.codehaus.jackson.map.JsonMappingException: Can not find a deserializer for 
non-concrete Collection type [collection type; ForeignCollection, contains 
[simple type, class Order]

I am using Restlet 2.1.2.

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

Reply via email to