Advertisement
Guest User

Untitled

a guest
Oct 18th, 2014
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.71 KB | None | 0 0
  1. package fst;
  2.  
  3. import static org.junit.Assert.*;
  4.  
  5. import java.io.IOException;
  6.  
  7. import org.junit.Test;
  8. import org.nustaq.serialization.FSTBasicObjectSerializer;
  9. import org.nustaq.serialization.FSTClazzInfo;
  10. import org.nustaq.serialization.FSTClazzInfo.FSTFieldInfo;
  11. import org.nustaq.serialization.FSTConfiguration;
  12. import org.nustaq.serialization.FSTObjectInput;
  13. import org.nustaq.serialization.FSTObjectOutput;
  14.  
  15. public class BugTest {
  16.  
  17.     @Test
  18.     public void testCustomSerializer() throws Exception {
  19.         FSTConfiguration FST = FSTConfiguration.createDefaultConfiguration();
  20.         //FST.setForceSerializable(true);
  21.         FST.registerSerializer(BugTest.NonSerializableClass.class, new Serializer(), false);
  22.         FSTObjectOutput out = FST.getObjectOutput();
  23.         out.writeObject(new BugTest.NonSerializableClass());
  24.        
  25.         FSTObjectInput in = FST.getObjectInput(out.getCopyOfWrittenBuffer());
  26.         assertEquals(NonSerializableClass.class, in.readObject().getClass());
  27.     }
  28.    
  29.     private static class Serializer extends FSTBasicObjectSerializer {
  30.  
  31.         @Override
  32.         public void writeObject(FSTObjectOutput out, Object toWrite,
  33.                 FSTClazzInfo clzInfo, FSTFieldInfo referencedBy,
  34.                 int streamPosition) throws IOException {
  35.             out.writeByte(0);
  36.         }
  37.  
  38.         @Override
  39.         public Object instantiate(Class objectClass, FSTObjectInput in,
  40.                 FSTClazzInfo serializationInfo, FSTFieldInfo referencee,
  41.                 int streamPosition) throws IOException,
  42.                 ClassNotFoundException, InstantiationException,
  43.                 IllegalAccessException {
  44.             Object o = new NonSerializableClass();
  45.             in.readByte();
  46.             in.registerObject(o, streamPosition, serializationInfo, referencee);
  47.             return o;
  48.         }
  49.        
  50.     }
  51.    
  52.     public static class NonSerializableClass {
  53.        
  54.     }
  55.    
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement