Search in sources :

Example 6 with NotSerializableException

use of java.io.NotSerializableException in project dubbo by alibaba.

the class AbstractSerializationPersionFailTest method test_PersonSet.

@Test
public void test_PersonSet() throws Exception {
    Set<Person> args = new HashSet<Person>();
    args.add(new Person());
    try {
        ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream);
        objectOutput.writeObject(args);
        fail();
    } catch (NotSerializableException expected) {
    } catch (IllegalStateException expected) {
        assertThat(expected.getMessage(), containsString("Serialized class com.alibaba.dubbo.common.model.Person must implement java.io.Serializable"));
    }
}
Also used : NotSerializableException(java.io.NotSerializableException) ObjectOutput(com.alibaba.dubbo.common.serialize.ObjectOutput) Person(com.alibaba.dubbo.common.model.Person) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 7 with NotSerializableException

use of java.io.NotSerializableException in project orientdb by orientechnologies.

the class TrackedMapTest method testMapSerialization.

/**
   * Test that {@link OTrackedMap} is serialised correctly.
   */
@Test
public void testMapSerialization() throws Exception {
    class NotSerializableDocument extends ODocument {

        private static final long serialVersionUID = 1L;

        private void writeObject(ObjectOutputStream oos) throws IOException {
            throw new NotSerializableException();
        }
    }
    final OTrackedMap<String> beforeSerialization = new OTrackedMap<String>(new NotSerializableDocument());
    beforeSerialization.put(0, "firstVal");
    beforeSerialization.put(1, "secondVal");
    final OMemoryStream memoryStream = new OMemoryStream();
    final ObjectOutputStream out = new ObjectOutputStream(memoryStream);
    out.writeObject(beforeSerialization);
    out.close();
    final ObjectInputStream input = new ObjectInputStream(new OMemoryInputStream(memoryStream.copy()));
    @SuppressWarnings("unchecked") final Map<Object, String> afterSerialization = (Map<Object, String>) input.readObject();
    Assert.assertEquals(afterSerialization.size(), beforeSerialization.size(), "Map size");
    for (int i = 0; i < afterSerialization.size(); i++) {
        Assert.assertEquals(afterSerialization.get(i), beforeSerialization.get(i));
    }
}
Also used : OMemoryInputStream(com.orientechnologies.orient.core.serialization.OMemoryInputStream) OMemoryStream(com.orientechnologies.orient.core.serialization.OMemoryStream) ObjectOutputStream(java.io.ObjectOutputStream) NotSerializableException(java.io.NotSerializableException) HashMap(java.util.HashMap) Map(java.util.Map) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) ObjectInputStream(java.io.ObjectInputStream) Test(org.testng.annotations.Test)

Example 8 with NotSerializableException

use of java.io.NotSerializableException in project robovm by robovm.

the class AnnotationTypeMismatchExceptionTest method testSerialization.

public void testSerialization() throws Exception {
    Method m = String.class.getMethod("length");
    AnnotationTypeMismatchException original = new AnnotationTypeMismatchException(m, "poop");
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    try {
        // AnnotationTypeMismatchException is broken: it's Serializable but has a non-transient
        // non-serializable field of type Method.
        new ObjectOutputStream(out).writeObject(original);
        fail();
    } catch (NotSerializableException expected) {
    }
}
Also used : NotSerializableException(java.io.NotSerializableException) Method(java.lang.reflect.Method) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) AnnotationTypeMismatchException(java.lang.annotation.AnnotationTypeMismatchException)

Example 9 with NotSerializableException

use of java.io.NotSerializableException in project spring-framework by spring-projects.

the class SerializationConverterTests method nonSerializableField.

@Test
public void nonSerializableField() {
    SerializingConverter toBytes = new SerializingConverter();
    try {
        toBytes.convert(new UnSerializable());
        fail("Expected SerializationFailureException");
    } catch (SerializationFailedException e) {
        assertNotNull(e.getCause());
        assertTrue(e.getCause() instanceof NotSerializableException);
    }
}
Also used : NotSerializableException(java.io.NotSerializableException) SerializingConverter(org.springframework.core.serializer.support.SerializingConverter) SerializationFailedException(org.springframework.core.serializer.support.SerializationFailedException) Test(org.junit.Test)

Example 10 with NotSerializableException

use of java.io.NotSerializableException in project j2objc by google.

the class AnnotationTypeMismatchExceptionTest method testSerialization.

public void testSerialization() throws Exception {
    Method m = String.class.getMethod("length");
    AnnotationTypeMismatchException original = new AnnotationTypeMismatchException(m, "poop");
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    try {
        // AnnotationTypeMismatchException is broken: it's Serializable but has a non-transient
        // non-serializable field of type Method.
        new ObjectOutputStream(out).writeObject(original);
        fail();
    } catch (NotSerializableException expected) {
    }
}
Also used : NotSerializableException(java.io.NotSerializableException) Method(java.lang.reflect.Method) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) AnnotationTypeMismatchException(java.lang.annotation.AnnotationTypeMismatchException)

Aggregations

NotSerializableException (java.io.NotSerializableException)39 ObjectOutputStream (java.io.ObjectOutputStream)14 IOException (java.io.IOException)13 ByteArrayOutputStream (java.io.ByteArrayOutputStream)9 ObjectInputStream (java.io.ObjectInputStream)9 Test (org.junit.Test)9 Person (com.alibaba.dubbo.common.model.Person)7 ObjectOutput (com.alibaba.dubbo.common.serialize.ObjectOutput)7 ArrayList (java.util.ArrayList)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 Serializable (java.io.Serializable)6 HashMap (java.util.HashMap)5 InvalidClassException (java.io.InvalidClassException)4 OptionalDataException (java.io.OptionalDataException)4 StreamCorruptedException (java.io.StreamCorruptedException)4 List (java.util.List)4 CancelException (org.apache.geode.CancelException)4 DistributedSystemDisconnectedException (org.apache.geode.distributed.DistributedSystemDisconnectedException)4 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)3 OMemoryInputStream (com.orientechnologies.orient.core.serialization.OMemoryInputStream)3