Skip to content
Open
Changes from all commits
Commits
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: 19 additions & 0 deletions project.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package dtrack

import (
"context"
"encoding/json"
"fmt"
"net/http"
"strconv"
Expand Down Expand Up @@ -32,6 +33,24 @@ type Project struct {
ExternalReferences []ExternalReference `json:"externalReferences,omitempty"`
}

// Here we write a custom MarshalJSON function to give us more control over the JSON output.
func (p Project) MarshalJSON() ([]byte, error) {
type Alias Project // Avoid infinite recursion
aux := struct {
Alias
LastBOMImport *int `json:"lastBomImport,omitempty"`
}{
Alias: (Alias)(p),
LastBOMImport: nil,
}
// In particular, sending a 0 to the API gives us an invalid date
// i.e. the beginning of the epoch. Better to be nil.
if p.LastBOMImport != 0 {
aux.LastBOMImport = &p.LastBOMImport
}
return json.Marshal(aux)
}

type ParentRef struct {
UUID uuid.UUID `json:"uuid,omitempty"`
}
Expand Down
Loading