-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support of unmarshalling and marshalling of pointers (#32)
During development of my own project I found some issues when trying to marshal php Nulls `N` into any Go struct fields. Was seeing uncaught panics such as `reflect: call of reflect.Value.Set on zero Value` if the value trying to be set on a struct field was Null. Additionally if a value was being set on a struct field of type reflect.Ptr that was nil a panic would occur when calling the .Set method on the struct field e.g. `reflect.Set: value of type string is not assignable to type *string` I've added testing to showcase the now supported functionality: * When serializing if a pointer value is Nil the MarshalNil function will be called * When unserializing if the value passed in is a nil interface the struct field will be left unset (set as default value) rather then panic * If unmarshalling to a pointer struct field, the field will first be instantiated before attempting to set the value of the pointer I used this Go playground to try base behaviour off of the `encoding/json` package: https://go.dev/play/p/5td0XqinlIP Co-authored-by: danielbairstow97 <daniel@paypaplane.com>
- Loading branch information
1 parent
c610362
commit 9905247
Showing
4 changed files
with
103 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters