title: Java Setup sidebar_position: 1 id: java license: | Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
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.
java -version mvn -version # or: ./gradlew --version
Use Object Serialization for object graphs. Xlang mode produces data that other Fory runtimes 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 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.