Class JcsSerializer

All Implemented Interfaces:
Function<Object,String>, ThrowingFunction<Object,String>, JsonMetaProvider, ArrayRecordWritable, RecordWritable, TokenWritable

public class JcsSerializer extends JsonSerializer
Serializes POJO models to canonical JSON per RFC 8785 (JCS).
Media types

Produces media type: application/jcs+json

Description

JCS (JSON Canonicalization Scheme) produces a deterministic, byte-for-byte canonical representation of JSON, enabling reliable cryptographic operations such as hashing and digital signing. All canonicalization rules are defined in RFC 8785.

  • No whitespace between tokens.
  • Object properties sorted by UTF-16 code unit order, applied recursively to all nested objects.
  • Numbers serialized using ECMAScript-compatible rules: shortest round-trip representation, no trailing zeros, lowercase e, positive exponent sign included (e.g. 1e+30).
  • Negative zero serialized as 0.
  • Non-ASCII characters emitted as literal UTF-8 bytes (no unnecessary unicode escape sequences).
  • Array element order is preserved (not sorted).
Example:

// Create a bean. MyBean bean = new MyBean().name("Alice").age(30); // Serialize to canonical JSON. String json = JcsSerializer.DEFAULT.write(bean); // Or use the Jcs marshaller convenience method. String json = Jcs.of(bean);

Example output (bean with name/age):

{"age":30,"name":"Alice"}

Example output with nested object:

{"address":{"city":"Denver","zip":"80201"},"name":"Alice"}

Notes:
See Also: