Skip to content

Commit

Permalink
Added test to show overriding the serializable type.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gray Watson committed Mar 28, 2013
1 parent 9d3bd4e commit 6a9e49b
Showing 1 changed file with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import java.io.ByteArrayOutputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.lang.reflect.Field;
import java.sql.SQLException;
import java.util.Collection;

import org.junit.Test;

Expand Down Expand Up @@ -153,6 +155,11 @@ public void testCoverage() {
new SerializableType(SqlType.SERIALIZABLE, new Class[0]);
}

@Test
public void testSerializedNotSerializable() throws Exception {
createDao(SerializedCollection.class, false);

This comment has been minimized.

Copy link
@j256

j256 Mar 28, 2013

Owner

This doesn't throw an exception so it worked.

}

/* ------------------------------------------------------------------------------------ */

@DatabaseTable(tableName = TABLE_NAME)
Expand Down Expand Up @@ -184,4 +191,35 @@ public SerializedField(String foo) {
this.foo = foo;
}
}

protected static class SerializedCollection {
public final static String SERIALIZED_FIELD_NAME = "serialized";
@DatabaseField(generatedId = true)
public int id;
@DatabaseField(columnName = SERIALIZED_FIELD_NAME, persisterClass = LocalSerializableType.class)
public Collection<String> serialized;
public SerializedCollection() {
}
}

protected static class LocalSerializableType extends SerializableType {

private static LocalSerializableType singleton;

public LocalSerializableType() {
super(SqlType.SERIALIZABLE, new Class<?>[0]);
}

public static LocalSerializableType getSingleton() {
if (singleton == null) {
singleton = new LocalSerializableType();
}
return singleton;
}

@Override
public boolean isValidForField(Field field) {
return Collection.class.isAssignableFrom(field.getType());
}
}
}

0 comments on commit 6a9e49b

Please sign in to comment.