File tree Expand file tree Collapse file tree 1 file changed +18
-3
lines changed
Expand file tree Collapse file tree 1 file changed +18
-3
lines changed Original file line number Diff line number Diff line change 2323 {% if val .year is defined %}
2424 {% do return(val .isoformat ()) %}
2525 {% endif %}
26- {% if val is number and ' .' in val | string %}
27- {# a bit of a hacky way to standardize Decimals which are not JSON-serializable #}
28- {% do return(val | string | float) %}
26+ {% if elementary .edr_is_decimal (val) %}
27+ {% do return(elementary .edr_serialize_decimal (val)) %}
2928 {% endif %}
3029 {% do return(val) %}
3130{% endmacro %}
31+
32+ {% macro edr_is_decimal(val) %}
33+ {# A hacky way to check if a value is of type Decimal, as there isn't a straightforward way to check that #}
34+ {% do return(val is number and val .normalize is defined and val .normalize is not none) %}
35+ {% endmacro %}
36+
37+ {% macro edr_serialize_decimal(val) %}
38+ {% set dec_tuple = val .normalize ().as_tuple() %}
39+
40+ {# A hacky way to standardize Decimals which are not JSON-serializable #}
41+ {% if dec_tuple[2 ] == 0 %}
42+ {% do return(val | string | int ) %}
43+ {% else %}
44+ {% do return(val | string | float) %}
45+ {% endif %}
46+ {% endmacro %}
You can’t perform that action at this time.
0 commit comments