Convert Figma logo to code with AI

RuedigerMoeller logofast-serialization

FST: fast java serialization drop in-replacement

1,580
248
1,580
120

Top Related Projects

6,166

Java binary serialization and cloning: fast, efficient, automatic

9,077

Main Portal page for the Jackson project

23,323

A Java serialization/deserialization library to convert Java Objects into JSON and back

25,732

FASTJSON 2.0.x has been released, faster and more secure, recommend you upgrade.

65,463

Protocol Buffers - Google's data interchange format

6,987

MessagePack is an extremely efficient object serialization library. It's like JSON, but very fast and small.

Quick Overview

The RuedigerMoeller/fast-serialization project is a high-performance Java serialization library that provides a fast and efficient way to serialize and deserialize Java objects. It aims to be a drop-in replacement for the built-in Java serialization mechanism, offering improved performance and reduced memory footprint.

Pros

  • Performance: The library is designed to be significantly faster than the built-in Java serialization, with benchmarks showing up to 10x improvement in serialization and deserialization speeds.
  • Memory Efficiency: The serialized data produced by the library is more compact, reducing memory usage and network bandwidth requirements.
  • Flexibility: The library supports a wide range of data types, including primitive types, arrays, collections, and custom objects.
  • Compatibility: The library is designed to be compatible with the built-in Java serialization, allowing for easy integration with existing systems.

Cons

  • Limited Documentation: The project's documentation could be more comprehensive, making it challenging for new users to get started.
  • Lack of Active Maintenance: The project appears to have limited active maintenance, with the last commit being over a year ago.
  • Potential Compatibility Issues: As the library is a replacement for the built-in Java serialization, there may be compatibility issues with certain applications or libraries that rely on the default serialization mechanism.
  • Learning Curve: The library has a slightly different API compared to the built-in Java serialization, which may require some effort to learn and integrate into existing projects.

Code Examples

Here are a few examples of how to use the fast-serialization library:

Serializing and Deserializing a Simple Object

import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.io.Input;
import com.esotericsoftware.kryo.io.Output;

public class Example {
    public static void main(String[] args) {
        Kryo kryo = new Kryo();
        MyObject obj = new MyObject("Hello, World!");

        // Serialize the object
        try (Output output = new Output(new FileOutputStream("object.bin"))) {
            kryo.writeObject(output, obj);
        }

        // Deserialize the object
        try (Input input = new Input(new FileInputStream("object.bin"))) {
            MyObject deserializedObj = kryo.readObject(input, MyObject.class);
            System.out.println(deserializedObj.getMessage());
        }
    }

    private static class MyObject {
        private final String message;

        public MyObject(String message) {
            this.message = message;
        }

        public String getMessage() {
            return message;
        }
    }
}

This example demonstrates how to use the Kryo serializer to serialize and deserialize a simple Java object.

Serializing and Deserializing a Collection

import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.io.Input;
import com.esotericsoftware.kryo.io.Output;

import java.util.ArrayList;
import java.util.List;

public class CollectionExample {
    public static void main(String[] args) {
        Kryo kryo = new Kryo();
        List<String> strings = new ArrayList<>();
        strings.add("apple");
        strings.add("banana");
        strings.add("cherry");

        // Serialize the list
        try (Output output = new Output(new FileOutputStream("strings.bin"))) {
            kryo.writeObject(output, strings);
        }

        // Deserialize the list
        try (Input input = new Input(new FileInputStream("strings.bin"))) {
            List<String> deserializedStrings = kryo.readObject(input, ArrayList.class);
            System.out.println(deserializedStrings);
        }
    }
}

This example demonstrates how to use the Kryo serializer to serialize and deserialize a list of strings.

Getting Started

To get started with the fast-serialization library, follow these steps:

  1. Add the library to your project's dependencies. If you're using Maven,

Competitor Comparisons

6,166

Java binary serialization and cloning: fast, efficient, automatic

Pros of Kryo

  • More flexible and customizable serialization process
  • Better support for complex object graphs and circular references
  • Wider community adoption and active development

Cons of Kryo

  • Slightly slower serialization and deserialization speed
  • Larger serialized output size in some cases
  • Steeper learning curve for advanced features

Code Comparison

Kryo:

Kryo kryo = new Kryo();
Output output = new Output(new FileOutputStream("file.bin"));
kryo.writeObject(output, someObject);
output.close();

