From e32c28bbb8d3c2a155d673d44eaeaf10c597338b Mon Sep 17 00:00:00 2001 From: Jon Sullivan Date: Thu, 28 Jul 2022 11:19:51 -0400 Subject: [PATCH] Read JSON::Any Columns as `.to_json`'d String --- src/granite/columns.cr | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/granite/columns.cr b/src/granite/columns.cr index 348a08ac..00c4272a 100644 --- a/src/granite/columns.cr +++ b/src/granite/columns.cr @@ -149,7 +149,12 @@ module Granite::Columns {% begin %} case attribute_name.to_s {% for column in @type.instance_vars.select { |ivar| ivar.annotation(Granite::Column) } %} - when "{{ column.name }}" then @{{ column.name.id }} + {% if column.type.union? && column.type.union_types.includes?(JSON::Any) %} + {% puts "registering #{column} with a .to_json" %} + when "{{ column.name }}" then @{{ column.name.id }}.to_json + {% else %} + when "{{ column.name }}" then @{{ column.name.id }} + {% end %} {% end %} else raise "Cannot read attribute #{attribute_name}, invalid attribute"