@@ -27,7 +27,7 @@ func NewObject(id string, objType string, attributes interface{}) (*Object, Send
27
27
Relationships : map [string ]* Object {},
28
28
}
29
29
30
- rawJSON , err := json .MarshalIndent (attributes , "" , " " )
30
+ rawJSON , err := json .MarshalIndent (attributes , "" , " " )
31
31
if err != nil {
32
32
return nil , ISE (fmt .Sprintf ("Error marshaling attrs while creating a new JSON Object: %s" , err ))
33
33
}
@@ -58,31 +58,41 @@ func NewObject(id string, objType string, attributes interface{}) (*Object, Send
58
58
// // log errors via error.ISE
59
59
// jsh.Send(w, r, errors)
60
60
// }
61
- func (o * Object ) Unmarshal (objType string , target interface {}) ( err SendableError ) {
61
+ func (o * Object ) Unmarshal (objType string , target interface {}) SendableError {
62
62
63
63
if objType != o .Type {
64
- err = ISE (fmt .Sprintf (
64
+ return ISE (fmt .Sprintf (
65
65
"Expected type %s, when converting actual type: %s" ,
66
66
objType ,
67
67
o .Type ,
68
68
))
69
- return
70
69
}
71
70
72
71
jsonErr := json .Unmarshal (o .Attributes , target )
73
72
if jsonErr != nil {
74
- err = ISE (fmt .Sprintf (
73
+ return ISE (fmt .Sprintf (
75
74
"For type '%s' unable to marshal: %s\n Error:%s" ,
76
75
objType ,
77
76
string (o .Attributes ),
78
77
jsonErr .Error (),
79
78
))
80
- return
81
79
}
82
80
83
81
return validateInput (target )
84
82
}
85
83
84
+ // Marshal allows you to load a modified payload back into an object to preserve
85
+ // all of the data it has
86
+ func (o * Object ) Marshal (attributes interface {}) SendableError {
87
+ raw , err := json .MarshalIndent (attributes , "" , " " )
88
+ if err != nil {
89
+ return ISE (fmt .Sprintf ("Error marshaling attrs while creating a new JSON Object: %s" , err ))
90
+ }
91
+
92
+ o .Attributes = raw
93
+ return nil
94
+ }
95
+
86
96
// Prepare creates a new JSON single object response with an appropriate HTTP status
87
97
// to match the request method type.
88
98
func (o * Object ) Prepare (r * http.Request , response bool ) (* Response , SendableError ) {
0 commit comments