Java Code Examples for org.springframework.http.MediaType#APPLICATION_JSON_UTF8

The following examples show how to use org.springframework.http.MediaType#APPLICATION_JSON_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: ProtobufHttpMessageConverterTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void writeJsonWithJavaFormat() throws IOException {
	this.converter = new ProtobufHttpMessageConverter(
			new ProtobufHttpMessageConverter.ProtobufJavaFormatSupport(),
			this.extensionRegistry);
	MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
	MediaType contentType = MediaType.APPLICATION_JSON_UTF8;
	this.converter.write(this.testMsg, contentType, outputMessage);

	assertEquals(contentType, outputMessage.getHeaders().getContentType());

	final String body = outputMessage.getBodyAsString(Charset.forName("UTF-8"));
	assertFalse("body is empty", body.isEmpty());

	Msg.Builder builder = Msg.newBuilder();
	JsonFormat.parser().merge(body, builder);
	assertEquals(this.testMsg, builder.build());

	assertNull(outputMessage.getHeaders().getFirst(
			ProtobufHttpMessageConverter.X_PROTOBUF_MESSAGE_HEADER));
	assertNull(outputMessage.getHeaders().getFirst(
			ProtobufHttpMessageConverter.X_PROTOBUF_SCHEMA_HEADER));
}
 
Example 2
Source File: ProtobufHttpMessageConverterTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void writeJsonWithGoogleProtobuf() throws IOException {
	this.converter = new ProtobufHttpMessageConverter(
			new ProtobufHttpMessageConverter.ProtobufJavaUtilSupport(null, null),
			this.extensionRegistry);
	MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
	MediaType contentType = MediaType.APPLICATION_JSON_UTF8;
	this.converter.write(this.testMsg, contentType, outputMessage);

	assertEquals(contentType, outputMessage.getHeaders().getContentType());

	final String body = outputMessage.getBodyAsString(Charset.forName("UTF-8"));
	assertFalse("body is empty", body.isEmpty());

	Msg.Builder builder = Msg.newBuilder();
	JsonFormat.parser().merge(body, builder);
	assertEquals(this.testMsg, builder.build());

	assertNull(outputMessage.getHeaders().getFirst(
			ProtobufHttpMessageConverter.X_PROTOBUF_MESSAGE_HEADER));
	assertNull(outputMessage.getHeaders().getFirst(
			ProtobufHttpMessageConverter.X_PROTOBUF_SCHEMA_HEADER));
}
 
Example 3
Source File: ProtobufHttpMessageConverterTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void writeJsonWithJavaFormat() throws IOException {
	this.converter = new ProtobufHttpMessageConverter(
			new ProtobufHttpMessageConverter.ProtobufJavaFormatSupport(),
			this.extensionRegistry);
	MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
	MediaType contentType = MediaType.APPLICATION_JSON_UTF8;
	this.converter.write(this.testMsg, contentType, outputMessage);

	assertEquals(contentType, outputMessage.getHeaders().getContentType());

	final String body = outputMessage.getBodyAsString(Charset.forName("UTF-8"));
	assertFalse("body is empty", body.isEmpty());

	Msg.Builder builder = Msg.newBuilder();
	JsonFormat.parser().merge(body, builder);
	assertEquals(this.testMsg, builder.build());

	assertNull(outputMessage.getHeaders().getFirst(
			ProtobufHttpMessageConverter.X_PROTOBUF_MESSAGE_HEADER));
	assertNull(outputMessage.getHeaders().getFirst(
			ProtobufHttpMessageConverter.X_PROTOBUF_SCHEMA_HEADER));
}
 
Example 4
Source File: SpringWebfluxApiExceptionHandlerUtils.java    From backstopper with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unused")
protected MediaType getErrorResponseContentType(
    DefaultErrorContractDTO errorContractDTO,
    int httpStatusCode,
    Collection<ApiError> rawFilteredApiErrors,
    Throwable originalException,
    RequestInfoForLogging request
) {
    // Default to simply application/json in UTF8.
    return MediaType.APPLICATION_JSON_UTF8;
}
 
Example 5
Source File: QuotesOnDesignConfiguration.java    From cloud-native-zwitscher with MIT License 4 votes vote down vote up
public QuoteOnDesignMessageConverter() {
    super(Jackson2ObjectMapperBuilder.json().build(),
            MediaType.APPLICATION_JSON_UTF8,
            new MediaType("text", "x-json", DEFAULT_CHARSET));
}
 
Example 6
Source File: GsonHttpMessageConverter.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
/**
 * Construct a new {@code GsonHttpMessageConverter}.
 */
public GsonHttpMessageConverter() {
	super(MediaType.APPLICATION_JSON_UTF8, new MediaType("application", "*+json", DEFAULT_CHARSET));
}
 
Example 7
Source File: FastjsonHttpMessageConverter.java    From java-platform with Apache License 2.0 4 votes vote down vote up
public FastjsonHttpMessageConverter(SerializeConfig serializeConfig, ParserConfig parserConfig) {
	super(MediaType.APPLICATION_JSON_UTF8, new MediaType("application", "*+json", DEFAULT_CHARSET));
	this.serializeConfig = serializeConfig;
	this.parserConfig = parserConfig;
}
 
Example 8
Source File: MappingJackson2HttpMessageConverter.java    From spring4-understanding with Apache License 2.0 2 votes vote down vote up
/**
 * Construct a new {@link MappingJackson2HttpMessageConverter} with a custom {@link ObjectMapper}.
 * You can use {@link Jackson2ObjectMapperBuilder} to build it easily.
 * @see Jackson2ObjectMapperBuilder#json()
 */
public MappingJackson2HttpMessageConverter(ObjectMapper objectMapper) {
	super(objectMapper, MediaType.APPLICATION_JSON_UTF8,
			new MediaType("application", "*+json", DEFAULT_CHARSET));
}