module
RemiLib::RSConf::ArrayConverter(Converter)
Overview
Converter to be used with RemiLib::RSConf::Serializable
to serialize the elements of an Array(T) with the custom converter.
require "libremiliacr"
alias RSConf = RemiLib::RSConf
class TimestampArray
include RSConf::Serializable
@[RSConf::Field(converter: RSConf::ArrayConverter(Time::EpochConverter))]
property dates : Array(Time)
end
timestamp = TimestampArray.fromRsconf(%|"dates":[1459859781,1567628762]|)
puts timestamp.dates # => [2016-04-05 12:36:21 UTC, 2019-09-04 20:26:02 UTC]
puts timestamp.toRsconf
RemiLib::RSConf::ArrayConverter.new should be used if the nested converter
is also an instance instead of a type.
require "libremiliacr"
alias RSConf = RemiLib::RSConf
class TimestampArray
include RSconf::Serializable
@[RSConf::Field(converter: RSConf::ArrayConverter.new(Time::Format.new("%b %-d, %Y")))]
property dates : Array(Time)
end
timestamp = TimestampArray.fromRsconf(%|"dates":["Apr 5, 2016", "Sep 4, 2019"]|)
puts timestamp.dates # => [2016-04-05 00:00:00 UTC, 2019-09-04 00:00:00 UTC]
puts timestamp.toRsconf
This implies that RemiLib::RSConf::ArrayConverter(T) and
RemiLib::RSConf::ArrayConverter(T.class).new(T) perform the same
serializations.