Skip to content

Adds custom marshaller for Project to support empty LastBomImports#40

Open
bomoko wants to merge 2 commits intoDependencyTrack:mainfrom
bomoko:main
Open

Adds custom marshaller for Project to support empty LastBomImports#40
bomoko wants to merge 2 commits intoDependencyTrack:mainfrom
bomoko:main

Conversation

@bomoko
Copy link

@bomoko bomoko commented Apr 8, 2025

This PR introduces a custom marshaller function for the Project type. It essentially allows for matching types with Dependency Track itself, which seems to allow nil values for their "Last BOM Import" column.

closes #38

Signed-off-by: Blaize Kaye <blaize.kaye@amazee.io>
Copilot AI review requested due to automatic review settings March 19, 2026 18:50
@owasp-dt-bot
Copy link

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adjusts how Project is serialized to JSON so that lastBomImport is omitted when it would otherwise be sent as 0, matching Dependency-Track’s behavior of leaving “Last BOM Import” empty for projects without an import.

Changes:

  • Added a custom Project.MarshalJSON implementation to omit lastBomImport when LastBOMImport == 0.
  • Added encoding/json import to support the custom marshaler.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +48 to +64
// 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)
}
Comment on lines +49 to +64
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)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Type incompatibility with Project.LastBOMImport

3 participants