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

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


      boolean backslash = false;

      int i = reader.read();
      char c = (char) i;
      StringBuffer buffer = new StringBuffer();
      if (c != '"') throw new JAXBUnmarshalException("Expecting '\"' in json map key");

      do
      {
         i = reader.read();
         if (i == -1) throw new JAXBUnmarshalException("Unexpected end of stream");
         c = (char) i;
         if (backslash)
         {
            buffer.append(c);
            backslash = false;
View Full Code Here


      char c;
      do
      {
         buffer.mark(2);
         i = buffer.read();
         if (i == -1) throw new JAXBUnmarshalException("Unexpected end of json input");
         c = (char) i;
      } while (Character.isWhitespace(c));
      if (reset) buffer.reset();
      return c;
   }
View Full Code Here

         reader = new BufferedReader(new InputStreamReader(entityStream));
      }


      char c = JsonParsing.eatWhitspace(reader, false);
      if (c != '{') throw new JAXBUnmarshalException("Expecting a json array as input");
      c = JsonParsing.eatWhitspace(reader, true);
      HashMap map = new HashMap();
      if (c != '}')
      {
         MessageBodyReader messageReader = providers.getMessageBodyReader(baseType, null, annotations, mediaType);

         do
         {
            String key = JsonParsing.getJsonString(reader);
            c = JsonParsing.eatWhitspace(reader, false);

            if (c != ':')
            {
               throw new JAXBUnmarshalException("Was expecting a ':' in json map");
            }

            c = JsonParsing.eatWhitspace(reader, true);

            String str = JsonParsing.extractJsonMapString(reader);
            ByteArrayInputStream stream = new ByteArrayInputStream(str.getBytes());
            Object obj = messageReader.readFrom(baseType, null, annotations, mediaType, httpHeaders, stream);
            map.put(key, obj);

            c = JsonParsing.eatWhitspace(reader, false);

            if (c == '}') break;

            if (c != ',')
            {
               throw new JAXBUnmarshalException("Was expecting a ',' in json array");
            }
            c = JsonParsing.eatWhitspace(reader, true);
         } while (c != -1);
      }
      return map;
View Full Code Here

         reader = new BufferedReader(new InputStreamReader(entityStream));
      }


      char c = JsonParsing.eatWhitspace(reader, false);
      if (c != '[') throw new JAXBUnmarshalException("Expecting a json array as input");
      c = JsonParsing.eatWhitspace(reader, true);
      ArrayList list = new ArrayList();
      if (c != ']')
      {
         MessageBodyReader messageReader = providers.getMessageBodyReader(baseType, null, annotations, mediaType);

         do
         {
            String str = JsonParsing.extractJsonMapString(reader);
            ByteArrayInputStream stream = new ByteArrayInputStream(str.getBytes());
            Object obj = messageReader.readFrom(baseType, null, annotations, mediaType, httpHeaders, stream);
            list.add(obj);

            c = JsonParsing.eatWhitspace(reader, false);

            if (c == ']') break;

            if (c != ',')
            {
               throw new JAXBUnmarshalException("Was expecting a ',' in json array");
            }
            c = JsonParsing.eatWhitspace(reader, true);
         } while (c != -1);
      }


      if (type.isArray())
      {
         Object array = Array.newInstance(baseType, list.size());
         for (int i = 0; i < list.size(); i++)
         {
            Array.set(array, i, list.get(i));
         }
         return array;
      }
      else
      {
         Collection outCol = null;
         if (type.isInterface())
         {
            if (List.class.isAssignableFrom(type)) return list;
            else if (SortedSet.class.isAssignableFrom(type)) outCol = new TreeSet();
            else if (Set.class.isAssignableFrom(type)) outCol = new HashSet();
            else outCol = new ArrayList();
         }
         else
         {
            try
            {
               outCol = (Collection) type.newInstance();
            }
            catch (Exception e)
            {
               throw new JAXBUnmarshalException(e);
            }
         }
         outCol.addAll(list);
         return outCol;
      }
View Full Code Here

*/
public class JAXBUnmarshalExceptionMapperTest extends TestExceptionMapperBase {

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

    @Test
    public void handleExceptionWithResponse() {
        Response mockr = mock(Response.class);
        when(mockr.getStatus()).thenReturn(500);
        JAXBUnmarshalException nfe = new JAXBUnmarshalException("unacceptable", mockr);
        JAXBUnmarshalExceptionMapper nfem =
            injector.getInstance(JAXBUnmarshalExceptionMapper.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.JAXBUnmarshalException

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.