Java Code Examples for org.springframework.mock.http.MockHttpInputMessage

Following code examples demonstrate how to use org.springframework.mock.http.MockHttpInputMessagefrom spring-framework. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use org.springframework.mock.http.MockHttpInputMessageand various code implementation of this class.

  public static String toJson(String o, Class clasz, HttpMessageConverter<Object> mappingJackson2HttpMessageConverter) throws IOException {
    MockHttpOutputMessage mockHttpOutputMessage = new MockHttpOutputMessage();
    mappingJackson2HttpMessageConverter.read(clasz, new MockHttpInputMessage(o.getBytes()));
    return mockHttpOutputMessage.getBodyAsString();
  } 


    protected Object jsonToObject(String json, Class clazz) throws IOException {
        MockHttpInputMessage mockHttpInputMessage = new MockHttpInputMessage(json.getBytes());
        return this.mappingJackson2HttpMessageConverter.read(clazz, mockHttpInputMessage);
    } 

	public <T> T entity(byte[] contents, Class<T> clazz) throws Exception {
		MockHttpInputMessage message = new MockHttpInputMessage(contents);
		Object read = messageConverter.read(clazz, message);
		return clazz.cast(read);
	} 

Advertisement
Javadoc
Mock implementation of HttpInputMessage. @author Rossen Stoyanchev @since 3.2
Advertisement