@Override
    public void filter(final ContainerRequestContext request,
            final ContainerResponseContext response) throws IOException {

        final MediaType type = response.getMediaType();
        if (type != null && !type.getParameters().containsKey(MediaType.CHARSET_PARAMETER)) {
            final MediaType typeWithCharset = type.withCharset(UTF_8);
            response.getHeaders().putSingle(HttpHeaders.CONTENT_TYPE, typeWithCharset);
        }
    }
@Test
    void testSetsCharsetEncoding() throws Exception {
        when(response.getMediaType()).thenReturn(MediaType.APPLICATION_JSON_TYPE);
        MultivaluedMap<String, Object> headers = new MultivaluedHashMap<>();
        headers.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_TYPE);
        when(response.getHeaders()).thenReturn(headers);

        charsetUtf8Filter.filter(request, response);

        assertThat((MediaType) headers.getFirst(HttpHeaders.CONTENT_TYPE))
            .isEqualTo(MediaType.valueOf("application/json;charset=UTF-8"));
    }