fast-serialization:

FSTObjectOutput out = new FSTObjectOutput(new FileOutputStream("file.bin"));
out.writeObject(someObject);
out.close();

Both libraries offer similar ease of use for basic serialization tasks. Kryo provides more options for customization, while fast-serialization focuses on simplicity and performance.

Kryo's flexibility allows for fine-tuning of the serialization process, making it suitable for complex scenarios. fast-serialization, on the other hand, excels in raw performance and ease of use for straightforward serialization tasks.

When choosing between the two, consider your specific requirements regarding performance, flexibility, and the complexity of the objects you need to serialize.

9,077

Main Portal page for the Jackson project

Pros of Jackson

  • More comprehensive feature set, supporting a wide range of data formats beyond JSON
  • Extensive documentation and large community support
  • Better integration with other Java frameworks and libraries

Cons of Jackson

  • Generally slower serialization/deserialization performance compared to fast-serialization
  • More complex API, which can lead to a steeper learning curve
  • Larger library size, potentially increasing application footprint

Code Comparison

fast-serialization:

FSTConfiguration conf = FSTConfiguration.createDefaultConfiguration();
byte[] bytes = conf.asByteArray(object);
MyClass result = (MyClass) conf.asObject(bytes);

Jackson:

ObjectMapper mapper = new ObjectMapper();
byte[] bytes = mapper.writeValueAsBytes(object);
MyClass result = mapper.readValue(bytes, MyClass.class);

Both libraries offer straightforward serialization and deserialization methods, but Jackson's API is more verbose and requires explicit type information for deserialization. fast-serialization's API is simpler and doesn't require type information, but may be less type-safe as a result.

23,323

A Java serialization/deserialization library to convert Java Objects into JSON and back

Pros of gson

  • Widely adopted and well-maintained by Google
  • Simple and intuitive API for JSON serialization/deserialization
  • Extensive documentation and community support

Cons of gson

  • Generally slower performance compared to fast-serialization
  • Limited to JSON format, while fast-serialization supports multiple formats

Code Comparison

gson:

Gson gson = new Gson();
String json = gson.toJson(myObject);
MyClass obj = gson.fromJson(json, MyClass.class);

fast-serialization:

FSTConfiguration conf = FSTConfiguration.createDefaultConfiguration();
byte[] bytes = conf.asByteArray(myObject);
MyClass obj = (MyClass) conf.asObject(bytes);

fast-serialization offers a more compact binary format and faster serialization/deserialization, while gson provides a human-readable JSON format with a simpler API. The choice between the two depends on specific project requirements, such as performance needs, data format preferences, and integration with existing systems.

25,732

FASTJSON 2.0.x has been released, faster and more secure, recommend you upgrade.

Pros of fastjson

  • Higher performance for JSON parsing and serialization
  • More comprehensive support for JSON features and data types
  • Active development and frequent updates

Cons of fastjson

  • Larger library size compared to fast-serialization
  • More complex API with a steeper learning curve

Code Comparison

fastjson:

String jsonString = JSON.toJSONString(object);
MyObject obj = JSON.parseObject(jsonString, MyObject.class);

fast-serialization:

FSTConfiguration conf = FSTConfiguration.createDefaultConfiguration();
byte[] bytes = conf.asByteArray(object);
MyObject obj = (MyObject) conf.asObject(bytes);

Both libraries offer efficient serialization and deserialization, but fastjson focuses on JSON while fast-serialization is more general-purpose. fastjson provides a simpler API for JSON operations, while fast-serialization offers more flexibility for different serialization formats.

fastjson is better suited for projects heavily reliant on JSON processing, while fast-serialization may be preferable for applications requiring broader serialization support or smaller library footprint.

65,463

Protocol Buffers - Google's data interchange format

Pros of Protocol Buffers

  • Widely adopted and supported across multiple languages and platforms
  • Efficient binary serialization format, resulting in smaller message sizes
  • Strong schema definition and backward compatibility support

Cons of Protocol Buffers

  • Requires a separate schema definition file (.proto)
  • More complex setup and tooling compared to fast-serialization
  • Limited support for dynamic types and structures

Code Comparison

Protocol Buffers

syntax = "proto3";
message Person {
  string name = 1;
  int32 age = 2;
}

fast-serialization

public class Person implements Serializable {
    String name;
    int age;
}

Summary

