Commit Graph

62 Commits

Author SHA1 Message Date
Aren Patel f3b4acfd23
RFC 3339 support for both Marshal and Unmarshal. (#204)
* RFC 3339 support for both Marshal and Unmarshal.

* Post merge cleanup

* Update request_test.go

Co-authored-by: Quetzy Garcia <quetzy.garcia@integrate.com>

* Spelling

* Update request.go

Co-authored-by: Quetzy Garcia <quetzy.garcia@integrate.com>

* Simplify the ISO 8601 logic. No need for the const rfc3339TimeFormat use time.RFC3339 directly.

Co-authored-by: Quetzy Garcia <quetzy.garcia@integrate.com>
2021-04-05 11:13:02 -07:00
Sam Woodard e9f117e24a fix logic error, break needs to be for loop not switch 2018-10-16 07:33:57 -07:00
Sam Woodard 6bf44faa3c return function return value when is only err 2018-10-16 07:33:23 -07:00
Ilya Baturin 5d047c6bc6 fixes issue with slice of nil pointers (#144)
fixes panic in case of marshaling of slice of nils like `[]*<SomeType>{nil, nil}`
2018-06-17 19:19:26 -07:00
Igor Zibarev 103c21c224 Fix omitempty for attributes (#119)
* Fix omitempty for attributes

Fix panic on omitempty field for attribute that is not of
a primitive type.

Fixes #103

* Add more types for omitempty test
2018-03-12 18:15:16 -07:00
Aren Patel 5e0c586099
Corrected spelling mistakes. 2017-09-13 12:52:31 -07:00
Aren Patel 46d3ced043 Added support for implementing the Linkable and Metable interface on collections (slices) being Marshalled. (#94) 2017-07-07 17:58:51 -07:00
Aren Patel cf83b97b3d Public Marshal API Simplification (#90)
* Used to have 6 functions: MarshalOnePayload, MarshalOnePayloadWithoutIncluded, MarshalOne, MarshalManyPayload, MarshalManyPayloadWithoutIncluded, MarshalMany - now there are only 3: MarshalPayload, MarshalPayloadWithoutIncluded, Marshal. This simplifies the public API; will be easier to explain and document while still providing the existing support for struct ptrs (&Blog{}) and slices of struct ptrs ([]*Blog{}).

* Correcting all code occurrences leftover.

* Updating README to reflect Marshal API changes.

* Omit the mention of One vs Many
2017-06-28 17:30:09 -07:00
Angelos Panagiotopoulos af3dab1a94 Update documentation for responding with proper JSON API headers (#84)
* Update documentation for responding with proper JSONAPI headers

* Fixed examples and commented code for sending proper response headers
2017-04-05 11:19:51 -07:00
Samantha Belkin 776433d17d Add support for 'meta' (#72)
* add Meta field in node structs and Metable/RelationshipMetable interfaces

* update response marshalling to add Meta

* update tests for presence of Meta

* add Metable and RelationshipMetable interfaces to example

* update README to include Meta details
2017-02-16 17:40:50 -08:00
Keiji Yoshida a8d743e645 Remove an unused parameter (#69)
`relationName` parameter of `visitModelNodeRelationships` method is not used and removed.
2017-01-28 19:43:47 -08:00
Lucius Humm 9d919b42a6 Add MarshalManyPayloadWithoutIncluded (#56)
* fix spelling in documentation

* add MarshalManyPayloadWithoutIncluded

does the same as `MarshalOnePayloadWithoutIncluded` but for
MarshalManyPayload

* Refactored MarshalManyPayloadWithoutIncluded to use the MarshalMany func
2017-01-24 14:53:31 -08:00
Aren Patel 15abc3066a Use constants for status codes, HTTP methods and JSON API media types in comments and readme 2017-01-20 18:06:44 -08:00
Kyle Truscott 46a5b96356 Add support for 'links' via optional interfaces (#57)
* Implement `links` via optional interfaces

* Updating example app to include links

* Update readme with links information

* Exclude a slice relationship only if the slice is empty AND there are no defined links

* Remove `Link` in favor of vanilla `map[string]interface{}`. More flexible for different allowed links spec implementations.

* Update app.go with correct Links methods

* Use LinksObject and LinkObject types along with type assertion to provide errors when marshaling an invalid links JSON API object.

* Renamed LinksObject Links and LinkObject Link

* Added back the relationship link post merge.

* Renamed the JSON* Linkable functions JSONAPI* such that when a library user implements the interface it is clear the functions are used for JSON API as opposed to JSON

* Example cleanup.

* Refactor the example to use constants from jsonapi and http.
2017-01-20 17:55:59 -08:00
Aren Patel 2cb19b89ed Skimata's null relationships + fixes (#62)
* Add support to nullify relationship; http://jsonapi.org/format/#document-resource-object-linkage

* Fixed: [null] is not valid as an empty relationship.

* add support for 'omitempty' on relationships; default behavior of marshalling empty/nil relations (i.e. w/o 'omitempty' tag) marshals with null data relation

* cleanup whitespace

* Added go 1.7 to test versions; fixed the marshaling of empty relations to return an empty array rather than a null/nil. Added a more robust test case for the marshaling of non omitted relations.

* Cleanup.

* Added a comment to UnmarshalMany

* Document the ‘omitempty’ annotation on a relation.

* Add common JSON API values as exported jsonapi pkg constants.
2017-01-20 16:13:04 -08:00
Aren Patel bb88592460 Simplify the MarshalMany implementation. For & range rather than for with int inc; etc. (#59) 2017-01-17 16:04:07 -08:00
Aren Patel 925ebf2136 Added support for string, int(8,16,32,64), uint(8,16,32,64) and each … (#51)
* Added support for string, int(8,16,32,64), uint(8,16,32,64) and each of their ptr types as acceptable to use for the ID field.

* No longer declaring a new idErr var; also eliminate the switch within a switch - if the ID field was a string or *string it will continue. Added a couple extra tests.
2016-09-22 15:02:30 -07:00
Geoff Garside b6c6609ff2 Add support for iso8601 struct tag argument (#47)
* Add support for iso8601 struct tag.

Currently only unix timestamps are supported for serialising time.Time objects. The JSON.API specification doesn't make a specific requirement on time serialisation format, though it does make a recommendation for using ISO8601.

This adds support for an additional struct tag `iso8601` which controls serialisation and deserialisation using the ISO8601 timestamp format.

* Update doc.go with information regarding iso8601 and omitempty tag arguments.
2016-09-22 13:58:07 -07:00
Aren Patel a1fa2c84a0 Feature/marshal many interface (#42)
* add support for direct use of slice of struct pointers for MarshalMany

* Added a test to ensure that whether MarshalManyPayload is called with a []interface{} or []*Struct it will produce the same desired result.

* Added a test to show how the new error type may be returned.

* Ensure the outside accessible Errs have comments.

* Page char width cleanup. Addressed warnings about duplicated "client-id" definition; using the const.
2016-09-12 22:12:42 -07:00
Aren Patel dd46e31eb5 Updated: build status badge, the go get installation instruction to account for the repo move, readme examples use ID instead of Id (so that they would be linter compliant if copy/pasted). shwoodard/jsonapi => google/jsonapi (#41) 2016-07-22 18:31:33 -07:00
Aren Patel de4994e265 Feature/omitempty (#35)
* Implemented a failing test demonstrating the intended behaviour of the omitempty annotation.

* Updated the failing test to ensure that unset field without the "omitempty" annotation are not inadvertently omitted.

* Working implementation of the "omitempty" annotation for fields that are of any type.

* Update the readme to include a brief description of how to use the `omitempty` in a attr field.

* Update the json example also using a uint for type variety.
2016-07-16 08:24:21 -07:00
Sam Woodard 81169d52b6 Merge pull request #32 from lyoung-uber/id
Update to reflect official Golang naming specifications
2016-07-15 13:32:39 -07:00
Aren Patel 0c87c2c473 Added the MarshalOnePayloadWithoutIncluded method for marshaling sing… (#34)
* Added the MarshalOnePayloadWithoutIncluded method for marshaling single objects and their relations without actually populating the "included" key with the full related object.

* Completed method description.

* Added a test to ensure that the library is capable of Unmarshmaling a payload where the One object in the payload had relationships but did not include them via "included"
2016-07-13 18:32:04 -07:00
Luke Young 57819f3b34 Follow Golang naming specifications 2016-07-05 20:32:15 -05:00
Sharon Lourduraj 04bf04450b Added support for int64 and uint64 primary id types 2016-01-07 15:14:57 -05:00
Sam Woodard d4c1f40f1d optimizations, refactors 2016-01-05 13:13:24 -08:00
Sam Woodard 438e9b0626 add support for pointers to time and if nil put null in json response 2015-10-13 09:10:10 -07:00
Sam Woodard fb2e4b68ce fix nil pointer panic 2015-10-12 11:05:06 -07:00
Sam Woodard 10e0987b5d start supporting client ids 2015-09-10 15:55:51 -07:00
Dustin Smith 1e33326303 adding methods to return the payload vs writing it 2015-08-07 17:18:10 -05:00
Sam Woodard 23302de79c paniced before when added Blog field to Post 2015-07-20 16:10:52 -07:00
Sam Woodard 8bd36714e8 fix code doc indentation 2015-07-13 15:04:21 -07:00
Sam Woodard 4c0eb15944 typo fix 2015-07-13 14:51:52 -07:00
Sam Woodard 6fb6757b35 lots more docs 2015-07-13 11:23:03 -07:00
Sam Woodard 4216780137 yay! finally figured out how to accept []interface{} 2015-07-12 11:45:03 -07:00
Sam Woodard 8f7c63b9c4 change interface of MarshalManyPayload to include reflect.Value for models 2015-07-12 11:37:31 -07:00
Sam Woodard aa2b010be5 fix unique included array algorithm 2015-07-12 08:46:30 -07:00
Sam Woodard 196492ffe5 only need the included array if sideloading 2015-07-12 08:02:29 -07:00
Sam Woodard 9b34096108 whitespace 2015-07-12 08:00:53 -07:00
Sam Woodard e7bfab161c make utility function to dry off 2015-07-12 07:59:37 -07:00
Sam Woodard ca0304f527 bug fix: don't forget some included nodes 2015-07-12 07:42:52 -07:00
Sam Woodard a6c9e05c33 marshal embedded payload now takes io rather than return struct 2015-07-10 17:34:04 -07:00
Sam Woodard 68c4bcfbb0 move a method higher for godoc 2015-07-10 17:16:26 -07:00
Sam Woodard 9b8432d9d9 bug fix: was missing objects in sideload 2015-07-10 14:31:26 -07:00
Sam Woodard b112561a72 support unmarshal sideloaded records for two-way function 2015-07-10 11:41:54 -07:00
Sam Woodard 0becfab81d remove 'JsonApi' everywhere, since we're already in a pkg 2015-07-10 09:07:12 -07:00
Sam Woodard 5fc25e655a in marshal methods, write json directly to io.Writer 2015-07-10 08:57:27 -07:00
Sam Woodard 97cf7cfca4 dry off 2015-07-10 08:25:24 -07:00
Sam Woodard 84eed2060a remove arg len check since we already do it above 2015-07-10 08:20:49 -07:00
Sam Woodard db9617ef6f omit zero times from the response 2015-07-09 12:07:33 -07:00