Discussion:
Progamatically setting JSON View
Vaibhav Dhawan
2016-03-17 13:10:11 UTC
Permalink
Hello,

Looking for a way to decide a json view on runtime based on certain
conditions with dw 0.9.2. Example

if role is user, return userview.class
if role is admin, return adminview.class

I could see that MappingJacksonValue class provides a similar feature in
spring boot and mvc. What would be the corresponding thing for dropwizard?
I have tried role based annotations on the entities/dto's but those doesnt
seem to work with dropwizard(not sure how to set security filtering feature
with dw).

I am happy with views implementation, just if i could programmatically
decide the view to be returned in my resource.
--
You received this message because you are subscribed to the Google Groups "dropwizard-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dropwizard-user+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
frankgrimes97
2016-03-17 15:01:36 UTC
Permalink
http://stackoverflow.com/questions/21778177/how-to-override-jsonview-in-jersey-resource-methods
Post by Vaibhav Dhawan
Hello,
Looking for a way to decide a json view on runtime based on certain
conditions with dw 0.9.2. Example
if role is user, return userview.class
if role is admin, return adminview.class
I could see that MappingJacksonValue class provides a similar feature in
spring boot and mvc. What would be the corresponding thing for dropwizard?
I have tried role based annotations on the entities/dto's but those doesnt
seem to work with dropwizard(not sure how to set security filtering feature
with dw).
I am happy with views implementation, just if i could programmatically
decide the view to be returned in my resource.
--
You received this message because you are subscribed to the Google Groups "dropwizard-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dropwizard-user+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
bladecatcher
2016-03-17 15:12:31 UTC
Permalink
You should be able to retrieve the User Principal and though it , the Role
that is assigned to the user. Will that work?

@RolesAllowed({"ADMIN","USER"})
@GET
public FreemarkerUserView getSecretPlan(@Context SecurityContext context) {
User userPrincipal = (User) context.getUserPrincipal();
String role = userPrincipal.getRole();
if (role.equals("ADMIN")) {
return new AdminView();
} else if (role.equals("USER")) {
return new UserView();
}
throw new WebApplicationException();
}
Post by Vaibhav Dhawan
Hello,
Looking for a way to decide a json view on runtime based on certain
conditions with dw 0.9.2. Example
if role is user, return userview.class
if role is admin, return adminview.class
I could see that MappingJacksonValue class provides a similar feature in
spring boot and mvc. What would be the corresponding thing for dropwizard?
I have tried role based annotations on the entities/dto's but those doesnt
seem to work with dropwizard(not sure how to set security filtering feature
with dw).
I am happy with views implementation, just if i could programmatically
decide the view to be returned in my resource.
--
You received this message because you are subscribed to the Google Groups "dropwizard-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dropwizard-user+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Vaibhav Dhawan
2016-03-18 04:13:49 UTC
Permalink
Thanks frank. I will try this out.

bladecatcher,

Yes, getting the role from principal is not an issue. However in my case, i
have common entities that i am returning to the consumer and i am just
using JsonViews to decide what should be returned to whom. Looks like in
your case you care creating two different objects and returning them basis
on role

Thanks
Post by Vaibhav Dhawan
Hello,
Looking for a way to decide a json view on runtime based on certain
conditions with dw 0.9.2. Example
if role is user, return userview.class
if role is admin, return adminview.class
I could see that MappingJacksonValue class provides a similar feature in
spring boot and mvc. What would be the corresponding thing for dropwizard?
I have tried role based annotations on the entities/dto's but those doesnt
seem to work with dropwizard(not sure how to set security filtering feature
with dw).
I am happy with views implementation, just if i could programmatically
decide the view to be returned in my resource.
--
You received this message because you are subscribed to the Google Groups "dropwizard-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dropwizard-user+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Tatu Saloranta
2016-03-18 04:18:03 UTC
Permalink
Frank's suggestion makes sense, as ObjectReader/WriterModifier was
specifically intended to allow dynamic configuration of JSON Views.
It is not as simple to use as it ideally would be, but integrating
configurability plug-in as part of request/response handling lifecycle is
bit challenging with JAX-RS. On plus side this can be used to configure
many different aspects aside from Views.

-+ Tatu +-
Post by Vaibhav Dhawan
Thanks frank. I will try this out.
bladecatcher,
Yes, getting the role from principal is not an issue. However in my case,
i have common entities that i am returning to the consumer and i am just
using JsonViews to decide what should be returned to whom. Looks like in
your case you care creating two different objects and returning them basis
on role
Thanks
Post by Vaibhav Dhawan
Hello,
Looking for a way to decide a json view on runtime based on certain
conditions with dw 0.9.2. Example
if role is user, return userview.class
if role is admin, return adminview.class
I could see that MappingJacksonValue class provides a similar feature in
spring boot and mvc. What would be the corresponding thing for dropwizard?
I have tried role based annotations on the entities/dto's but those
doesnt seem to work with dropwizard(not sure how to set security filtering
feature with dw).
I am happy with views implementation, just if i could programmatically
decide the view to be returned in my resource.
--
You received this message because you are subscribed to the Google Groups
"dropwizard-user" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "dropwizard-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dropwizard-user+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...