Uploaded image for project: 'RESTEasy'
  1. RESTEasy
  2. RESTEASY-571

MessageBodyReader returns empty Collection for TreeSet<E>

    XMLWordPrintable

Details

    • Bug
    • Resolution: Won't Do
    • Major
    • 2.3-RC1
    • 2.2.1
    • jaxrs
    • None
    • Hide

      I have JUnit Test cases but not sure how the issue can be reproduced without the actual service. If required, I can jar up the Eclipse project.

      Show
      I have JUnit Test cases but not sure how the issue can be reproduced without the actual service. If required, I can jar up the Eclipse project.

    Description

      My service returns SortedSet<Movie>, where Movie is a JAXB annotated class. The resulting XML is given below.
      On the client side, I have a custom MessageBodyReader as given below. The issue is that the Unmarshaller always returns an empty TreeSet.

      MovieSetMessageBodyReader.java
          @SuppressWarnings("unchecked")
          @Override
          public TreeSet<Movie> readFrom(Class<TreeSet<Movie>> type,
      	    Type genericType, Annotation[] annotations, MediaType mediaType,
      	    MultivaluedMap<String, String> httpHeaders, InputStream entityStream)
      	    throws IOException, WebApplicationException {
      	Class<Movie> baseType = Types.getCollectionBaseType(type, genericType);
      
      	try {
      	    JAXBContext ctx = JAXBContext.newInstance(type, baseType);
      	    JAXBElement<?> element = ctx.createUnmarshaller().unmarshal(
      		    new StreamSource(entityStream), type);
      
      	    return (TreeSet<Movie>) element.getValue();
      	} catch (JAXBException e) {
      	    e.printStackTrace();
      	}
      
      	return null;
          }
      
      MovieServiceRestEasyClient.java
          @GET
          @Consumes("text/xml")
          public SortedSet<Movie> sendRequestByProxy() {
      	Map<String, Object> requestAttributes = new HashMap<String, Object>();
      	requestAttributes.put("path", path);
      
      	MovieServiceRestEasy proxy = ProxyFactory.create(
      		MovieServiceRestEasy.class, ENDPOINT, requestAttributes);
      	ClientResponse<TreeSet<Movie>> response = (ClientResponse<TreeSet<Movie>>) proxy
      		.getMovieSet(path);
      	return response.getEntity(TreeSet.class, (new GenericType<TreeSet<Movie>>() {}).getGenericType());
      
          }
      
      <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
      <collection>
      	<movie>		
      		<genre>Unknown</genre>
      		<name>4.3.2.1</name>
      		<year>2010</year>
      	</movie>
      	<movie>		
      		<genre>Unknown</genre>
      		<name>Battlestar Galactica The Plan</name>
      		<year>2009</year>
      	</movie>
      </collection>
      

      Attachments

        Activity

          People

            patriot1burke@gmail.com Bill Burke (Inactive)
            Abhi0123 Abhijit Sarkar (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: