class

UCL::Encoder

Inherits Reference < Object

Serializes a Crystal object into a UCL/JSON/YAML/MsgPack string by building a libucl object tree and emitting it. Backs UCL.dump.

Constants

DEFAULT_EMITTER = "config"

Emitter used when none is given: "config" (UCL output).

EMITTERS = {"json" => UCL::LibUCL::Emitters::UCL_EMIT_JSON, "json_compact" => UCL::LibUCL::Emitters::UCL_EMIT_JSON_COMPACT, "config" => UCL::LibUCL::Emitters::UCL_EMIT_CONFIG, "yaml" => UCL::LibUCL::Emitters::UCL_EMIT_YAML, "msgpack" => UCL::LibUCL::Emitters::UCL_EMIT_MSGPACK}

Maps the emitter names accepted by .encode to their libucl counterparts.

Class methods

encode(object, emit_type : String | Emitter = DEFAULT_EMITTER) : String

Serializes object using emit_type, a typed UCL::Emitter or one of the legacy string keys of EMITTERS.

Raises UCL::Error::EncoderError for an unknown string emit_type, and UCL::Error::TypeError for a non-String hash key or an unsupported value type.

Source