Skip to content

Commit 5057a02

Browse files
committed
fix JSON marshal for platforms
1 parent dcc1d2f commit 5057a02

File tree

1 file changed

+30
-8
lines changed

1 file changed

+30
-8
lines changed

Diff for: arduino/cores/cores.go

+30-8
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package cores
1919

2020
import (
21+
"encoding/json"
2122
"strings"
2223

2324
paths "github.com/arduino/go-paths-helper"
@@ -41,14 +42,13 @@ type PlatformRelease struct {
4142
Resource *resources.DownloadResource
4243
Version *semver.Version
4344
BoardsManifest []*BoardManifest
44-
Dependencies ToolDependencies // The Dependency entries to load tools.
45-
Platform *Platform `json:"-"`
46-
47-
Properties *properties.Map `json:"-"`
48-
Boards map[string]*Board `json:"-"`
49-
Programmers map[string]*properties.Map `json:"-"`
50-
Menus *properties.Map `json:"-"`
51-
InstallDir *paths.Path `json:"-"`
45+
Dependencies ToolDependencies // The Dependency entries to load tools.
46+
Platform *Platform `json:"-"`
47+
Properties *properties.Map `json:"-"`
48+
Boards map[string]*Board `json:"-"`
49+
Programmers map[string]*properties.Map `json:"-"`
50+
Menus *properties.Map `json:"-"`
51+
InstallDir *paths.Path `json:"-"`
5252
}
5353

5454
// BoardManifest contains information about a board. These metadata are usually
@@ -226,3 +226,25 @@ func (release *PlatformRelease) String() string {
226226
}
227227
return release.Platform.String() + "@" + version
228228
}
229+
230+
// MarshalJSON provides a more user friendly serialization for
231+
// PlatformRelease objects.
232+
func (release *PlatformRelease) MarshalJSON() ([]byte, error) {
233+
latestStr := ""
234+
latest := release.Platform.GetLatestRelease()
235+
if latest != nil {
236+
latestStr = latest.Version.String()
237+
}
238+
239+
return json.Marshal(&struct {
240+
ID string `json:"ID,omitempty"`
241+
Installed string `json:"Installed,omitempty"`
242+
Latest string `json:"Latest,omitempty"`
243+
Name string `json:"Name,omitempty"`
244+
}{
245+
ID: release.Platform.String(),
246+
Installed: release.Version.String(),
247+
Latest: latestStr,
248+
Name: release.Platform.Name,
249+
})
250+
}

0 commit comments

Comments
 (0)