Jackson EntityFiltering with Dropwizard

202 views
Skip to first unread message

Vaibhav Dhawan

unread,
Jan 29, 2016, 3:18:14 AM1/29/16
to dropwizard-user
Hello, 

I am trying to configure EntityFilteringFeature in my DW application but it doesnt seem to filter out fields. here is what i have done

Entity is listed as 

public class Cities {

private int cityId;
private String cityName;
@ProjectDetailedView
private int cityStatus;

//.. setters and getters

ProjectDetailedView is listed as 

@Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@EntityFiltering
public @interface ProjectDetailedView {

public static class Factory extends AnnotationLiteral<ProjectDetailedView> implements ProjectDetailedView {
       private Factory() {
       }
       public static ProjectDetailedView get() {
           return new Factory();
       }}}

Added following lines in app 

environment.jersey().register(EntityFilteringFeature.class);
environment.jersey().register(JacksonFeatures.class); //Probably not needed

Resource is listed as following. 

GET
@UnitOfWork
   @Produces(MediaType.APPLICATION_JSON)
//@ProjectDetailedView
   public List<Cities> getCities() {
return citiesDAO.findAll(); 
   }

I am expecting limited response when the annotation is commented out. However i get the full response in both the cases. 

Am i missing anything. Any pointers are much appreciated. 

Thanks
Vaibhav

Vaibhav Dhawan

unread,
Jan 29, 2016, 11:06:28 AM1/29/16
to dropwizard-user
I was able to get through this. Jersey entity filter dependency was missing from my pom and i though dw core would have it covered.

Still surprised why wont it throw a compilation error.

Vaibhav Dhawan

unread,
Jan 29, 2016, 11:06:44 AM1/29/16
to dropwizard-user
I was able to get through this. Jersey entity filter dependency was missing from my pom and i though dw core would have it covered.

Still surprised why wont it throw a compilation error.

On Friday, 29 January 2016 13:48:14 UTC+5:30, Vaibhav Dhawan wrote:

Ashish

unread,
Jun 21, 2016, 11:01:06 AM6/21/16
to dropwizard-user
What drop wizard version are you using  ?,  It is  not working for me  with 0.9.3 

Vaibhav Dhawan

unread,
Jun 22, 2016, 1:24:32 AM6/22/16
to dropwiz...@googlegroups.com
I am using 0.9.2 but worked well on 0.9.1 as well. Although, i moved on from this to a different solution where in i am deciding the view on basis of the user role. 



--
You received this message because you are subscribed to a topic in the Google Groups "dropwizard-user" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/dropwizard-user/9i5tdMHUDk0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to dropwizard-us...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Thanks

Vaibhav Dhawan
+919871488896

Ashish

unread,
Jun 22, 2016, 9:04:14 AM6/22/16
to dropwizard-user
I tried with both  0.9.2 and 0.9.1,  neither works for me,  here is my code could you please take a look and point  me  what I am doing wrong here?

pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.test</groupId>
<artifactId>dt</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<dropwizard.version>0.9.1</dropwizard.version>
</properties>

<dependencies>
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-core</artifactId>
<version>${dropwizard.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.ext</groupId>
<artifactId>jersey-entity-filtering</artifactId>
<version>2.23.1</version>
</dependency>
</dependencies>
</project>


Application:
public class DApplication extends Application<DConfiguration>
{
public static void main(String[] args) throws Exception
{
new DApplication().run(args);
}
@Override public void initialize(Bootstrap<DConfiguration> bootstrap)
{
super.initialize(bootstrap);
}

@Override public void run(DConfiguration dConfiguration,
Environment environment) throws Exception
{

// Does not work with the line below commented or uncommented
//environment.jersey().property(
// EntityFilteringFeature.ENTITY_FILTERING_SCOPE,
// new Annotation[] {
// Detail.Factory.get()
// }
//);
environment.jersey().register(EntityFilteringFeature.class);
environment.jersey().register(MyResource.class);
}
}

Resource :
@Path("hello")
@Produces({ MediaType.APPLICATION_JSON})
public class MyResource
{
@GET
//@Detail
public Model getModel() {
Model model = new Model();
model.setTest("abcd");
model.setDetail("efgh");
return model;
}

}


Model:
public class Model
{
private String test;

@Detail
private String detail ;

// getters and setters
}


Annotation :

@Target({ ElementType.TYPE, ElementType.METHOD ,ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@EntityFiltering
public @interface Detail
{
/**
* Factory class for creating instances of the annotation.
*/
public static class Factory extends AnnotationLiteral<Detail>
implements Detail {

private Factory() {
}

public static Detail get() {
return new Factory();
}
}

}

Harsh Desai

unread,
Oct 24, 2016, 7:37:01 PM10/24/16
to dropwizard-user
Ashish: Did you get any success around this issue? I'm facing the same issue.
Reply all
Reply to author
Forward
0 new messages