Skip to content
Java serialization library, proto compiler, code generator
Java Other
  1. Java 99.0%
  2. Other 1.0%
Branch: master
Clone or download

Latest commit

Latest commit 89ef89a May 24, 2020

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
protostuff-api 1.8.0-SNAPSHOT May 24, 2020
protostuff-benchmarks 1.8.0-SNAPSHOT May 24, 2020
protostuff-bom 1.8.0-SNAPSHOT May 24, 2020
protostuff-collectionschema preserve_null_elements support in derived/object schemas May 24, 2020
protostuff-compiler allow protostuff-runtime to work with java 9 and above May 24, 2020
protostuff-core 1.8.0-SNAPSHOT May 24, 2020
protostuff-it 1.8.0-SNAPSHOT May 24, 2020
protostuff-json 1.8.0-SNAPSHOT May 24, 2020
protostuff-kvp 1.8.0-SNAPSHOT May 24, 2020
protostuff-maven-plugin 1.8.0-SNAPSHOT May 24, 2020
protostuff-msgpack Merge pull request #278 from mirlord/jdk11 May 24, 2020
protostuff-parser 1.8.0-SNAPSHOT May 24, 2020
protostuff-runtime-md allow protostuff-runtime to work with java 9 and above May 24, 2020
protostuff-runtime-registry 1.8.0-SNAPSHOT May 24, 2020
protostuff-runtime-view 1.8.0-SNAPSHOT May 24, 2020
protostuff-runtime allow protostuff-runtime to work with java 9 and above May 24, 2020
protostuff-uberjar 1.8.0-SNAPSHOT May 24, 2020
protostuff-xml 1.8.0-SNAPSHOT May 24, 2020
protostuff-yaml 1.8.0-SNAPSHOT May 24, 2020
.gitignore Added intellij files to gitignore Feb 20, 2014
.travis.yml Enable Travis automatic build testing. Feb 21, 2014
CHANGELOG.md allow protostuff-runtime to work with java 9 and above May 24, 2020
CONTRIBUTORS.md Update readme formatting Nov 7, 2014
LICENSE.txt apache 2 license Sep 30, 2009
NOTICE.txt #148: Fix unsigned number serialization for JsonInput/JsonOutput Feb 1, 2016
README.md programmatic config May 24, 2020
pom.xml Merge pull request #278 from mirlord/jdk11 May 24, 2020
release.sh release script Oct 4, 2019
styleGuidelines.xml Reformat code Dec 14, 2014

README.md

Protostuff

A java serialization library with built-in support for forward-backward compatibility (schema evolution) and validation.

  • efficient, both in speed and memory
  • flexible, supporting pluggable formats

Usecase

  • messaging layer in RPC
  • storage format in the datastore or cache

For more information, go to https://protostuff.github.io/docs/

Maven

  1. For the core formats (protostuff, protobuf, graph)
<dependency>
  <groupId>io.protostuff</groupId>
  <artifactId>protostuff-core</artifactId>
  <version>1.7.2</version>
</dependency>
  1. For schemas generated at runtime
<dependency>
  <groupId>io.protostuff</groupId>
  <artifactId>protostuff-runtime</artifactId>
  <version>1.7.2</version>
</dependency>

Usage

public final class Foo
{
    String name;
    int id;
    
    public Foo(String name, int id)
    {
        this.name = name;
        this.id = id;
    }
}

static void roundTrip()
{
    Foo foo = new Foo("foo", 1);

    // this is lazily created and cached by RuntimeSchema
    // so its safe to call RuntimeSchema.getSchema(Foo.class) over and over
    // The getSchema method is also thread-safe
    Schema<Foo> schema = RuntimeSchema.getSchema(Foo.class);

    // Re-use (manage) this buffer to avoid allocating on every serialization
    LinkedBuffer buffer = LinkedBuffer.allocate(512);

    // ser
    final byte[] protostuff;
    try
    {
        protostuff = ProtostuffIOUtil.toByteArray(foo, schema, buffer);
    }
    finally
    {
        buffer.clear();
    }

    // deser
    Foo fooParsed = schema.newMessage();
    ProtostuffIOUtil.mergeFrom(protostuff, fooParsed, schema);
}

Important

If you are to purely use this to replace java serialization (no compatibility with protobuf), set the following system properties:

-Dprotostuff.runtime.always_use_sun_reflection_factory=true
-Dprotostuff.runtime.preserve_null_elements=true
-Dprotostuff.runtime.morph_collection_interfaces=true
-Dprotostuff.runtime.morph_map_interfaces=true
-Dprotostuff.runtime.morph_non_final_pojos=true

You can also customize it programmatically:

static final DefaultIdStrategy STRATEGY = new DefaultIdStrategy(IdStrategy.DEFAULT_FLAGS 
        | IdStrategy.PRESERVE_NULL_ELEMENTS,
        | IdStrategy.MORPH_COLLECTION_INTERFACES,
        | IdStrategy.MORPH_MAP_INTERFACES,
        | IdStrategy.MORPH_NON_FINAL_POJOS);

Use it:

Schema<Foo> schema = RuntimeSchema.getSchema(Foo.class, STRATEGY);

Questions/Concerns/Suggestions

Requirements

Java 1.6 or higher

Build Requirements

Maven 3.2.3 or higher

Developing with eclipse

mvn install && mvn eclipse:eclipse
# Open eclipse, import existing project, navigate to the protostuff module you're after, then hit 'Finish'.
You can’t perform that action at this time.