Controlling which fields are returned

7 vaatamist
Liigu esimese lugemata sõnumi juurde

Rick Mann

lugemata,
7. okt 2016, 02:52:5407.10.16
kuni Baratine
In a REST method to return, for example, a /users/{userID} endpoint, I want to control what fields are returned. For example, anyone can see a basic subset of fields of User record, but a logged-in user can see a larger subset of fields.

What's the intended way, in Baratine, to control what subset of information is relayed? Is it to create different POJOs representing the field sets? This seems cumbersome, and prone to a lot of class proliferation.

Is there a way to create simple dictionaries that can be rendered as JSON in a result? Is there a way to render an Object to JSON, but to limit which fields are rendered?

--
Rick Mann
rm...@latencyzero.com


Alex Rojkov

lugemata,
7. okt 2016, 11:20:3807.10.16
kuni Rick Mann,Baratine
The idea is to create a DTO and that shouldn't be many. For User
object create a WebUser DTO that has the needed fields. This allows
for easier readability.

Thanks for the feedback.
> --
> You received this message because you are subscribed to the Google Groups "Baratine" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to baratine-io...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Rick Mann

lugemata,
7. okt 2016, 18:34:2507.10.16
kuni Alex Rojkov,Baratine
I can imagine a scenario in which a given endpoint has to return four variants of a user record: anonymous visitor, logged-in visitor, logged-in user (looking at own record), and customer service personnel.

Instead imagine if I could do something like this:

request.ok(myObject, "field1", "field2", "field3.subfield1", ...);

You could get fancier with wildcarding and include/exclude, but you get the idea.
--
Rick Mann
rm...@latencyzero.com


Vasta kõigile
Vasta autorile
Saada edasi
0 uut sõnumit