UnmarshalJSON() overrides the unmarshalling logic of the Page for generic structure assignment (registered pageables) and custom formatting
(jsonBytes []byte)
| 209 | // UnmarshalJSON() overrides the unmarshalling logic of the |
| 210 | // Page for generic structure assignment (registered pageables) and custom formatting |
| 211 | func (p *Page) UnmarshalJSON(jsonBytes []byte) (err error) { |
| 212 | // create a new json object reference to ensure a non-nil result |
| 213 | j := new(jsonPage) |
| 214 | // populate the json page with json bytes |
| 215 | if err = json.Unmarshal(jsonBytes, &j); err != nil { |
| 216 | // exit with error |
| 217 | return |
| 218 | } |
| 219 | // extract the pageable implementation from the previously registered pageable type |
| 220 | m, found := RegisteredPageables[j.Type] |
| 221 | // if not found among the registered |
| 222 | if !found { |
| 223 | return ErrUnknownPageable(j.Type) |
| 224 | } |
| 225 | // create a new instance of the page |
| 226 | pageable := m.New() |
| 227 | // populate the results with json bytes |
| 228 | if err = json.Unmarshal(j.Results, pageable); err != nil { |
| 229 | // exit with error |
| 230 | return |
| 231 | } |
| 232 | // |
| 233 | *p = Page{ |
| 234 | PageParams: j.PageParams, |
| 235 | Results: pageable, |
| 236 | Type: j.Type, |
| 237 | Count: j.Count, |
| 238 | TotalPages: j.TotalPages, |
| 239 | TotalCount: j.TotalCount, |
| 240 | } |
| 241 | // exit |
| 242 | return |
| 243 | } |
| 244 | |
| 245 | // jsonPage is the internal structure for custom json for the Page structure |
| 246 | type jsonPage struct { |
nothing calls this directly
no test coverage detected