Serialize List Coherence Example

Serialize List Coherence Example

To serialize list object for Oracle coherence please use pofWriter.writeCollection and to deserialize use (List) pofReader.readCollection as example shows below:

To show complete example I will create Model then will serialize data:

  • JavaHonkModel.java:
import java.util.List;

public class JavaHonkModel {
	
	private List<String> list;

	public JavaHonkModel(List<String> list) {
		this.list = list;
	}

	public List<String> getList() {
		return list;
	}

	public void setList(List<String> list) {
		this.list = list;
	}	

}
  • SerializeList.java:
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import com.tangosol.io.pof.PofReader;
import com.tangosol.io.pof.PofSerializer;
import com.tangosol.io.pof.PofWriter;

public class SerializeList implements PofSerializer{
	
	@SuppressWarnings("unchecked")
	@Override
	public Object deserialize(PofReader pofReader) throws IOException {
		
		int count = 0;
		
		List<String> list = (List<String>) pofReader.readCollection(count++, new ArrayList<String>());	
		
		pofReader.readRemainder();
		
		return new JavaHonkModel(list);

	}

	@Override
	public void serialize(PofWriter pofWriter, Object o) throws IOException {
		
		JavaHonkModel JavaHonkModel = (JavaHonkModel) o;
		
		int count = 0;
		
		pofWriter.writeCollection(count++, JavaHonkModel.getList());
		
		pofWriter.writeRemainder(null);
		
	}
}

Reference:

Leave a Reply

Your email address will not be published. Required fields are marked *