Converter to be used with JSON::Serializable
to serialize the Array(T)
elements with the custom converter.
require "json" class TimestampArray include JSON::Serializable @[JSON::Field(converter: JSON::ArrayConverter(Time::EpochConverter))] property dates : Array(Time) end timestamp = TimestampArray.from_json(%({"dates":[1459859781,1567628762]})) timestamp.dates # => [2016-04-05 12:36:21 UTC, 2019-09-04 20:26:02 UTC] timestamp.to_json # => %({"dates":[1459859781,1567628762]})
© 2012–2020 Manas Technology Solutions.
Licensed under the Apache License, Version 2.0.
https://crystal-lang.org/api/0.35.1/JSON/ArrayConverter.html