Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package fst;
- import static org.junit.Assert.*;
- import java.io.IOException;
- import org.junit.Test;
- import org.nustaq.serialization.FSTBasicObjectSerializer;
- import org.nustaq.serialization.FSTClazzInfo;
- import org.nustaq.serialization.FSTClazzInfo.FSTFieldInfo;
- import org.nustaq.serialization.FSTConfiguration;
- import org.nustaq.serialization.FSTObjectInput;
- import org.nustaq.serialization.FSTObjectOutput;
- public class BugTest {
- @Test
- public void testCustomSerializer() throws Exception {
- FSTConfiguration FST = FSTConfiguration.createDefaultConfiguration();
- //FST.setForceSerializable(true);
- FST.registerSerializer(BugTest.NonSerializableClass.class, new Serializer(), false);
- FSTObjectOutput out = FST.getObjectOutput();
- out.writeObject(new BugTest.NonSerializableClass());
- FSTObjectInput in = FST.getObjectInput(out.getCopyOfWrittenBuffer());
- assertEquals(NonSerializableClass.class, in.readObject().getClass());
- }
- private static class Serializer extends FSTBasicObjectSerializer {
- @Override
- public void writeObject(FSTObjectOutput out, Object toWrite,
- FSTClazzInfo clzInfo, FSTFieldInfo referencedBy,
- int streamPosition) throws IOException {
- out.writeByte(0);
- }
- @Override
- public Object instantiate(Class objectClass, FSTObjectInput in,
- FSTClazzInfo serializationInfo, FSTFieldInfo referencee,
- int streamPosition) throws IOException,
- ClassNotFoundException, InstantiationException,
- IllegalAccessException {
- Object o = new NonSerializableClass();
- in.readByte();
- in.registerObject(o, streamPosition, serializationInfo, referencee);
- return o;
- }
- }
- public static class NonSerializableClass {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement