Skip to content

Commit

Permalink
fix(2.2 json): remove emtpy packageVerificationCode
Browse files Browse the repository at this point in the history
Signed-off-by: Keith Zantow <kzantow@gmail.com>
  • Loading branch information
kzantow committed Sep 21, 2023
1 parent 6a271aa commit 6d25b5b
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions spdx/v2/v2_2/package.go
Expand Up @@ -4,6 +4,7 @@ package v2_2

import (
"encoding/json"
"regexp"
"strings"

"github.com/spdx/tools-golang/spdx/v2/common"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 6d25b5b

Please sign in to comment.