Skip to content

Commit 71538e5

Browse files
committed
feat(apijson): add decode_null_to_zero tag option
Add support for a new `decode_null_to_zero` tag option in JSON struct tags to decode null and omitted JSON values as zero values instead of leaving them unset (which usually results in them being set to null). This is particularly useful for resources where the API does not include certain optional attributes in responses when they are the default value. For example, when the API uses Go's `omitempty` or `omitzero` with a non-pointer type. In this case, the attribute cannot simply be marked as `Optional`, because Terraform will complain that the API does not include the attribute in responses when it is explicitly set to the default value in a configuration. Marking the attribute as `Computed` and `Optional` with a `Default` also does not work without adding the new `decode_null_to_zero` tag, because Terraform expects the API to always include computed attributes in responses, which it will not for the default value. Using the new `decode_null_to_zero` tag solves this issue, since from Terraform's perspective, the API now always returns a value for the attribute, even if it is just the default.
1 parent 9bd4f74 commit 71538e5

File tree

3 files changed

+988
-88
lines changed

3 files changed

+988
-88
lines changed

0 commit comments

Comments
 (0)