Java Setup
Fory Java provides binary Object Serialization, Fory JSON, Row Format, generated models, and Fory gRPC. Artifacts are published to Maven Central. Fory core and Fory JSON support Java 8 and later, Java Records require Java 17 or later, and Row Format requires Java 11 or later. Keep every Fory artifact in one application on the same version.
Verify the Toolchain
java -version
mvn -version
# or: ./gradlew --version
Object Serialization
Use Object Serialization for object graphs. Xlang mode produces data that other Fory implementations in other languages can read; native mode supports a broader JVM object surface.
Maven:
<dependency>
<groupId>org.apache.fory</groupId>
<artifactId>fory-core</artifactId>
<version>1.5.0</version>
</dependency>
Gradle:
implementation("org.apache.fory:fory-core:1.5.0")
Run this complete xlang round trip:
import org.apache.fory.Fory;
public final class ForyExample {
public static final class User {
public long id;
public String name;
public User() {}
public User(long id, String name) {
this.id = id;
this.name = name;
}
}
public static void main(String[] args) {
Fory fory = Fory.builder().withXlang(true).build();
fory.register(User.class, 1);
byte[] bytes = fory.serialize(new User(1, "Alice"));
User decoded = (User) fory.deserialize(bytes);
System.out.println(decoded.name);
}
}
Reuse a Fory instance within one thread instead of rebuilding it for every
value. Fory is not thread-safe; use ThreadSafeFory for shared concurrent
access. Continue with
Java Object Serialization,
xlang mode,
native mode, or
configuration.
Fory JSON
Fory JSON maps Java objects to standard JSON text and UTF-8 bytes. Add
fory-json instead of fory-core when the application only needs JSON:
implementation("org.apache.fory:fory-json:1.5.0")
Add the import to ForyExample.java:
import org.apache.fory.json.ForyJson;
Then place the JSON round trip inside ForyExample.main:
ForyJson json = ForyJson.builder().build();
String text = json.toJson(new User(1, "Alice"));
User jsonDecoded = json.fromJson(text, User.class);
System.out.println(jsonDecoded.name);
See Fory JSON Getting Started for Maven setup, object mapping, annotations, Android, GraalVM, and security.
Other Capabilities
- Row Format provides random and partial field access for trusted analytical data. See Java Row Format.
- Fory IDL and Compiler generates Java models and registration helpers from Fory IDL, protobuf IDL, or FlatBuffers IDL. See Compiler Getting Started and the Java generated-code guide.
- Fory gRPC uses normal grpc-java transports with Fory-encoded request and response objects. See Java gRPC.
Platform Notes
- On JDK 25 and later, follow the setup in Java Object Serialization.
- For Android, see Java Android support.
- For native images, see Java GraalVM support.