jmattheis / goverter

Generate type-safe Go converters by simply defining an interface
https://goverter.jmattheis.de/
MIT License
496 stars 46 forks source link

map nil slice to nil #44

Closed YasserRabee closed 1 year ago

YasserRabee commented 1 year ago

In our usecase, nil slice is not the same as empty slice. This patch maps nil slices to nil.

This changes may affect users who depended on the older behavior that converts nil slices to empty slices. For example, encoding a nil slice in a JSON response will be null but empty slice will be []. So users who don't tolerate this in their code flow may be affected.

I suggest to enable this behavior on-demand, but couldn't resolve a possible solution.

jmattheis commented 1 year ago

I think it's okay to make this breaking change, I'd see this as a bugfix.

This PR will change the output of the tests, you can run

UPDATE_SCENARIO=true go test ./

To update them automatically. In one test case, the nil check produces a compile error.

YasserRabee commented 1 year ago

Thanks @jmattheis. I have handled the fixed length lists correctly, and updated the test scenarios.