Java Code Examples for com.fasterxml.jackson.core.JsonEncoding#UTF8

The following examples show how to use com.fasterxml.jackson.core.JsonEncoding#UTF8 . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MappingJackson2MessageConverter.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Determine the JSON encoding to use for the given content type.
 * @param contentType the MIME type from the MessageHeaders, if any
 * @return the JSON encoding to use (never {@code null})
 */
protected JsonEncoding getJsonEncoding(@Nullable MimeType contentType) {
	if (contentType != null && (contentType.getCharset() != null)) {
		Charset charset = contentType.getCharset();
		for (JsonEncoding encoding : JsonEncoding.values()) {
			if (charset.name().equals(encoding.getJavaName())) {
				return encoding;
			}
		}
	}
	return JsonEncoding.UTF8;
}
 
Example 2
Source File: AbstractJackson2HttpMessageConverter.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Determine the JSON encoding to use for the given content type.
 * @param contentType the media type as requested by the caller
 * @return the JSON encoding to use (never {@code null})
 */
protected JsonEncoding getJsonEncoding(@Nullable MediaType contentType) {
	if (contentType != null && contentType.getCharset() != null) {
		Charset charset = contentType.getCharset();
		for (JsonEncoding encoding : JsonEncoding.values()) {
			if (charset.name().equals(encoding.getJavaName())) {
				return encoding;
			}
		}
	}
	return JsonEncoding.UTF8;
}
 
Example 3
Source File: AbstractJackson2Encoder.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Determine the JSON encoding to use for the given mime type.
 * @param mimeType the mime type as requested by the caller
 * @return the JSON encoding to use (never {@code null})
 * @since 5.0.5
 */
protected JsonEncoding getJsonEncoding(@Nullable MimeType mimeType) {
	if (mimeType != null && mimeType.getCharset() != null) {
		Charset charset = mimeType.getCharset();
		for (JsonEncoding encoding : JsonEncoding.values()) {
			if (charset.name().equals(encoding.getJavaName())) {
				return encoding;
			}
		}
	}
	return JsonEncoding.UTF8;
}
 
Example 4
Source File: MappingJackson2MessageConverter.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Determine the JSON encoding to use for the given content type.
 * @param contentType the MIME type from the MessageHeaders, if any
 * @return the JSON encoding to use (never {@code null})
 */
protected JsonEncoding getJsonEncoding(@Nullable MimeType contentType) {
	if (contentType != null && (contentType.getCharset() != null)) {
		Charset charset = contentType.getCharset();
		for (JsonEncoding encoding : JsonEncoding.values()) {
			if (charset.name().equals(encoding.getJavaName())) {
				return encoding;
			}
		}
	}
	return JsonEncoding.UTF8;
}
 
Example 5
Source File: AbstractJackson2HttpMessageConverter.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Determine the JSON encoding to use for the given content type.
 * @param contentType the media type as requested by the caller
 * @return the JSON encoding to use (never {@code null})
 */
protected JsonEncoding getJsonEncoding(@Nullable MediaType contentType) {
	if (contentType != null && contentType.getCharset() != null) {
		Charset charset = contentType.getCharset();
		for (JsonEncoding encoding : JsonEncoding.values()) {
			if (charset.name().equals(encoding.getJavaName())) {
				return encoding;
			}
		}
	}
	return JsonEncoding.UTF8;
}
 
Example 6
Source File: AbstractJackson2Encoder.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Determine the JSON encoding to use for the given mime type.
 * @param mimeType the mime type as requested by the caller
 * @return the JSON encoding to use (never {@code null})
 * @since 5.0.5
 */
protected JsonEncoding getJsonEncoding(@Nullable MimeType mimeType) {
	if (mimeType != null && mimeType.getCharset() != null) {
		Charset charset = mimeType.getCharset();
		for (JsonEncoding encoding : JsonEncoding.values()) {
			if (charset.name().equals(encoding.getJavaName())) {
				return encoding;
			}
		}
	}
	return JsonEncoding.UTF8;
}
 
Example 7
Source File: AbstractJackson2HttpMessageConverter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Determine the JSON encoding to use for the given content type.
 * @param contentType the media type as requested by the caller
 * @return the JSON encoding to use (never {@code null})
 */
protected JsonEncoding getJsonEncoding(MediaType contentType) {
	if (contentType != null && contentType.getCharset() != null) {
		Charset charset = contentType.getCharset();
		for (JsonEncoding encoding : JsonEncoding.values()) {
			if (charset.name().equals(encoding.getJavaName())) {
				return encoding;
			}
		}
	}
	return JsonEncoding.UTF8;
}
 
