Package com.aevans.test.web

Source Code of com.aevans.test.web.EndpointMessageConverter

package com.aevans.test.web;

import java.io.IOException;

import org.codehaus.jackson.JsonEncoding;
import org.codehaus.jackson.JsonGenerator;
import org.springframework.http.HttpOutputMessage;
import org.springframework.http.converter.HttpMessageNotWritableException;
import org.springframework.http.converter.json.MappingJacksonHttpMessageConverter;

public class EndpointMessageConverter extends MappingJacksonHttpMessageConverter{
 
 
  public EndpointMessageConverter() {
    super();
    this.setObjectMapper(new EndpointObjectMapper());
  }

  @Override
  protected void writeInternal(Object object, HttpOutputMessage outputMessage)
      throws IOException, HttpMessageNotWritableException {
   
    EndpointResponse<Object> resp = new EndpointResponse<>();
    resp.setResult(object);
    resp.setSuccess(true);
   
    JsonGenerator jsonGenerator =
        getObjectMapper().getJsonFactory().createJsonGenerator(outputMessage.getBody(),  JsonEncoding.UTF8);
   
    getObjectMapper().writerWithDefaultPrettyPrinter().writeValue(jsonGenerator, resp);
   
  }

 
}
TOP

Related Classes of com.aevans.test.web.EndpointMessageConverter

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.