aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--decoding_json.go10
1 files changed, 10 insertions, 0 deletions
diff --git a/decoding_json.go b/decoding_json.go
index 77fddc9..1423284 100644
--- a/decoding_json.go
+++ b/decoding_json.go
@@ -25,6 +25,9 @@ var ItemTyperFunc TyperFn = GetItemByType
// JSONItemUnmarshal can be set externally to populate a custom object based on its type
var JSONItemUnmarshal JSONUnmarshalerFn = nil
+// NotEmptyChecker checks if an object is empty
+var NotEmptyChecker NotEmptyCheckerFn = NotEmpty
+
// TyperFn is the type of the function which returns an Item struct instance
// for a specific ActivityVocabularyType
type TyperFn func(ActivityVocabularyType) (Item, error)
@@ -33,6 +36,9 @@ type TyperFn func(ActivityVocabularyType) (Item, error)
// that the current package doesn't know about.
type JSONUnmarshalerFn func(ActivityVocabularyType, *fastjson.Value, Item) error
+// NotEmptyCheckerFn is the type of a function that checks if an object is empty
+type NotEmptyCheckerFn func(Item) bool
+
func JSONGetID(val *fastjson.Value) ID {
i := val.Get("id").GetStringBytes()
return ID(i)
@@ -186,6 +192,7 @@ func JSONLoadItem(val *fastjson.Value) (Item, error) {
if err != nil || IsNil(i) {
return nil, nil
}
+ var empty = func(i Item) bool { return !NotEmptyChecker(i) }
switch typ {
case "":
@@ -258,6 +265,9 @@ func JSONLoadItem(val *fastjson.Value) (Item, error) {
if err != nil {
return nil, err
}
+ if empty(i) {
+ return nil, nil
+ }
return i, nil
}