Backend Development 13 min read

Fastjson DateFormat Priority and Circular Reference Issues: Debugging and Solutions

The article details a senior architect's investigation of Fastjson problems, including a date format priority bug that behaved differently on Windows and Linux due to an outdated library version, and a circular reference serialization issue resolved by disabling specific serializer features, while offering broader insights on version management and feature control.

Top Architect
Top Architect
Top Architect
Fastjson DateFormat Priority and Circular Reference Issues: Debugging and Solutions

The author, a senior architect, shares experiences with Fastjson issues encountered in a Java backend project, focusing on date format priority problems and circular reference handling.

DateFormat Priority Issue

When configuring a global date format yyyy-MM-dd HH:mmss and annotating a bean with @JSONField(format="yyyy-MM-dd") , the change worked locally but not in the Linux test environment, resulting in timestamps still containing time components.

Investigation involved simulating Linux via VM options, remote debugging, and inspecting JSONSerializer and its writeWithFormat method, eventually discovering that the test environment used an older Fastjson version ( 1.2.53 ) where the bug (issue #1868) was fixed only in version 1.2.72 .

Circular Reference ($ref) Issue

A sample method returns two lists, young and children , where both reference the same Person objects. Fastjson serializes the second reference as {"$ref":"$.result.young[1]"} , indicating circular reference detection.

The problem can be avoided by disabling the feature with SerializerFeature.DisableCircularReferenceDetect , though the author notes that the data does not actually contain a true circular reference.

Other Observations

Fastjson’s default features such as WriteMapNullValue and WriteNullListAsEmpty can affect API contracts, and users should have control over enabling them.

The author concludes that debugging Fastjson issues often starts with searching GitHub issues, and recommends upgrading to Fastjson 2 or newer versions for better maintenance.

BackendJavaSerializationdateformatfastjsonCircularReference
Top Architect
Written by

Top Architect

Top Architect focuses on sharing practical architecture knowledge, covering enterprise, system, website, large‑scale distributed, and high‑availability architectures, plus architecture adjustments using internet technologies. We welcome idea‑driven, sharing‑oriented architects to exchange and learn together.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.