Skip to main content

Fory v1.7.2 Released

· 4 min read
Shawn Yang
Apache Fory PMC Chair

The Apache Fory team is pleased to announce the 1.7.2 release. This patch release adds JSON property filtering and fixes serialization issues in Go, Java, and JavaScript. See Getting Started for installation instructions.

Highlights​

  • Java JSON can omit empty object properties.
  • Go thread-safe serialization retains type registrations after garbage collection clears cached instances.
  • Java compatible metadata cache hits skip redundant local metadata lookups.

Omit Empty JSON Properties​

Fory JSON 1.7.2 adds NON_EMPTY inclusion, allowing applications to leave empty properties out of JSON objects. Enable it for all properties with the builder:

import java.util.Collections;
import java.util.List;
import org.apache.fory.json.ForyJson;
import org.apache.fory.json.annotation.JsonProperty.Include;

public final class Response {
public String message = "";
public List<String> items = Collections.emptyList();
public int count = 0;
}

ForyJson json = ForyJson.builder().defaultPropertyInclusion(Include.NON_EMPTY).build();

assert json.toJson(new Response()).equals("{\"count\":0}");

The empty message and items properties are omitted, while count remains present. NON_EMPTY skips null values, zero-length strings and other CharSequence values, empty Java arrays, collections and maps, and absent JDK Optional values. Numeric zero and false are retained. Filtering is shallow: a nonempty list containing null or an empty list is still included.

To apply the rule to individual properties, use @JsonProperty:

import org.apache.fory.json.ForyJson;
import org.apache.fory.json.annotation.JsonProperty;

public final class Result {
@JsonProperty(include = JsonProperty.Include.NON_EMPTY)
public java.util.List<String> items;

@JsonProperty(include = JsonProperty.Include.ALWAYS)
public String nextPage;
}

ForyJson json = ForyJson.builder().build();

assert json.toJson(new Result()).equals("{\"nextPage\":null}");

Explicit property inclusion overrides the builder default. Here, items is omitted and nextPage is written even when null. The default remains NON_NULL; existing applications opt into empty-property filtering. defaultPropertyInclusion and writeNullFields change the same setting, so the last call wins.

Inclusion affects object-property writing only. It does not filter root values, collection elements, or Map entries, and it checks the logical value before calling a custom codec. Kotlin and Scala retain their reconstruction rules for constructor parameters; see the Kotlin guide and Scala guide. Full details are in the JSON annotations guide and builder configuration.

Go Thread-Safe Type Registration​

The Go threadsafe wrapper now preserves registrations when garbage collection reclaims cached instances. Register every type before the first serialization or deserialization operation: that first operation freezes registration, even if it fails. Later registration attempts return an error. For custom per-instance initialization, use NewWithFactory, returning a fresh, identically configured instance on each call. See the Go thread-safety guide.

Features and Improvements​

Bug Fixes​

  • Clear the JavaScript metadata string disposal list on writer reset — @ayush00git, #4015.
  • Allow JavaScript user type ID 0 in struct, extension, and enum factories — @ayush00git, #4014.
  • Preserve the TypeDef root kind for factory-created custom serializers — @Pigsy-Monk, #4022.
  • Correct JVM notices and C# license headers — @chaokunyang, #4026.
  • Respect declared element types when registering JavaScript root containers — @ayush00git, #4013.
  • Fix Go thread-safe pooling and remove Python lazy imports — @chaokunyang, #4027.

Other Improvements​

Full Changelog: v1.7.1...v1.7.2