The Crystal Programming Language Forum

Same common annotation instead of JSON::Field and YAML::Field

The JSON and YAML modules brings their own, very similar Field annotations.
When an object as to be serialized in both YAML and JSON, both JSON::Field and YAML::Field have to be used.
It would save duplications to have only one annotation.

An example to illustrate the redundancy:

class Location
  include JSON::Serializable
  include YAML::Serializable

  @[JSON::Field(key: "lat")]
  @[YAML::Field(key: "lat")]
  property latitude : Float64

  @[JSON::Field(key: "lng")]
  @[YAML::Field(key: "lng")]
  property longitude : Float64
1 Like

I think this makes only sense in the scope of a generic serialization framework like serde. I’d really like to see something like this for Crystal :heart:


Agree @straight-shoota , that’s partially why I think the Serializable and mapping stuff, while being handy, will better live outside the stdlib, inside a dedicated framework.