Commit Graph

57 Commits

Author SHA1 Message Date
Preston Baxter 403bd2e40b handle pointers being dumb 2023-11-21 19:14:36 -06:00
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
Aren Patel 58702143d4
Revert "Add RFC3339 timestamp (#201)" (#203)
This reverts commit c0ee6d2554.
2021-04-03 09:11:22 -07:00
Omar Ismail c0ee6d2554
Add RFC3339 timestamp (#201)
@omarismail LGTM.

I'm curious what you think about perhaps documenting these `iso8601` and `rfc3339` in the `Readme.md`? How did you find that this tag option/value existed? How can we make this better for others vs having to search the library implementation?
2021-04-02 17:10:43 -07:00
Quetzy Garcia b10ff4bf78
[FIX] Issue 176 (#199)
* fix(request): change the order of the resource data check to prioritise the type when unmarshalling
- fixes #176

* tests(request): update the TestUnmarshalPayload_ptrsAllNil test that broke

* Using %v instead of %s

* Added a test case to demonstrate that this library follows the spec: covered the case where the incoming request payload is missing the `type` field, an error is expected.

Co-authored-by: Aren Patel <git@arenpatel.com>
2021-03-06 12:33:18 -08:00
Sam Woodard ed08d4f02a refactor, consistency, add test to ensure we don't need additional type check 2018-10-05 08:57:33 -07:00
Sam Woodard d05fcd97df one line method removed 2018-10-05 08:56:32 -07:00
Sam Woodard ab24913148 adjust test so values are like from a json payload 2018-10-05 07:29:18 -07:00
CrushedPixel 87c6b8e5b5 Fixed format types 2018-10-05 07:29:06 -07:00
CrushedPixel ccac636b4b Add support for attributes of custom defined types 2018-10-05 07:10:00 -07:00
Sam Woodard 3c8221b373 use jsonapi tags for nested attrs 2018-10-03 13:51:04 -07:00
Markus Ritberger 72f7bad5b3 check for ptr error type in tests 2018-03-14 21:43:24 +01:00
Markus Ritberger 21b4945ad6
Merge pull request #3 from msabramo/pr-99-make-nested-struct-ptr-work
Make nested struct pointers work
2018-01-22 12:11:07 +01:00
Markus Ritberger bb266b4483
Merge pull request #2 from msabramo/pr-99-show-type-for-ErrUnsupportedPtrType
Show type for ErrUnsupportedPtrType
2018-01-22 08:33:37 +01:00
Marc Abramowitz a3b3bb2cb5 Show type for ErrUnsupportedPtrType
to aid in troubleshooting.

Before:

```
Pointer type in struct is not supported
```

After:

```
jsonapi: Can't unmarshal true (bool) to struct field `Name`, which is a pointer to `string`
```
2018-01-17 13:38:32 -08:00
Marc Abramowitz b28beab7f3 Add TestUnmarshalNestedStructPtr 2018-01-17 13:02:30 -08:00
Marc Abramowitz e3c0871f34 Test more things in TestUnmarshalNestedStruct 2018-01-17 08:12:59 -08:00
Slemgrim 0400041771 fix wrong type for formatting 2017-11-21 19:15:24 +08:00
Slemgrim a6577dfae8 Add more speaking tests
tests should have an expected outcome vs. an actual outcome to make them easier to debug
2017-11-21 19:05:50 +08:00
Slemgrim 7e5c9014d9 Merge remote-tracking branch 'upstream/master' 2017-11-21 18:42:48 +08:00
Aren Patel a06052dd83
Run gofmt -s to simplifiy. 2017-09-13 12:59:59 -07:00
Slemgrim af21dba1b2 handle nested struct slices 2017-07-15 15:22:03 +02: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
Anthony Dodd bce7629682 Use subtests (can only test against go >= 1.7 now). (#63) 2017-02-17 15:11:39 -08:00
Aren Patel 0a2decba43 Make the Meta test also check for the value of the detail key. Moving all testing models to their own file. Updated the readme to include a deeply nested, varying typed meta example. Convert the map[string]interface to a Meta in the tests. Make the Meta field of a Link of type Meta rather than a map[string]inteface{}. Use the headerAccept constant defined for the example app. Commenting the new Metable interface and moving the Meta type beside it. Example app updated to use jsonapi.Links and jsonapi.Meta types rather than the underlying map[string]interface{}. 2017-02-16 20:28:09 -08:00
Aren Patel 7d60f153a2 Added test (serialization, deserialization) for the []string attr feature. 2017-02-03 15:18:58 -08:00
Mirek Petricek 6e6258e1ab Remove accidentaly introduced? noisy println from tests (#75)
* use constants rather than strings in request.go

* Remove accidentaly introduced? noisy println from tests
2017-02-03 14:45:34 -08:00
Anthony Dodd 1e69609202
Revert use of new error system in `request.go`.
Update tests to account for generic `errors.New` use.
2017-01-31 13:36:56 -06:00
Anthony Dodd 5836d603a3
Handle type errors properly during unmarshal node.
During the `unmarshalNode` routine, various type errors may come up.
Currently they are being swallowed by the error handling mechanism.
Rework that system so that errors are actually exposed and can be
corrected without having to dive into the code.

Handle time.Time & *time.Time type errors.

Add test for unmarshalling ptr with bad type.

Final `attr` type check catch-all & tests.

Implement system for JSON API compatible errors.

This commit creates a series of structs and interfaces for representing
JSON API compatible error objects. It includes a method for emitting a
payload of error objects (according to the JSON API spec). Its algorithm
is based upon a series of interfaces which define incremental levels of
support for errors which are JSON API compatible.

Use new error type for unmarshalling errors.

Update some docs & the privacy of a func.

Don't be prescriptive on `meta`. Use map[string]interface{}.

Add a README section on errors &c.

Do not force inclusion of `title` & `detail` (use omitempty).

Update README & docs on use of pertient errors related types.

Update tests to account for these changes.

If error type is already *ErrorObject, return immediately.

Rm everything except for ErrorsPayload, ErrorObject & MarshalErrors.

Also update README & tests.

Remove a test fixture which is no longer needed.
2017-01-31 13:06:10 -06:00
Aren Patel 3ea9ec4904 Testing and Documentation for UnmarshalManyPayload (#66)
* Added a test for UnmarshalManyPayload

* Document UnmarshalManyPayload in the Readme

* Update the example app to have a UnmarshalManyPayload usage.

* DRY the UnmarshalManyPayload implementation.

* Add a test for grabbing the Links out of a ManyPayload
2017-01-26 15:25:13 -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 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 a70d58d3c8 Support pointers as attrs (#40)
* add support to unmarshal attributes to struct field that are ptr types

* Spacing, addressed all the linter warnings, comments to describe errors, cleanup, left a TODO note to resolve the Error messaging.
2016-07-22 18:34:38 -07:00
Sam Woodard 3b09fe9cb9 fix the build 2016-07-15 13:40:23 -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
Sam Woodard d4c1f40f1d optimizations, refactors 2016-01-05 13:13:24 -08:00
Sam Woodard 57cb7c9f3f Merge remote-tracking branch 'origin/master' into client-ids
* origin/master:
  Fix issue #10 to avoid panics with invalid JSON
2015-10-12 11:08:23 -07:00
Sam Woodard d9645f7f7e major code simplification while making client ids work 2015-09-17 15:55:53 -07:00
Sam Woodard 10e0987b5d start supporting client ids 2015-09-10 15:55:51 -07:00
Christian Klotz b11e9985b4 Fix issue #10 to avoid panics with invalid JSON 2015-08-29 18:29:58 +01: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 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 a228611aa0 skip field if attr is not in the hash 2015-07-09 12:27:03 -07:00
Sam Woodard c887cfc585 Add test for set id 2015-07-08 13:11:03 -07:00