@Override public boolean isWriteable(Class<?> type, Type genericType, Annotation annotations[], MediaType mediaType) { return (type == c) && isSupported(mediaType); }
@Override protected final JAXBElement<?> readFrom(Class<?> type, MediaType mediaType, Unmarshaller unmarshaller, InputStream entityStream) throws JAXBException { final Charset c = getCharset(mediaType); return JettisonJaxbContext.getJSONUnmarshaller(unmarshaller) .unmarshalJAXBElementFromJSON(new InputStreamReader(entityStream, c), type); }
@Override protected final XMLStreamReader getXMLStreamReader(Class<?> elementType, MediaType mediaType, Unmarshaller u, InputStream entityStream) throws XMLStreamException { JettisonConfig c = JettisonConfig.DEFAULT; final Charset charset = getCharset(mediaType); if (u instanceof JettisonConfigured) { c = ((JettisonConfigured) u).getJSONConfiguration(); } return Stax2JettisonFactory.createReader(new InputStreamReader(entityStream, charset), c); } }
@Override protected final void writeTo(JAXBElement<?> t, MediaType mediaType, Charset c, Marshaller m, OutputStream entityStream) throws JAXBException { JettisonMarshaller jsonMarshaller = JettisonJaxbContext.getJSONMarshaller(m); if (isFormattedOutput()) { jsonMarshaller.setProperty(JettisonMarshaller.FORMATTED, true); } jsonMarshaller.marshallToJSON(t, new OutputStreamWriter(entityStream, c)); } }
@Override protected final Object readFrom(Class<Object> type, MediaType mediaType, Unmarshaller u, InputStream entityStream) throws JAXBException { final Charset c = getCharset(mediaType); return JettisonJaxbContext.getJSONUnmarshaller(u) .unmarshalFromJSON(new InputStreamReader(entityStream, c), type); }
@Override protected void writeTo(Object t, MediaType mediaType, Charset c, Marshaller m, OutputStream entityStream) throws JAXBException { JettisonMarshaller jsonMarshaller = JettisonJaxbContext.getJSONMarshaller(m); if (isFormattedOutput()) { jsonMarshaller.setProperty(JettisonMarshaller.FORMATTED, true); } jsonMarshaller.marshallToJSON(t, new OutputStreamWriter(entityStream, c)); } }
@Override public JSONArray readFrom( Class<JSONArray> type, Type genericType, Annotation annotations[], MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException { try { return new JSONArray(readFromAsString(entityStream, mediaType)); } catch (JSONException je) { throw new WebApplicationException( new Exception(LocalizationMessages.ERROR_PARSING_JSON_ARRAY(), je), 400); } }
@Override public JSONObject readFrom( Class<JSONObject> type, Type genericType, Annotation annotations[], MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException { try { return new JSONObject(readFromAsString(entityStream, mediaType)); } catch (JSONException je) { throw new WebApplicationException( new Exception(LocalizationMessages.ERROR_PARSING_JSON_OBJECT(), je), 400); } }
@Produces("*/*") @Consumes("*/*") public static final class General extends JettisonArrayProvider { @Override protected boolean isSupported(MediaType m) { return m.getSubtype().endsWith("+json"); } }
@Produces("*/*") @Consumes("*/*") public static final class General extends JettisonObjectProvider { @Override protected boolean isSupported(MediaType m) { return m.getSubtype().endsWith("+json"); } }
@Override public final void writeCollection(Class<?> elementType, Collection<?> t, MediaType mediaType, Charset c, Marshaller m, OutputStream entityStream) throws JAXBException, IOException { final OutputStreamWriter osw = new OutputStreamWriter(entityStream, c); JettisonConfig origJsonConfig = JettisonConfig.DEFAULT; if (m instanceof JettisonConfigured) { origJsonConfig = ((JettisonConfigured) m).getJSONConfiguration(); } final JettisonConfig unwrappingJsonConfig = JettisonConfig.createJSONConfiguration(origJsonConfig); final XMLStreamWriter jxsw = Stax2JettisonFactory.createWriter(osw, unwrappingJsonConfig); final String invisibleRootName = getRootElementName(elementType); try { jxsw.writeStartDocument(); jxsw.writeStartElement(invisibleRootName); for (Object o : t) { m.marshal(o, jxsw); } jxsw.writeEndElement(); jxsw.writeEndDocument(); jxsw.flush(); } catch (XMLStreamException ex) { Logger.getLogger(JettisonListElementProvider.class.getName()).log(Level.SEVERE, null, ex); throw new JAXBException(ex.getMessage(), ex); } }
@Override public boolean isReadable(Class<?> type, Type genericType, Annotation annotations[], MediaType mediaType) { return (type == c) && isSupported(mediaType); }
@Override protected final JAXBElement<?> readFrom(Class<?> type, MediaType mediaType, Unmarshaller unmarshaller, InputStream entityStream) throws JAXBException { final Charset c = getCharset(mediaType); return JettisonJaxbContext.getJSONUnmarshaller(unmarshaller) .unmarshalJAXBElementFromJSON(new InputStreamReader(entityStream, c), type); }
@Override protected final XMLStreamReader getXMLStreamReader(Class<?> elementType, MediaType mediaType, Unmarshaller u, InputStream entityStream) throws XMLStreamException { JettisonConfig c = JettisonConfig.DEFAULT; final Charset charset = getCharset(mediaType); if (u instanceof JettisonConfigured) { c = ((JettisonConfigured) u).getJSONConfiguration(); } return Stax2JettisonFactory.createReader(new InputStreamReader(entityStream, charset), c); } }
@Override protected final void writeTo(JAXBElement<?> t, MediaType mediaType, Charset c, Marshaller m, OutputStream entityStream) throws JAXBException { JettisonMarshaller jsonMarshaller = JettisonJaxbContext.getJSONMarshaller(m); if (isFormattedOutput()) { jsonMarshaller.setProperty(JettisonMarshaller.FORMATTED, true); } jsonMarshaller.marshallToJSON(t, new OutputStreamWriter(entityStream, c)); } }
@Override protected final Object readFrom(Class<Object> type, MediaType mediaType, Unmarshaller u, InputStream entityStream) throws JAXBException { final Charset c = getCharset(mediaType); return JettisonJaxbContext.getJSONUnmarshaller(u) .unmarshalFromJSON(new InputStreamReader(entityStream, c), type); }
@Override protected void writeTo(Object t, MediaType mediaType, Charset c, Marshaller m, OutputStream entityStream) throws JAXBException { JettisonMarshaller jsonMarshaller = JettisonJaxbContext.getJSONMarshaller(m); if (isFormattedOutput()) { jsonMarshaller.setProperty(JettisonMarshaller.FORMATTED, true); } jsonMarshaller.marshallToJSON(t, new OutputStreamWriter(entityStream, c)); } }
@Override public JSONArray readFrom( Class<JSONArray> type, Type genericType, Annotation annotations[], MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException { try { return new JSONArray(readFromAsString(entityStream, mediaType)); } catch (JSONException je) { throw new WebApplicationException( new Exception(LocalizationMessages.ERROR_PARSING_JSON_ARRAY(), je), 400); } }
@Override public boolean isWriteable(Class<?> type, Type genericType, Annotation annotations[], MediaType mediaType) { return (type == c) && isSupported(mediaType); }
@Override public boolean isReadable(Class<?> type, Type genericType, Annotation annotations[], MediaType mediaType) { return (type == c) && isSupported(mediaType); }