Interface Json2StringConverter

All Known Implementing Classes:
PrettyStringConverter
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface Json2StringConverter

Implementations of this interface are required when formatting JSON structures in a predictable way prior to applying digital signatures. Logically identical JSON structures may have different signatures dependent on their formatting. RFC 7515 doesn't specify or reference a JSON canonicalization scheme although there exists one (RFC 8785). This is understandable since e.g. RFC 8785 applies a "bury the head in the sand" strategy when dealing with "Big Numbers", that is RFC 8785 explicitly forbids the serialization of "Big Numbers" by using the JSON number type without even saying what qualifies as "Big Number". Instead those "Big Numbers" must be wrapped using JSON strings without even specifying how this should be exactly done either. Needless to say that the ECMA standard 404 ("The JSON Data Interchange Syntax") doesn't forbid arbitrarily big numbers as JSON numbers. The internet draft "JSON Schema Validation: A Vocabulary for Structural Validation of JSON" explicitly states in section 4.2 "The JSON specification allows numbers with arbitrary precision, and JSON Schema does not add any such bounds."

Different line endings may lead to different signatures as well.

The Jakarta JSON Processing reference implementation (Eclipse Parsson) does print a JSON structure without any line breaks and spaces onto one line when invoking toString() but this is unspecified either. This distribution invokes indeed toString() prior to computing the signature if you don't explicitly specify a converter like the PrettyStringConverter.

Author:
Christof Reichardt
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    convert(jakarta.json.JsonStructure jsonStructure)
    Converts predictably the given JsonStructure into a string.
  • Method Details

    • convert

      String convert(jakarta.json.JsonStructure jsonStructure)
      Converts predictably the given JsonStructure into a string.
      Parameters:
      jsonStructure - the to be converted JsonStructure.
      Returns:
      a string representation of the given JsonStructure.