package org.rcsb.mmtf.serialization;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import org.msgpack.jackson.dataformat.MessagePackFactory;
import org.rcsb.mmtf.dataholders.MmtfStructure;

import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
 * A message pack implementation of the {@link MmtfStructure} serializer / deserializer.
 * @author Anthony Bradley
 *
 */
public class MessagePackSerialization implements MmtfStructureSerializationInterface {
	
	@Override
	public MmtfStructure deserialize(InputStream inputStream){
		MmtfStructure mmtfBean = null;
		try {
			mmtfBean = new ObjectMapper(new MessagePackFactory()).readValue(inputStream, MmtfStructure.class);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return mmtfBean;
	}
	
	@Override
	public void serialize(MmtfStructure mmtfStructure, OutputStream outputStream) {
		ObjectMapper objectMapper = new ObjectMapper(new MessagePackFactory());
		objectMapper.setSerializationInclusion(Include.NON_NULL);
		try {
			objectMapper.writeValue(outputStream, mmtfStructure);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}

@@ -554,16 +554,356 @@
 ace %7B%0A%09%0A
+%09private ObjectMapper objectMapper;%0A%09%0A%09/**%0A%09 * Constructor for the %7B@link MessagePackSerialization%7D class.%0A%09 * Generates %7B@link ObjectMapper%7D and sets to include non-null.%0A%09 */%0A%09public MessagePackSerialization() %7B%0A%09%09objectMapper = new ObjectMapper(new MessagePackFactory());%0A%09%09objectMapper.setSerializationInclusion(Include.NON_NULL);%0A%09%7D%0A%09%0A
 %09@Overri
@@ -1020,21 +1020,17 @@
 fBean = 
-new O
+o
 bjectMap
@@ -1036,34 +1036,8 @@
 pper
-(new MessagePackFactory())
 .rea
@@ -1254,142 +1254,8 @@
 ) %7B%0A
-%09%09ObjectMapper objectMapper = new ObjectMapper(new MessagePackFactory());%0A%09%09objectMapper.setSerializationInclusion(Include.NON_NULL);%0A
 %09%09tr

Update to the serialization module - only construct object mapper once.