diff --git a/spdx/v2/v2_2/package.go b/spdx/v2/v2_2/package.go index 54de537c..700c83e8 100644 --- a/spdx/v2/v2_2/package.go +++ b/spdx/v2/v2_2/package.go @@ -4,6 +4,7 @@ package v2_2 import ( "encoding/json" + "regexp" "strings" "github.com/spdx/tools-golang/spdx/v2/common" @@ -122,6 +123,20 @@ type Package struct { hasFiles []common.DocElementID } +var emptyVerificationCodeRegex = regexp.MustCompile(`,\s*"packageVerificationCode"\s*:\s*\{\s*"packageVerificationCodeValue"\s*:\s*""\s*}`) + +func (p *Package) MarshalJSON() ([]byte, error) { + type pkg Package + p2 := pkg(*p) + + data, err := json.Marshal(p2) + if err != nil { + return nil, err + } + + return emptyVerificationCodeRegex.ReplaceAll(data, []byte("")), nil +} + func (p *Package) UnmarshalJSON(b []byte) error { type pkg Package type extras struct { @@ -153,6 +168,7 @@ func (p *Package) UnmarshalJSON(b []byte) error { } var _ json.Unmarshaler = (*Package)(nil) +var _ json.Marshaler = (*Package)(nil) // PackageExternalReference is an External Reference to additional info // about a Package, as defined in section 7.21 in version 2.2 of the spec.