use of io.servicetalk.http.router.jersey.internal.SourceWrappers.SingleSource in project servicetalk by apple.
the class JacksonSerializerMessageBodyReaderWriter method readFrom.
@Override
public Object readFrom(final Class<Object> type, final Type genericType, final Annotation[] annotations, final MediaType mediaType, final MultivaluedMap<String, String> httpHeaders, final InputStream entityStream) throws WebApplicationException {
final boolean oldJacksonProviderPresent = providers.getContextResolver(JacksonSerializationProvider.class, mediaType) != null;
// FIXME 0.43 - Remove this branch when deprecation go away.
if (oldJacksonProviderPresent) {
return readFromOld(type, genericType, annotations, mediaType, httpHeaders, entityStream);
} else {
final JacksonSerializerFactory serializerFactory = getJacksonSerializerFactory(mediaType);
final ExecutionContext<?> executionContext = ctxRefProvider.get().get().executionContext();
final BufferAllocator allocator = executionContext.bufferAllocator();
final int contentLength = requestCtxProvider.get().getLength();
if (Single.class.isAssignableFrom(type)) {
return handleEntityStream(entityStream, allocator, (p, a) -> deserialize(p, serializerFactory.serializerDeserializer(getSourceClass(genericType)), contentLength, a), (is, a) -> new SingleSource<>(deserialize(toBufferPublisher(is, a), serializerFactory.serializerDeserializer(getSourceClass(genericType)), contentLength, a)));
} else if (Publisher.class.isAssignableFrom(type)) {
return handleEntityStream(entityStream, allocator, (p, a) -> serializerFactory.streamingSerializerDeserializer(getSourceClass(genericType)).deserialize(p, a), (is, a) -> new PublisherSource<>(serializerFactory.streamingSerializerDeserializer(getSourceClass(genericType)).deserialize(toBufferPublisher(is, a), a)));
}
return handleEntityStream(entityStream, allocator, (p, a) -> deserializeObject(p, serializerFactory.serializerDeserializer(type), contentLength, a), (is, a) -> deserializeObject(toBufferPublisher(is, a), serializerFactory.serializerDeserializer(type), contentLength, a));
}
}
use of io.servicetalk.http.router.jersey.internal.SourceWrappers.SingleSource in project servicetalk by apple.
the class JacksonSerializerMessageBodyReaderWriter method readFromOld.
// FIXME 0.43 - Remove this branch when deprecation go away.
@Deprecated
private Object readFromOld(final Class<Object> type, final Type genericType, final Annotation[] annotations, final MediaType mediaType, final MultivaluedMap<String, String> httpHeaders, final InputStream entityStream) throws WebApplicationException {
final io.servicetalk.serialization.api.Serializer serializer = getSerializer(mediaType);
final ExecutionContext<?> executionContext = ctxRefProvider.get().get().executionContext();
final BufferAllocator allocator = executionContext.bufferAllocator();
final int contentLength = requestCtxProvider.get().getLength();
if (Single.class.isAssignableFrom(type)) {
return handleEntityStream(entityStream, allocator, (p, a) -> deserializeOld(p, serializer, getSourceClass(genericType), contentLength, a), (is, a) -> new SingleSource<>(deserializeOld(toBufferPublisher(is, a), serializer, getSourceClass(genericType), contentLength, a)));
} else if (Publisher.class.isAssignableFrom(type)) {
return handleEntityStream(entityStream, allocator, (p, a) -> serializer.deserialize(p, getSourceClass(genericType)), (is, a) -> new PublisherSource<>(serializer.deserialize(toBufferPublisher(is, a), getSourceClass(genericType))));
}
return handleEntityStream(entityStream, allocator, (p, a) -> deserializeObjectOld(p, serializer, type, contentLength, a), (is, a) -> deserializeObjectOld(toBufferPublisher(is, a), serializer, type, contentLength, a));
}
Aggregations