This discussion is archived
2 Replies Latest reply: Oct 27, 2013 3:15 PM by Leo_TA RSS

POF deserialisation - Map values

BretCalvey Newbie
Currently Being Moderated



I can sort of understand why this happens, but it has caught me out a few times.


I have an object that I want to pass to an Invocation Service (POF enabled) and this object has a "map" field...


private Map<String, Set<Object>> data;


When this is deserialised, the values in the map are not Sets, but instead com.tangosol.util.ImmutableArrayList$ListView


I assume this is a limitation of POF because it has no idea what sort of collection it needs to create for map values


The code below will produce a ClassCastException...


package test;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import com.tangosol.util.Binary;
import com.tangosol.util.ExternalizableHelper;
public class PofBug implements PortableObject {
  private Map<String, Set<Object>> data;
  public void readExternal(PofReader reader) throws IOException {
  data = reader.readMap(1, new HashMap<Object, Set<Object>>());
  public void writeExternal(PofWriter writer) throws IOException {
  writer.writeMap(1, data);
  public static void main(String[] args) {
  PofBug bug = new PofBug();
  Map<String, Set<Object>> testData = new HashMap<String, Set<Object>>();
  Set<Object> setOfStuff = new HashSet<Object>();
  testData.put("[KEY]", setOfStuff); = testData;
  Serializer serializer = new ConfigurablePofContext("/test/test-pof-config.xml");
  Binary bin = ExternalizableHelper.toBinary(bug, serializer);
  PofBug deserialised = (PofBug) ExternalizableHelper.fromBinary(bin, serializer);
  // BANG!!!
  Set<Object> mySet ="[KEY]");
  System.out.println("IT WORKED!!!! " + mySet);


The POF config is...


<pof-config xmlns:xsi=""
  xsi:schemaLocation=" coherence-pof-config.xsd">


I assume that the thing to do will be to manually write each entry (or wrap my Set<Object> values into another type)


Is this a known "feature"/"bug"?




  • Correct Answers - 10 points
  • Helpful Answers - 5 points