@TestComponent public class SerializationHelper extends Object
| Constructor and Description |
|---|
SerializationHelper(org.springframework.beans.factory.ObjectFactory<org.springframework.boot.autoconfigure.http.HttpMessageConverters> messageConverters) |
| Modifier and Type | Method and Description |
|---|---|
<T> String |
asJsonString(T payload) |
<T> String |
asString(T payload,
org.springframework.http.MediaType mediaType)
Provides with a String representation of provided payload using
outputMessage(Object, MediaType) |
<T> String |
asXmlnString(T payload) |
<T> ByteArrayHttpOutputMessage |
outputMessage(T payload,
org.springframework.http.MediaType mediaType)
Serializes objects (request payloads) to any media-type using registered HTTP message converters.
|
@Autowired public SerializationHelper(org.springframework.beans.factory.ObjectFactory<org.springframework.boot.autoconfigure.http.HttpMessageConverters> messageConverters)
public <T> ByteArrayHttpOutputMessage outputMessage(T payload, org.springframework.http.MediaType mediaType) throws Exception
converter.canWrite(payload.getClass(), mediaType) return true) is tried until one actually succeeds at
serializing.T - payload typepayload - request body to serializemediaType - expected body media-typeException - if no converter is found for requested media-type or if conversion goes wrongpublic <T> String asString(T payload, org.springframework.http.MediaType mediaType) throws Exception
outputMessage(Object, MediaType)T - payload typepayload - request body to serializemediaType - expected body media-typeException - if no converter is found for requested media-type or if conversion goes wrongCopyright © 2021. All rights reserved.