APISonar


com.linecorp.armeria.common.MediaType.JSON

> com > linecorp > armeria > common > MediaType > JSON
com APIs linecorp APIs armeria APIs common APIs MediaType APIs JSON APIs

Example 1
public void testMapped() {
        final ContentPreviewerFactory factory = ContentPreviewerFactory.of(
                ContentPreviewerFactory.ofText(10, Charset.defaultCharset(), MediaType.JSON),
                ContentPreviewerFactory.ofText(20, Charset.defaultCharset(), MediaType.ANY_TEXT_TYPE),
                // shouldn't get those.
                ContentPreviewerFactory.ofText(30, Charset.defaultCharset(), MediaType.JSON),
                ContentPreviewerFactory.ofText(40, Charset.defaultCharset(), MediaType.JSON),
                ContentPreviewerFactory.ofText(50, Charset.defaultCharset(), MediaType.JSON),
                ContentPreviewerFactory.ofText(60, Charset.defaultCharset(), MediaType.JSON)
        );
        assertThat(((StringContentPreviewer) factory.get(ctx, textHeader)).length()).isEqualTo(20);
        assertThat(((StringContentPreviewer) factory.get(ctx, jsonHeader)).length()).isEqualTo(10);
    }
Example 2
void jsonTextToByteArray() throws Exception {
        when(req.contentType()).thenReturn(MediaType.JSON);
        when(req.content()).thenReturn(HttpData.ofUtf8(JSON_TEXT));

        final Object result = function.convertRequest(ctx, req, byte[].class);
        assertThat(result).isInstanceOf(byte[].class);
    }
Example 3
private JsonNode toJsonNode(AggregatedHttpRequest req) {
        final MediaType contentType = req.contentType();
        if (contentType != null && !contentType.is(MediaType.JSON)) {
            throw HttpStatusException.of(HttpStatus.UNSUPPORTED_MEDIA_TYPE);
        }

        final Charset charset = contentType == null ? StandardCharsets.UTF_8
                                                    : contentType.charset().orElse(StandardCharsets.UTF_8);
        try {
            return StandardCharsets.UTF_8.equals(charset) ? mapper.readTree(req.content().array())
                                                          : mapper.readTree(req.content(charset));
        } catch (IOException e) {
            throw HttpStatusException.of(HttpStatus.BAD_REQUEST);
        }
    }
Example 4
public void requestConverterOrder() throws Exception {
        final String body = "{\"foo\":\"bar\"}";
        final AggregatedHttpRequest aReq = AggregatedHttpRequest.of(
                HttpMethod.POST, "/1/requestConverterOrder", MediaType.JSON, body);

        final AggregatedHttpResponse aRes = executeRequest(aReq);

        assertThat(aRes.status()).isEqualTo(HttpStatus.OK);
        // Converted from the default converter which is JacksonRequestConverterFunction.
        assertThat(aRes.contentUtf8()).isEqualTo(body);

        // parameter level(+1) -> method level(+1) -> class level(+1) -> service level(+1) -> default
        assertThat(requestCounter.get()).isEqualTo(4);
    }