122016Mar

Bean Filtering In ATG REST MVC

Bean Filtering In ATG REST MVC is use to filter the response using beanFilteringConfiguration.xml of /atg/dynamo/service/filter/bean/BeanFilterService component.

Filter the Response – What does it mean?
Here filtering is used in context of sending only required properties in REST MVC response whether JSON or XML response.

How Bean Filtering Works?
ATG provides beanFilteringConfiguration.xml for manipulating the response before sending to the client. Below is the simple example.

Output Bean

public class Name{
private String firstName;
private String lastName;
private String email;
//getters & setters
}

ATG REST MVC Output (Without Bean Filtering)

{
"firstName":"John",
"lastName":"Doe",
"email":"johndoe@gmail.com",
"@class":"com.XXXXXXX.Name"
}

Apply Bean Filtering (beanFilteringConfiguration.xml)

<bean type="com.XXXXX.Name>
<filter id="summary">
<property name="firstName"/>
<property name="lastName"/>
</filter>
</bean>

ATG REST MVC Output (With Bean Filtering)

{
"firstName":"John",
"lastName":"Doe"
}

As you can see in the above example only the two property will be output as response because of bean filtering. Also, here we have used filterId=”summary” because we can have multiple filters for a bean like one filter to display one property and other filter to display two properties. And we can specify these filters in actor chains.

  • aashish patel

    There is another beautiful feature with bean filtering, you can specify a different name for a property using target attribute, like

    In the above example target is having the field which exists with the bean. in the response it goes with the name mentioned.