Don't fail on properties that are missing when unmarshaling json

This commit is contained in:
Marius Orcsik 2022-03-06 13:34:08 +01:00
parent 16bd1c8aa0
commit d29b4fa0ae
No known key found for this signature in database
GPG key ID: DBF5E47F5DBC4D21

View file

@ -37,31 +37,49 @@ func JSONGetType(val *fastjson.Value) ActivityVocabularyType {
}
func JSONGetMimeType(val *fastjson.Value, prop string) MimeType {
if !val.Exists(prop) {
return ""
}
t := val.GetStringBytes(prop)
return MimeType(t)
}
func JSONGetInt(val *fastjson.Value, prop string) int64 {
if !val.Exists(prop) {
return 0
}
i := val.Get(prop).GetInt64()
return i
}
func JSONGetFloat(val *fastjson.Value, prop string) float64 {
if !val.Exists(prop) {
return 0.0
}
f := val.Get(prop).GetFloat64()
return f
}
func JSONGetString(val *fastjson.Value, prop string) string {
if !val.Exists(prop) {
return ""
}
s := val.Get(prop).GetStringBytes()
return string(s)
}
func JSONGetBytes(val *fastjson.Value, prop string) []byte {
if !val.Exists(prop) {
return nil
}
s := val.Get(prop).GetStringBytes()
return s
}
func JSONGetBoolean(val *fastjson.Value, prop string) bool {
if !val.Exists(prop) {
return false
}
t, _ := val.Get(prop).Bool()
return t
}