annotation CrSerializer::Annotations::VirtualProperty

Overview

Can be applied to a method to make it act like a property.

class Example
  include CrSerializer

  def initialize; end

  property foo : String = "foo"

  property bar : String = "bar"

  @[CRS::VirtualProperty]
  @[CRS::SerializedName("testing")]
  def some_method : Bool
    false
  end

  @[CRS::VirtualProperty]
  def get_val : String
    "VAL"
  end
end

Example.new.serialize JSON # => {"foo":"foo","bar":"bar","testing":false,"get_val":"VAL"}

NOTE The return type restriction MUST be defined.

Defined in:

annotations.cr