Package org.jboss.resteasy.plugins.providers.jaxb

Examples of org.jboss.resteasy.plugins.providers.jaxb.JAXBMarshalException


   public void writeTo(Object entry, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException
   {
      JAXBContextFinder finder = getFinder(mediaType);
      if (finder == null)
      {
         throw new JAXBMarshalException("Unable to find JAXBContext for media type: " + mediaType);
      }
      Class baseType = Types.getCollectionBaseType(type, genericType);
      entityStream.write('[');
      try
      {
         JAXBContext ctx = finder.findCachedContext(baseType, mediaType, annotations);
         Marshaller marshaller = ctx.createMarshaller();
         marshaller = AbstractJAXBProvider.decorateMarshaller(baseType, annotations, mediaType, marshaller);
         if (type.isArray())
         {
            Object[] array = (Object[]) entry;
            boolean first = true;
            for (Object obj : array)
            {
               if (first)
               {
                  first = false;
               }
               else
               {
                  entityStream.write(',');
               }
               marshaller.marshal(obj, entityStream);
            }
         }
         else
         {
            Collection collection = (Collection) entry;
            boolean first = true;
            for (Object obj : collection)
            {
               if (first)
               {
                  first = false;
               }
               else
               {
                  entityStream.write(',');
               }
               marshaller.marshal(obj, entityStream);
            }
         }
         entityStream.write(']');
      }
      catch (JAXBException e)
      {
         throw new JAXBMarshalException(e);
      }
   }
View Full Code Here


*/
public class JAXBMarshalExceptionMapperTest extends TestExceptionMapperBase {

    @Test
    public void handleExceptionWithoutResponse() {
        JAXBMarshalException nfe = new JAXBMarshalException("unacceptable");
        JAXBMarshalExceptionMapper nfem =
            injector.getInstance(JAXBMarshalExceptionMapper.class);
        Response r = nfem.toResponse(nfe);
        assertEquals(500, r.getStatus());
        verifyMessage(r, rtmsg("unacceptable"));
View Full Code Here

    @Test
    public void handleExceptionWithResponse() {
        Response mockr = mock(Response.class);
        when(mockr.getStatus()).thenReturn(500);
        JAXBMarshalException nfe = new JAXBMarshalException("unacceptable", mockr);
        JAXBMarshalExceptionMapper nfem =
            injector.getInstance(JAXBMarshalExceptionMapper.class);
        Response r = nfem.toResponse(nfe);
        assertEquals(500, r.getStatus());
        verifyMessage(r, rtmsg("unacceptable"));
View Full Code Here

TOP

Related Classes of org.jboss.resteasy.plugins.providers.jaxb.JAXBMarshalException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.