-
Notifications
You must be signed in to change notification settings - Fork 0
GravSerializable
When building your application, you might run into the issue of serializing your own custom classes. The simplest way to do this is GravSerializable. Simply implement GravSerializable in your class and you are set.
public class Example implements GravSerializable {
// ...
@Override
public void serialize(GravSerializer serializer) {
// Write the information to be stored into serializer
}
// ...
}There are two ways to create the deserialization method.
- Constructor
public class Example implements GravSerializable {
// ...
public Example(GravSerializer serializer) {
// Load data from the serializer
}
// ...
}- Static deserialization method
public class Example implements GravSerializable {
// ...
public static Example deserialize(GravSerializer serializer) {
// Load data from the serializer and return Example instance
}
// ...
}Both are useful depending on the application. For example, if a class should have only a specific set of instances, but a reference to the class is required, then it is best using a static deserialization method to get an instance from a registry.
Sometimes reorganizing a project is necessary, and classes will be moved around, in these cases class names will change. To avoid issues with reading old data, remappings can be used. A remapping allows you to remap class or package names for deserialization. To remap a class/package simply add it to the relocationMappings map. Exact matches (classes) are handled first, then partial matches (packages). Note that matching code is very basic (replace matches).
Regular expression support may be added in the future.