Package hydra.json

Interface Encode


  • public interface Encode
    JSON encoding for Hydra terms. Converts Terms to JSON Values using Either for error handling.
    • Method Detail

      • encodeFloat

        static <T0> Either<T0,​Value> encodeFloat​(FloatValue fv)
        Encode a float value to JSON. Finite values become JSON numbers (shortest round-trip); IEEE specials (NaN/Inf/-0.0) become JSON strings. Float32 and Float64 are symmetric; the schema disambiguates precision on decode.
      • encodeInteger

        static <T0> Either<T0,​Value> encodeInteger​(IntegerValue iv)
        Encode an integer value to JSON. Small ints use native numbers; large ints use strings.
      • encodeLiteral

        static <T0> Either<T0,​Value> encodeLiteral​(Literal lit)
        Encode a Hydra literal to a JSON value
      • requiresJsonStringSentinel

        static java.lang.Boolean requiresJsonStringSentinel​(java.lang.String s)
        True for IEEE sentinel strings that JSON must escape as a string to preserve.
      • toJson

        static Either<java.lang.String,​Value> toJson​(java.util.Map<Name,​Type> types,
                                                           java.lang.Boolean compactMaps,
                                                           Name tname,
                                                           Type typ,
                                                           Term term)
        Encode a Hydra term to a JSON value given a type and type name. Returns Left for unsupported constructs. The compactMaps flag enables the #624 compact object form for string-resolving map keys; it must be False for any caller that reads/writes the checked-in dist/json module-bootstrapping representation (moduleToJson, decodeModuleFromJson, verify-json-kernel), since that wire format is consumed by the published (pre-#624) host and must stay byte-stable. New callers encoding/decoding arbitrary values against a schema (e.g. hydra.build.format digests) may pass True.
      • toJsonUntyped

        static Either<java.lang.String,​Value> toJsonUntyped​(Term term)
        Encode a Hydra term to a JSON value without type information. Falls back to array-wrapped Maybe encoding.