java - providing granular data for data intensive web service -
i developing webservice data intensive. unfortunately of data returned not needed calls, might needed call.
an overly simplified response might below:
response : { a, b, c, d : { x : { } y, z } }
i want provide flexibility callers such can request specific data big object. thought of achieving exposing enums, , taking list of enum input. each enum map field in response.
example if caller needs , d, can specify passing list of enums immutablelist.of(get_enum_a, get_enum_d) , @ web service end can compute , d.
questions: there better way of taking input (other enum) of data needed caller?
i give control user on more fine grained data, eg. can specify part of d needed. get_enum_d_x.
at server end, thinking of implementing using command pattern, having command each enum , executing if corresponding enum present in list.
- here d facade.
- if granular data requested don't use facade instead use command x.
issue can think of:
- i end many commands.
- if command subset of command , both requested execute superset command (we need in code)
is there better way of solving problem.
(ps : not interested in fragmenting smaller apis, because of use cases).
if using jackson serialize objects can take advantage of views:
http://wiki.fasterxml.com/jacksonjsonviews
basically, define view class , when serializing object pass in view want. example:
// view definitions: class views { static interface { } static interface b { } static interface c { } static class ac implements a, c { } } public class bean { @jsonview(views.a.class) public object geta() { // compute } @jsonview(views.b.class) public object getb() { // compute b } @jsonview(views.c.class) public object getc() { // compute c } }
then, when want serialize can pass in view want:
objectmapper.writevalueusingview(out, beaninstance, a.class);
if want both , c use ac class
objectmapper.writevalueusingview(out, beaninstance, ac.class);
Comments
Post a Comment