Protocol Buffers offers a robust, cross-platform serialization solution with strong schema support and efficient encoding. However, it requires additional setup and tooling. fast-serialization provides a simpler, Java-focused approach with less overhead but may lack some of the advanced features and cross-language support offered by Protocol Buffers. The choice between the two depends on specific project requirements, such as language support, schema flexibility, and performance needs.

6,987

MessagePack is an extremely efficient object serialization library. It's like JSON, but very fast and small.

Pros of msgpack

  • Wider language support and ecosystem
  • More compact serialization format
  • Better performance for small data structures

Cons of msgpack

  • Less flexible type system
  • Slower for large, complex objects
  • Limited support for custom serialization

Code Comparison

msgpack:

MessagePack msgpack = new MessagePack();
byte[] raw = msgpack.write(someObject);
SomeObject deserialized = msgpack.read(raw, SomeObject.class);

fast-serialization:

FSTConfiguration conf = FSTConfiguration.createDefaultConfiguration();
byte[] bytes = conf.asByteArray(someObject);
SomeObject deserialized = (SomeObject) conf.asObject(bytes);

Key Differences

  • msgpack focuses on a compact, cross-language format
  • fast-serialization prioritizes speed for Java objects
  • msgpack has a simpler API but less flexibility
  • fast-serialization offers more customization options

Use Cases

msgpack is ideal for:

  • Cross-language communication
  • Scenarios where data size is critical

fast-serialization excels in:

  • High-performance Java-only environments
  • Complex object graphs with custom serialization needs

Both libraries aim to provide efficient serialization, but they target different priorities and use cases. The choice between them depends on specific project requirements and constraints.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

fast-serialization

  • up to 10 times faster 100% JDK Serialization compatible drop-in replacement (Ok, might be 99% ..). As an example: Lambda Serialization which came with 1.8 worked instantly.
  • Android compatible since version >= 2.17 (use FSTConfiguration.createAndroidDefaultConfiguration() both on server and client side. The configuration object has to be passed into FSTObjectIn/Output constructors)
  • OffHeap Maps, Persistent OffHeap maps
  • FSTStructs is very similar to IBM's packed objects. Difference is: You can run it with Oracle JDK today.
  • optionally en/decode any Serializable object graph to JSON (incl. shared references) (since 2.29) for interop
  • Apache 2.0 license since 2.17

Docs:

Fast JDK-compatible Serialization

Json Serialization

OffHeap + Persistent Maps

MinBin cross platform binary format

Kson: a JSon extension

mvn

note: maven.org might lag 1 day behind after releasing.

3.0.0 version (requires java 14, "--add-modules jdk.incubator.foreign" option on compiler and runtime)

<dependency>
    <groupId>de.ruedigermoeller</groupId>
    <artifactId>fst</artifactId>
    <version>3.0.1</version>
</dependency>

2.0 version (java 8)

<dependency>
    <groupId>de.ruedigermoeller</groupId>
    <artifactId>fst</artifactId>
    <version>2.56</version>
</dependency>

jdk1.6 compatible build of fst 2.x

<dependency>
    <groupId>de.ruedigermoeller</groupId>
    <artifactId>fst</artifactId>
    <version>2.48-jdk-6</version>
</dependency>

1.x version (different package name, 1.6 compatible ..). Fixes are not backported anymore, unsupported.

<dependency>
    <groupId>de.ruedigermoeller</groupId>
    <artifactId>fst</artifactId>
    <version>1.63</version>
</dependency>

Who uses FST ?

I am not actively tracking use, maven.org reports more than 14000 downloads from 6000 distinct IP accesses triggered by maven builds world wide per month.

Notable also:

  • used in production in Eurex Exchange's trading back end's middleware
  • JUptr.io's distributed system / NLP engine uses FST
  • Popular Apache Wicket supplementals use FST to speed up Wicket

alt tag

how to build

  • master contains dev branch/trunk.
  • 1.x contains old version
  • The maven build should work out of the box and reproduces the artifact hosted on maven.org
  • To use the gradle build, you need to configure the proxy server in settings.properties (or just set empty if you do not sit behind a proxy).

Note that instrumentation done for fst-structs works only if debug info is turned on during compile. Reason is that generating methods at runtime with javassist fails (probably a javassist bug ..). This does not affect the serialization implementation.

JDK 1.6 Build 1.x build since v1.62 are still jdk 6 compatible