cbor icon indicating copy to clipboard operation
cbor copied to clipboard

feature: Encode nil map/slice with cbor empty map/list tag

Open dedefer opened this issue 3 years ago • 4 comments

Is your feature request related to a problem? Please describe. I use cbor as a serialization format for rpc between services written in different languages. So when i try to send some structure like

type Example struct {
  Data map[string]string `cbor:"data"`
}

I always need to initialize Data explicitly Example{Data: map[string]string{}} because Example{} is serialized to {"data":null}.

So I need to describe this dto in python like

class Example:
  data: Optional[dict[str, str]]

despite the fact that this field is required.

Describe the solution you'd like I think it would be nice to have encoding option to enforce encoder use empty list/map cbor type for nil slice/map.

dedefer avatar Jun 06 '22 14:06 dedefer

@dedefer Thanks for opening issue and PR. It makes sense to me to add this option.

I'll take a look at the PR. It may be a while because I need to update fuzz test, etc. first.

fxamacker avatar Jun 12 '22 17:06 fxamacker

@fxamacker Could you please give any updates on an issue?

dedefer avatar Jul 19 '22 11:07 dedefer

Hello @dedefer,

I like your PR and want to include it in the next release. I've been swamped with work and hope to get to it after an upcoming deadline. I need to update the fuzzer for this PR and etc. so there's some extra work behind the scenes.

You can specify unmerged PR's commit inside go.mod as a workaround before the PR is merged.

Thanks again for the contribution and your patience!

fxamacker avatar Jul 20 '22 03:07 fxamacker

It's ok! I know that feel, bro. Thanks for not forgetting about this issue! I really appreciate your work!

dedefer avatar Jul 20 '22 06:07 dedefer

Closed by PR #352 and #377.

fxamacker avatar Dec 30 '22 23:12 fxamacker