Skip to content

Add nullable option to codec #2171

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 45 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
80289ab
Add ability to serialize Nil pointers
nytzuga Oct 14, 2023
f94bf74
Added support for `omitempty:"true"`
nytzuga Oct 16, 2023
8c726fc
Use a single byte for Nil values
nytzuga Oct 17, 2023
6c9dbb2
UnpackIfMatches() is not longer needed
nytzuga Oct 17, 2023
db794ca
Allow `omitempty` for interfaces
nytzuga Oct 18, 2023
d67dc7c
Remove optimization
nytzuga Oct 19, 2023
81ace67
Do not pass omitEmpty by default
nytzuga Oct 19, 2023
10a7beb
Minor improvements
nytzuga Oct 24, 2023
9c091f0
Improve tests
nytzuga Oct 24, 2023
2959056
Merge tests
nytzuga Oct 25, 2023
4c7a2e0
Fix size() with omitEmpty and added tests
nytzuga Oct 25, 2023
40e95c8
Enhanced the tests
nytzuga Oct 25, 2023
c4be2d3
Minor improvements
nytzuga Oct 27, 2023
553dbad
Rename `omitEmpty` to `nullable` for consistency
nytzuga Oct 27, 2023
ad4db9d
Addressed issues reported by @darioush
nytzuga Oct 27, 2023
a447007
Cleanup nil serialization (#2231)
StephenButtolph Oct 30, 2023
9693c7a
Address PR review comments
StephenButtolph Oct 31, 2023
9761d05
Update codec/reflectcodec/struct_fielder.go
nytzuga Nov 1, 2023
79f8e3b
Update codec/reflectcodec/struct_fielder.go
nytzuga Nov 1, 2023
4d6c4cf
Update codec/reflectcodec/type_codec.go
nytzuga Nov 1, 2023
273f5f7
Update codec/reflectcodec/type_codec.go
nytzuga Nov 1, 2023
5c4be97
merged
StephenButtolph Nov 1, 2023
9d3d881
Add ability to serialize Nil pointers
nytzuga Oct 14, 2023
808ec92
Added support for `omitempty:"true"`
nytzuga Oct 16, 2023
f757dc4
Use a single byte for Nil values
nytzuga Oct 17, 2023
bd44485
UnpackIfMatches() is not longer needed
nytzuga Oct 17, 2023
72be530
Allow `omitempty` for interfaces
nytzuga Oct 18, 2023
86af7cb
Remove optimization
nytzuga Oct 19, 2023
f01a50d
Do not pass omitEmpty by default
nytzuga Oct 19, 2023
6335873
Minor improvements
nytzuga Oct 24, 2023
b137285
Improve tests
nytzuga Oct 24, 2023
c2b3564
Merge tests
nytzuga Oct 25, 2023
c2d1ea4
Fix size() with omitEmpty and added tests
nytzuga Oct 25, 2023
a0b8fec
Enhanced the tests
nytzuga Oct 25, 2023
945e914
Minor improvements
nytzuga Oct 27, 2023
d1e78b7
Rename `omitEmpty` to `nullable` for consistency
nytzuga Oct 27, 2023
6df507c
Addressed issues reported by @darioush
nytzuga Oct 27, 2023
c74bf4d
Cleanup nil serialization (#2231)
StephenButtolph Oct 30, 2023
e41ae13
Update codec/reflectcodec/struct_fielder.go
nytzuga Nov 1, 2023
6a598e7
Update codec/reflectcodec/struct_fielder.go
nytzuga Nov 1, 2023
900aa56
Update codec/reflectcodec/type_codec.go
nytzuga Nov 1, 2023
3bd2e18
Update codec/reflectcodec/type_codec.go
nytzuga Nov 1, 2023
76530bd
Rename test as suggested
nytzuga Nov 1, 2023
168627d
Add more tests
nytzuga Nov 1, 2023
90b73c5
merged
StephenButtolph Nov 1, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions codec/reflectcodec/struct_fielder.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,18 @@ const (

// TagValue is the value the tag must have to be serialized.
TagValue = "true"

// TagValue is the value the tag must have to be serialized, this variant
// includes the nullable option
TagWithNullableValue = "true,nullable"
)

var _ StructFielder = (*structFielder)(nil)

type FieldDesc struct {
Index int
MaxSliceLen uint32
Nullable bool
}

// StructFielder handles discovery of serializable fields in a struct.
Expand Down Expand Up @@ -82,10 +87,19 @@ func (s *structFielder) GetSerializedFields(t reflect.Type) ([]FieldDesc, error)
// Multiple tags per fields can be specified.
// Serialize/Deserialize field if it has
// any tag with the right value
captureField := false
var (
captureField bool
nullable bool
)
for _, tag := range s.tags {
if field.Tag.Get(tag) == TagValue {
switch field.Tag.Get(tag) {
case TagValue:
captureField = true
case TagWithNullableValue:
captureField = true
nullable = true
}
if captureField {
break
}
}
Expand All @@ -107,6 +121,7 @@ func (s *structFielder) GetSerializedFields(t reflect.Type) ([]FieldDesc, error)
serializedFields = append(serializedFields, FieldDesc{
Index: i,
MaxSliceLen: maxSliceLen,
Nullable: nullable,
})
}
s.serializedFieldIndices[t] = serializedFields // cache result
Expand Down
Loading