Example 8
Source File: MappingJackson2MessageConverter.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Determine the JSON encoding to use for the given content type.
 * @param contentType the MIME type from the MessageHeaders, if any
 * @return the JSON encoding to use (never {@code null})
 */
protected JsonEncoding getJsonEncoding(MimeType contentType) {
	if ((contentType != null) && (contentType.getCharSet() != null)) {
		Charset charset = contentType.getCharSet();
		for (JsonEncoding encoding : JsonEncoding.values()) {
			if (charset.name().equals(encoding.getJavaName())) {
				return encoding;
			}
		}
	}
	return JsonEncoding.UTF8;
}
 
Example 9
Source File: AbstractJackson2HttpMessageConverter.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Determine the JSON encoding to use for the given content type.
 * @param contentType the media type as requested by the caller
 * @return the JSON encoding to use (never {@code null})
 */
protected JsonEncoding getJsonEncoding(MediaType contentType) {
	if (contentType != null && contentType.getCharSet() != null) {
		Charset charset = contentType.getCharSet();
		for (JsonEncoding encoding : JsonEncoding.values()) {
			if (charset.name().equals(encoding.getJavaName())) {
				return encoding;
			}
		}
	}
	return JsonEncoding.UTF8;
}
 
Example 10
Source File: MappingJacksonRPC2HttpMessageConverter.java    From jsonrpc4j with MIT License 5 votes vote down vote up
/**
 * Determine the JSON encoding to use for the given content type.
 *
 * @param contentType the media type as requested by the caller
 * @return the JSON encoding to use (never <code>null</code>)
 */
private JsonEncoding getJsonEncoding(MediaType contentType) {
	if (contentType != null && contentType.getCharset() != null) {
		Charset charset = contentType.getCharset();
		for (JsonEncoding encoding : JsonEncoding.values()) {
			if (charset.name().equals(encoding.getJavaName())) {
				return encoding;
			}
		}
	}
	return JsonEncoding.UTF8;
}
 
Example 11
Source File: HoconFactory.java    From jackson-dataformat-hocon with Apache License 2.0 5 votes vote down vote up
protected Reader _createReader(InputStream in, JsonEncoding enc, IOContext ctxt) throws IOException
{
    if (enc == null) {
        enc = JsonEncoding.UTF8;
    }
    // default to UTF-8 if encoding missing
    if (enc == JsonEncoding.UTF8) {
        boolean autoClose = ctxt.isResourceManaged() || isEnabled(JsonParser.Feature.AUTO_CLOSE_SOURCE);
        return new UTF8Reader(in, autoClose);
    }
    return new InputStreamReader(in, enc.getJavaName());
}
 
Example 12
Source File: HoconFactory.java    From jackson-dataformat-hocon with Apache License 2.0 5 votes vote down vote up
protected Reader _createReader(byte[] data, int offset, int len,
        JsonEncoding enc, IOContext ctxt) throws IOException
{
    if (enc == null) {
        enc = JsonEncoding.UTF8;
    }
    // default to UTF-8 if encoding missing
    if (enc == null || enc == JsonEncoding.UTF8) {
        return new UTF8Reader(data, offset, len, true);
    }
    ByteArrayInputStream in = new ByteArrayInputStream(data, offset, len);
    return new InputStreamReader(in, enc.getJavaName());
}
 
Example 13
Source File: MappingJacksonHttpMessageConverter.java    From android-viewer-for-khan-academy with GNU General Public License v3.0 5 votes vote down vote up
private JsonEncoding getEncoding(MediaType contentType) {
	if (contentType != null && contentType.getCharSet() != null) {
		Charset charset = contentType.getCharSet();
		for (JsonEncoding encoding : JsonEncoding.values()) {
			if (charset.name().equals(encoding.getJavaName())) {
				return encoding;
			}
		}
	}
	return JsonEncoding.UTF8;
}
 
Example 14
Source File: MessagePackFactoryTest.java    From jackson-dataformat-msgpack with Apache License 2.0 4 votes vote down vote up
@Test
public void testCreateGenerator() throws IOException {
    JsonEncoding enc = JsonEncoding.UTF8;
    JsonGenerator generator = factory.createGenerator(out, enc);
    assertEquals(MessagePackGenerator.class, generator.getClass());
}