A value that has already been serialized to JSON iodata, and encodes as those bytes wherever it appears.
TypeSafeAPI.evaluate_many/4 sends one question set with many states. Keeping
the questions as a TypeSafeAPI.JSON.OrderedObject would mean walking and
serializing the whole set once per request; wrapping it here serializes it
once, and every request body splices the same iodata in.
encoded = TypeSafeAPI.JSON.Encoded.new(TypeSafeAPI.JSON.OrderedObject.new([{"a", 1}]))
JSON.encode!(%{"questions" => encoded})
#=> ~s({"questions":{"a":1}})The original term is kept in object so callers can still read the
structure. The two are captured together at construction and never diverge,
because nothing modifies the struct afterwards.
Summary
Functions
Serializes object once and wraps it with its bytes.
The term that was encoded.
The cached JSON bytes, as a binary.