1 48 49 package com.caucho.hessian.io; 50 51 import java.io.IOException ; 52 import java.util.ArrayList ; 53 import java.util.Collection ; 54 import java.util.Iterator ; 55 56 59 public class CollectionSerializer extends AbstractSerializer { 60 private boolean _sendJavaType = true; 61 62 65 public void setSendJavaType(boolean sendJavaType) 66 { 67 _sendJavaType = sendJavaType; 68 } 69 70 73 public boolean getSendJavaType() 74 { 75 return _sendJavaType; 76 } 77 78 79 public void writeObject(Object obj, AbstractHessianOutput out) 80 throws IOException 81 { 82 if (out.addRef(obj)) 83 return; 84 85 Collection list = (Collection ) obj; 86 87 Class cl = obj.getClass(); 88 boolean hasEnd; 89 90 if (cl.equals(ArrayList .class) || ! _sendJavaType) 91 hasEnd = out.writeListBegin(list.size(), null); 92 else 93 hasEnd = out.writeListBegin(list.size(), obj.getClass().getName()); 94 95 Iterator iter = list.iterator(); 96 while (iter.hasNext()) { 97 Object value = iter.next(); 98 99 out.writeObject(value); 100 } 101 102 if (hasEnd) 103 out.writeListEnd(); 104 } 105 } 106 | Popular Tags |