|
| 1 | +# Java Serialization |
| 2 | + |
| 3 | +This project aims to create a low-latency serialization framework for Java. |
| 4 | + |
| 5 | +> [!CAUTION] |
| 6 | +> This framework is still very much work-in-progress. Non-experimental usage is not yet recommended. |
| 7 | +
|
| 8 | +### Example |
| 9 | + |
| 10 | +```java |
| 11 | +import java.nio.ByteBuffer; |
| 12 | + |
| 13 | +@Getter |
| 14 | +@Setter |
| 15 | +@SerializableType |
| 16 | +public class MyClass { |
| 17 | + |
| 18 | + private int someInteger; |
| 19 | + private boolean someBoolean; |
| 20 | + private String someString; |
| 21 | + |
| 22 | +} |
| 23 | + |
| 24 | +public static void main(String[] args) { |
| 25 | + final ByteBuffer buffer = ByteBuffer.allocateDirect(64); |
| 26 | + final Writer writer = new ByteBufferWriter(buffer); |
| 27 | + final Reader reader = new ByteBufferReader(buffer); |
| 28 | + |
| 29 | + final MyClass myObject = new MyClass(); |
| 30 | + myObject.setSomeInteger(123); |
| 31 | + myObject.setSomeBoolean(true); |
| 32 | + myObject.setSomestring("abc"); |
| 33 | + |
| 34 | + final MyClassSerializer serializer = new MyClassSerializer(); |
| 35 | + serializer.bind(writer).write(myObject); |
| 36 | + |
| 37 | + buffer.flip(); |
| 38 | + |
| 39 | + final MyClassDeserializer deserializer = new MyClassDeserializer(); |
| 40 | + final MyClass output = deserializer.bind(reader).read(new MyClass()); |
| 41 | +} |
| 42 | +``` |
| 43 | + |
| 44 | +For more examples see [here](/example/src/main/java/de/bethibande/serial/example/Main.java) |
| 45 | + |
| 46 | +### Type support |
| 47 | + |
| 48 | +- ✅ Fully supported |
| 49 | +- 💡Coming soon |
| 50 | +- ❌ Not yet supported |
| 51 | + |
| 52 | +| Type | Support | |
| 53 | +|--------------------------|---------| |
| 54 | +| Any primitive type | ✅ | |
| 55 | +| Any boxed primitive type | ✅ | |
| 56 | +| String / CharSequence | ✅ | |
| 57 | +| Any enum type | ✅ | |
| 58 | +| Arrays | ✅ | |
| 59 | +| Collections | 💡 | |
| 60 | +| Maps | 💡 | |
| 61 | +| Other serializable types | ❌ | |
| 62 | +| Java time types | ❌ | |
| 63 | + |
| 64 | +Please note that not null annotations are supported. Marking nullable fields as not nullable will omit null-checks, |
| 65 | +doing so can cause null pointer exceptions at runtime in the event that such a field does contain a null value. |
| 66 | +However, serializing/deserializing not nullable fields is faster. |
0 commit comments