Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Control field serialization / deserialization #7

Closed
docelic opened this issue Mar 18, 2021 · 0 comments
Closed

Control field serialization / deserialization #7

docelic opened this issue Mar 18, 2021 · 0 comments

Comments

@docelic
Copy link
Contributor

docelic commented Mar 18, 2021

I think a patch as small as this could work:

diff --git a/src/crystalizer.cr b/src/crystalizer.cr
index 03989e3..397c66a 100644
--- a/src/crystalizer.cr
+++ b/src/crystalizer.cr
@@ -7,7 +7,7 @@ module Crystalizer
   protected def self.each_ivar(object : O, &) forall O
     {% for ivar in O.instance_vars %}
       {% ann = ivar.annotation(::Crystalizer::Field) %}
-      {% unless ann && ann[:ignore] %}
+      {% unless ann && (ann[:ignore] || ann[:ignore_serialize])%}
         {% key = ((ann && ann[:key]) || ivar).id.stringify %}
         yield {{key}}, object.@{{ivar}}, Variable.new(
             type: {{ivar.type}},
diff --git a/src/deserializer/non_self_describing_object.cr b/src/deserializer/non_self_describing_object.cr
index 3694fb2..9721beb 100644
--- a/src/deserializer/non_self_describing_object.cr
+++ b/src/deserializer/non_self_describing_object.cr
@@ -15,7 +15,7 @@ struct Crystalizer::Deserializer::NonSelfDescribingObject(T)
   def set_each_ivar(&)
     {% for ivar in T.instance_vars %}
       {% ann = ivar.annotation(::Crystalizer::Field) %}
-      {% unless ann && ann[:ignore] %}
+      {% unless ann && (ann[:ignore] || ann[:ignore_deserialize])%}
         {% key = ((ann && ann[:key]) || ivar).id.stringify %}
         variable = Variable.new(
           type: {{ivar.type}},
diff --git a/src/deserializer/self_describing_object.cr b/src/deserializer/self_describing_object.cr
index 60f5719..1994dff 100644
--- a/src/deserializer/self_describing_object.cr
+++ b/src/deserializer/self_describing_object.cr
@@ -16,7 +16,7 @@ struct Crystalizer::Deserializer::SelfDescribingObject(T, N)
     case key
     {% for ivar in T.instance_vars %}
       {% ann = ivar.annotation(::Crystalizer::Field) %}
-      {% unless ann && ann[:ignore] %}
+      {% unless ann && (ann[:ignore] || ann[:ignore_deserialize]) %}
         {% key = ((ann && ann[:key]) || ivar).id.stringify %}
         when {{key}}
           raise Error.new "Duplicated field for {{T}}: #{key}" if @found[{{i}}]
@@ -41,7 +41,7 @@ struct Crystalizer::Deserializer::SelfDescribingObject(T, N)
     {% i = 0 %}
     {% for ivar in T.instance_vars %}
       {% ann = ivar.annotation(::Crystalizer::Field) %}
-      {% unless ann && ann[:ignore] %}
+      {% unless ann && (ann[:ignore] || (ann[:ignore_serialize] && ann[:ignore_deserialize])) %}
       if !@found[{{i}}]
         {% if ivar.has_default_value? %}
           pointerof(@object_instance.@{{ivar}}).value = {{ivar.default_value}}
@j8r j8r closed this as completed in f673349 Mar 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant