use of io.helidon.common.GenericType in project helidon by oracle.
the class JacksonBodyReaderTest method testDeserializeWithGenerics.
@Test
void testDeserializeWithGenerics() throws Exception {
JacksonBodyReader reader = JacksonBodyReader.create(new ObjectMapper());
DataChunk dataChunk = DataChunk.create("[{\"title\":\"The Stand\"}]".getBytes(StandardCharsets.UTF_8));
List<Book> books = reader.read(Single.just(dataChunk), new GenericType<List<Book>>() {
}, MessageBodyReaderContext.create()).get();
assertThat(books.size(), is(1));
assertThat(books.get(0), notNullValue());
}
use of io.helidon.common.GenericType in project helidon by oracle.
the class JsonbBodyStreamWriter method write.
@Override
public Multi<DataChunk> write(Flow.Publisher<?> publisher, GenericType<?> type, MessageBodyWriterContext context) {
MediaType contentType = context.findAccepted(MediaType.JSON_PREDICATE, MediaType.APPLICATION_JSON);
context.contentType(contentType);
AtomicBoolean first = new AtomicBoolean(true);
ObjectToChunks jsonToChunks = new ObjectToChunks(jsonb, context.charset());
return Multi.create(publisher).flatMap(jsonToChunks).flatMap(it -> {
if (first.getAndSet(false)) {
// first record, do not prepend a comma
return Multi.just(DataChunk.create(ARRAY_JSON_BEGIN_BYTES), it);
} else {
// any subsequent record starts with a comma
return Multi.just(DataChunk.create(COMMA_BYTES), it);
}
}).onCompleteResume(DataChunk.create(ARRAY_JSON_END_BYTES));
}
Aggregations