https://github.com/tsjensen/sercoll
Java Collections declared Serializable
https://github.com/tsjensen/sercoll
collections java serializable-objects serialization
Last synced: 3 months ago
JSON representation
Java Collections declared Serializable
- Host: GitHub
- URL: https://github.com/tsjensen/sercoll
- Owner: tsjensen
- License: apache-2.0
- Created: 2015-10-22T13:31:49.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2021-06-03T20:00:32.000Z (over 4 years ago)
- Last Synced: 2025-02-15T05:42:43.743Z (12 months ago)
- Topics: collections, java, serializable-objects, serialization
- Language: Java
- Homepage: http://tsjensen.github.io/sercoll/apidocs/latest/
- Size: 311 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/tsjensen/sercoll/actions/workflows/build.yml)
[](http://search.maven.org/#search%7Cgav%7C1%7Cg%3Acom.thomasjensen.sercoll)
# sercoll
**Java Collections declared Serializable**
This Java library provides one way to deal with the problem that Java collection interfaces are not declared serializable. Without *sercoll*, the following code will cause the FindBugs warning `Non-transient non-serializable instance field in serializable class` ([SE_BAD_FIELD](http://findbugs.sourceforge.net/bugDescriptions.html#SE_BAD_FIELD)):
```java
public class MyObject implements Serializable {
private static final long serialVersionUID = 1L;
private String foo;
private List strings; // FindBugs error
// ... snip ...
}
```
This is correct, because `List`, `Set`, `Map`, and other standard Java collection classes do not implement `Serializable`, as they cannot know whether their elements are serializable or not.
So, while [other solutions](http://stackoverflow.com/q/4861228/1005481) exist, such as using the concrete collection type, tricking the detector into not working for your class, or ignoring the warning, I believe the cleanest way is to make the declaration:
```java
public class MyObject implements Serializable {
private static final long serialVersionUID = 1L;
private String foo;
private SerializableList strings; // OK!
// ... snip ...
}
```
*Sercoll* provides the interfaces such as `SerializableList` that are directly derived from the JDK classes, but add the serializability declaration. In addition to that, the required supplementary code is provided to successfully use the new interfaces in practice with little to no refactoring effort.
## Prerequisites
*Sercoll* requires at least JDK 6. It has no dependencies on other libraries.
## Status
This is work in progress. *Sercoll* is not yet complete (some classes are missing), and also poorly tested as yet. This notice will be updated once *sercoll* has stabilized sufficiently to be ready for production use.
## Integration
*Sercoll* is distributed through [Maven Central](http://search.maven.org/#search|gav|1|g%3Acom.thomasjensen.sercoll), so you can just use it in your build. *Sercoll* uses [semantic versioning](http://semver.org/), so you can safely include the latest of a major version.
**Gradle:**
```groovy
dependencies {
compile group: 'com.thomasjensen.sercoll', name: 'sercoll', version: '0.+'
}
```
**Maven:**
```xml
com.thomasjensen.sercoll
sercoll
0.7.0
```
**Download:**
You can also [download](https://repo1.maven.org/maven2/com/thomasjensen/sercoll/sercoll/) the JAR manually, of course.
## Resources
[Javadoc](http://tsjensen.github.io/sercoll/apidocs/latest/)