struct CrSerializer::ExclusionStrategies::Version

Overview

Serialize properties based on a SemanticVersion string.

It is enabled by default when using CrSerializer::Context#version=.

class Example
  include CrSerializer

  def initialize; end

  @[CRS::Until("1.0.0")]
  property name : String = "Legacy Name"

  @[CRS::Since("1.1.0")]
  property name2 : String = "New Name"
end

example = Example.new

example.to_json(CrSerializer::SerializationContext.new.version = "0.30.0") # => {"name":"Legacy Name"}
example.to_json(CrSerializer::SerializationContext.new.version = "1.2.0")  # => {"name2":"New Name"}

Defined in:

exclusion_strategies/version.cr

Constructors

Instance Method Summary

Instance methods inherited from struct CrSerializer::ExclusionStrategies::ExclusionStrategy

skip_property?(metadata : PropertyMetadata, context : Context) : Bool skip_property?

Constructor methods inherited from struct CrSerializer::ExclusionStrategies::ExclusionStrategy

new new

Constructor Detail

def self.new(version : SemanticVersion) #

[View source]

Instance Method Detail

def skip_property?(metadata : PropertyMetadata, context : Context) : Bool #

Returns true if a property should NOT be serialized/deserialized.


[View source]
def version : SemanticVersion #

[View source]