@@ -16,6 +16,7 @@ import (
1616type Finding struct {
1717 jsonlog.ObjectHeader
1818 Meta LogEventMetadata `json:"meta" textlog:",expand"`
19+ Text string `json:"message" textlog:"-"`
1920 Subject ReportableObject `json:"subject" textlog:",expand"`
2021 Score int64 `json:"score" textlog:"score"`
2122 Reasons []Reason `json:"reasons" textlog:",expand"`
@@ -31,7 +32,7 @@ type ReportableObject interface {
3132}
3233
3334func (f * Finding ) Message () string {
34- return f .Summary
35+ return f .Text
3536}
3637
3738func (f * Finding ) Version () common.Version {
@@ -43,29 +44,20 @@ func (f *Finding) Metadata() *LogEventMetadata {
4344}
4445
4546func (f * Finding ) UnmarshalJSON (data []byte ) error {
47+ type plainFinding Finding
4648 var rawFinding struct {
47- jsonlog.ObjectHeader
48- Meta LogEventMetadata `json:"meta"`
49- Subject EmbeddedObject `json:"subject"`
50- Score int64 `json:"score"`
51- Reasons []Reason `json:"reasons"`
52- EventContext Context `json:"context"`
53- LogVersion common.Version `json:"log_version"`
49+ plainFinding // Embed without unmarshal method to avoid infinite recursion
50+ Subject EmbeddedObject `json:"subject"` // EmbeddedObject is used to allow unmarshalling of the subject as a ReportableObject
5451 }
5552 if err := json .Unmarshal (data , & rawFinding ); err != nil {
5653 return err
5754 }
58- f .ObjectHeader = rawFinding .ObjectHeader
59- f .Meta = rawFinding .Meta
6055 subject , ok := rawFinding .Subject .Object .(ReportableObject )
6156 if ! ok {
6257 return fmt .Errorf ("subject must implement the reportable interface" )
6358 }
59+ * f = Finding (rawFinding .plainFinding ) // Copy the fields from rawFinding to f
6460 f .Subject = subject
65- f .Score = rawFinding .Score
66- f .Reasons = rawFinding .Reasons
67- f .EventContext = rawFinding .EventContext
68- f .LogVersion = rawFinding .LogVersion
6961
7062 // Resolve all references
7163 // When the event is unmarshalled, the references are not resolved yet and only contain the JSON pointers.
@@ -163,9 +155,9 @@ func init() { AddLogObjectType(typeFinding, &Finding{}) }
163155func NewFinding (subject ReportableObject , message string ) * Finding {
164156 return & Finding {
165157 ObjectHeader : LogObjectHeader {
166- Type : typeFinding ,
167- Summary : message ,
158+ Type : typeFinding ,
168159 },
160+ Text : message ,
169161 Subject : subject ,
170162 LogVersion : currentVersion ,
171163 }
@@ -174,12 +166,13 @@ func NewFinding(subject ReportableObject, message string) *Finding {
174166type Message struct {
175167 jsonlog.ObjectHeader
176168 Meta LogEventMetadata `json:"meta" textlog:",expand"`
169+ Text string `json:"message" textlog:"-"`
177170 Fields MessageFields `json:"fields" textlog:",expand" jsonschema:"nullable"`
178171 LogVersion common.Version `json:"log_version"`
179172}
180173
181174func (m * Message ) Message () string {
182- return m .Summary
175+ return m .Text
183176}
184177
185178func (m * Message ) Version () common.Version {
@@ -199,9 +192,9 @@ func init() { AddLogObjectType(typeMessage, &Message{}) }
199192func NewMessage (meta LogEventMetadata , message string , kvs ... any ) * Message {
200193 msg := & Message {
201194 ObjectHeader : LogObjectHeader {
202- Type : typeMessage ,
203- Summary : message ,
195+ Type : typeMessage ,
204196 },
197+ Text : message ,
205198 Meta : meta ,
206199 LogVersion : currentVersion ,
207200 }
0 commit comments