Class SerializationHelper
java.lang.Object
com.c4_soft.springaddons.test.support.web.SerializationHelper
Helps with HTTP requests body serialization using Spring registered message converters.
- Author:
- Jérôme Wacongne <ch4mp@c4-soft.com>
-
Constructor Summary
ConstructorsConstructorDescriptionSerializationHelper(org.springframework.beans.factory.ObjectFactory<org.springframework.boot.autoconfigure.http.HttpMessageConverters> messageConverters) -
Method Summary
Modifier and TypeMethodDescription<T> StringasJsonString(T payload) <T> StringasString(T payload, org.springframework.http.MediaType mediaType) Provides with a String representation of provided payload usingoutputMessage(Object, MediaType)<T> StringasXmlnString(T payload) outputMessage(T payload, org.springframework.http.MediaType mediaType) Serializes objects (request payloads) to any media-type using registered HTTP message converters.
-
Constructor Details
-
SerializationHelper
public SerializationHelper(org.springframework.beans.factory.ObjectFactory<org.springframework.boot.autoconfigure.http.HttpMessageConverters> messageConverters)
-
-
Method Details
-
outputMessage
public <T> ByteArrayHttpOutputMessage outputMessage(T payload, org.springframework.http.MediaType mediaType) Serializes objects (request payloads) to any media-type using registered HTTP message converters. Each acceptable converter (converter.canWrite(payload.getClass(), mediaType)return true) is tried until one actually succeeds at serializing.- Type Parameters:
T- payload type- Parameters:
payload- request body to serializemediaType- expected body media-type- Returns:
- serialized payload in JSON, XML, or whatever media-type an HttpMessageConverter is registered for
-
asString
Provides with a String representation of provided payload usingoutputMessage(Object, MediaType)- Type Parameters:
T- payload type- Parameters:
payload- request body to serializemediaType- expected body media-type- Returns:
- serialized payload in JSON, XML, or whatever media-type an HttpMessageConverter is registered for
-
asJsonString
-
asXmlnString
-