HADOOP-15835. Reuse Object Mapper in KMSJSONWriter (jeagles)

This commit is contained in:
Jonathan Eagles 2018-10-10 10:32:43 -05:00
parent b170de8be5
commit 2b6d8c1e29
1 changed files with 4 additions and 3 deletions

View File

@ -18,7 +18,7 @@
package org.apache.hadoop.crypto.key.kms.server; package org.apache.hadoop.crypto.key.kms.server;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.http.JettyUtils; import org.apache.hadoop.http.JettyUtils;
@ -46,6 +46,8 @@ import java.util.Map;
@Produces(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8) @Produces(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8)
@InterfaceAudience.Private @InterfaceAudience.Private
public class KMSJSONWriter implements MessageBodyWriter<Object> { public class KMSJSONWriter implements MessageBodyWriter<Object> {
private static final ObjectWriter WRITER =
new ObjectMapper().writerWithDefaultPrettyPrinter();
@Override @Override
public boolean isWriteable(Class<?> aClass, Type type, public boolean isWriteable(Class<?> aClass, Type type,
@ -67,8 +69,7 @@ public class KMSJSONWriter implements MessageBodyWriter<Object> {
OutputStream outputStream) throws IOException, WebApplicationException { OutputStream outputStream) throws IOException, WebApplicationException {
Writer writer = new OutputStreamWriter(outputStream, Charset Writer writer = new OutputStreamWriter(outputStream, Charset
.forName("UTF-8")); .forName("UTF-8"));
ObjectMapper jsonMapper = new ObjectMapper(); WRITER.writeValue(writer, obj);
jsonMapper.writerWithDefaultPrettyPrinter().writeValue(writer, obj);
} }
} }