public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mt) { return isSupported(type, mt); }
@Override public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) { return !supportSimpleTypesOnly || primitiveHelper.isReadable(type, genericType, annotations, mediaType); }
@Override public void writeTo(T t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> headers, OutputStream os) throws IOException, WebApplicationException { if (!supportSimpleTypesOnly && !InjectionUtils.isPrimitive(type)) { @SuppressWarnings("unchecked") MessageBodyWriter<T> next = (MessageBodyWriter<T>)providers.getMessageBodyWriter(type, genericType, annotations, mediaType); JAXRSUtils.getCurrentMessage().put(ProviderFactory.ACTIVE_JAXRS_PROVIDER_KEY, this); try { next.writeTo(t, type, genericType, annotations, mediaType, headers, os); } finally { JAXRSUtils.getCurrentMessage().put(ProviderFactory.ACTIVE_JAXRS_PROVIDER_KEY, null); } } else { os.write(StringUtils.toBytesASCII("{\"" + type.getSimpleName().toLowerCase() + "\":")); writeQuote(os, type); primitiveHelper.writeTo(t, type, genericType, annotations, mediaType, headers, os); writeQuote(os, type); os.write(StringUtils.toBytesASCII("}")); } }
@Override public T readFrom(Class<T> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> headers, InputStream is) throws IOException, WebApplicationException { if (!supportSimpleTypesOnly && !InjectionUtils.isPrimitive(type)) { MessageBodyReader<T> next = providers.getMessageBodyReader(type, genericType, annotations, mediaType); JAXRSUtils.getCurrentMessage().put(ProviderFactory.ACTIVE_JAXRS_PROVIDER_KEY, this); try { return next.readFrom(type, genericType, annotations, mediaType, headers, is); } finally { JAXRSUtils.getCurrentMessage().put(ProviderFactory.ACTIVE_JAXRS_PROVIDER_KEY, null); } } String data = IOUtils.toString(is).trim(); int index = data.indexOf(':'); data = data.substring(index + 1, data.length() - 1).trim(); if (data.startsWith("\"")) { data = data.substring(1, data.length() - 1); } return primitiveHelper.readFrom(type, genericType, annotations, mediaType, headers, new ByteArrayInputStream(StringUtils.toBytesUTF8(data))); }
public T readFrom(Class<T> type, Type genType, Annotation[] anns, MediaType mt, MultivaluedMap<String, String> headers, InputStream is) throws IOException { String string = IOUtils.toString(is, HttpUtils.getEncoding(mt, StandardCharsets.UTF_8.name())); if (StringUtils.isEmpty(string)) { reportEmptyContentLength(); } if (type == Character.class) { char character = string.charAt(0); return type.cast(Character.valueOf(character)); } return InjectionUtils.handleParameter( string, false, type, genType, anns, ParameterType.REQUEST_BODY, null); }
protected static void initFactory(ProviderFactory factory) { // ensure to not load providers not available in a module environment if not needed factory.setProviders(false, false, new BinaryDataProvider<Object>(), new SourceProvider<Object>(), tryCreateInstance("org.apache.cxf.jaxrs.provider.DataSourceProvider"), new FormEncodingProvider<Object>(), new StringTextProvider(), new PrimitiveTextProvider<Object>(), tryCreateInstance(JAXB_PROVIDER_NAME), tryCreateInstance("org.apache.cxf.jaxrs.provider.JAXBElementTypedProvider"), tryCreateInstance("org.apache.cxf.jaxrs.provider.MultipartProvider")); Object prop = factory.getBus().getProperty("skip.default.json.provider.registration"); if (!PropertyUtils.isTrue(prop)) { factory.setProviders(false, false, createProvider(JSON_PROVIDER_NAME, factory.getBus())); } }
@Override public void writeTo(T t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> headers, OutputStream os) throws IOException, WebApplicationException { if (!supportSimpleTypesOnly && !InjectionUtils.isPrimitive(type)) { @SuppressWarnings("unchecked") MessageBodyWriter<T> next = (MessageBodyWriter<T>)providers.getMessageBodyWriter(type, genericType, annotations, mediaType); JAXRSUtils.getCurrentMessage().put(ProviderFactory.ACTIVE_JAXRS_PROVIDER_KEY, this); try { next.writeTo(t, type, genericType, annotations, mediaType, headers, os); } finally { JAXRSUtils.getCurrentMessage().put(ProviderFactory.ACTIVE_JAXRS_PROVIDER_KEY, null); } } else { os.write(StringUtils.toBytesASCII("{\"" + type.getSimpleName().toLowerCase() + "\":")); writeQuote(os, type); primitiveHelper.writeTo(t, type, genericType, annotations, mediaType, headers, os); writeQuote(os, type); os.write(StringUtils.toBytesASCII("}")); } }
@Override public T readFrom(Class<T> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> headers, InputStream is) throws IOException, WebApplicationException { if (!supportSimpleTypesOnly && !InjectionUtils.isPrimitive(type)) { MessageBodyReader<T> next = providers.getMessageBodyReader(type, genericType, annotations, mediaType); JAXRSUtils.getCurrentMessage().put(ProviderFactory.ACTIVE_JAXRS_PROVIDER_KEY, this); try { return next.readFrom(type, genericType, annotations, mediaType, headers, is); } finally { JAXRSUtils.getCurrentMessage().put(ProviderFactory.ACTIVE_JAXRS_PROVIDER_KEY, null); } } String data = IOUtils.toString(is).trim(); int index = data.indexOf(':'); data = data.substring(index + 1, data.length() - 1).trim(); if (data.startsWith("\"")) { data = data.substring(1, data.length() - 1); } return primitiveHelper.readFrom(type, genericType, annotations, mediaType, headers, new ByteArrayInputStream(StringUtils.toBytesUTF8(data))); }
public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mt) { return isSupported(type, mt); }
@Override public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) { return !supportSimpleTypesOnly || primitiveHelper.isReadable(type, genericType, annotations, mediaType); }
public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mt) { return isSupported(type); }
public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mt) { return isSupported(type); }