com.alibaba.fastjson.serializer.BeanContext Java Examples

The following examples show how to use com.alibaba.fastjson.serializer.BeanContext. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FastJsonUnitTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test
public void givenContextFilter_whenJavaObject_thanJsonCorrect() {
    ContextValueFilter valueFilter = new ContextValueFilter() {
        public Object process(BeanContext context, Object object, String name, Object value) {
            if (name.equals("DATE OF BIRTH")) {
                return "NOT TO DISCLOSE";
            }
            if (value.equals("John") || value.equals("Doe")) {
                return ((String) value).toUpperCase();
            } else {
                return null;
            }
        }
    };
    JSON.toJSONString(listOfPersons, valueFilter);
}