kamikat / moshi-jsonapi

JSON API v1.0 Specification in Moshi.
MIT License
156 stars 34 forks source link

Remove ResourceNotFoundException #24

Closed mreichelt closed 8 years ago

mreichelt commented 8 years ago

Instead of using ResourceNotFoundException I suggest we should simply return null instead. Reasons:

kamikat commented 8 years ago

When a ResourceNotFoundException thrown from get() it means that the referenced resource is not provided by Document or there is not document related with current Resource object. When there is a null value of a relationship the value of HasOne<>/HasMany<> should be null, and there's no matter with ResourceNotFoundException.

kamikat commented 8 years ago

UPDATE I've update the document. We're now returning null when HasOne/HasMany cannot found resources. ResourceNotFoundException is reserved for Document.find(String, String)

mreichelt commented 8 years ago

@kamikat Thanks! Document.find(String, String) is a good example for my case: It should behave nearly like a Map in Java – which returns null if a value can not be found.

mreichelt commented 8 years ago

@kamikat I added PR https://github.com/kamikat/moshi-jsonapi/pull/25 for a simple merge-and-be-happy if you like the change. :)