• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java PropertyPreFilter类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.alibaba.fastjson.serializer.PropertyPreFilter的典型用法代码示例。如果您正苦于以下问题:Java PropertyPreFilter类的具体用法?Java PropertyPreFilter怎么用?Java PropertyPreFilter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



PropertyPreFilter类属于com.alibaba.fastjson.serializer包,在下文中一共展示了PropertyPreFilter类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: test_0

import com.alibaba.fastjson.serializer.PropertyPreFilter; //导入依赖的package包/类
public void test_0() throws Exception {
    class VO {
        public int getId() { throw new RuntimeException(); }
    }

    PropertyPreFilter filter = new PropertyPreFilter () {
        public boolean apply(JSONSerializer serializer, Object source, String name) {
            return false;
        }
    };

    VO vo = new VO();

    String text = JSON.toJSONString(vo, filter);
    Assert.assertEquals("{}", text);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:17,代码来源:PrePropertyFilterTest.java


示例2: setFilter

import com.alibaba.fastjson.serializer.PropertyPreFilter; //导入依赖的package包/类
private static void setFilter(JSONSerializer serializer, SerializeFilter filter) {
    if (filter != null) {
        if (filter instanceof PropertyPreFilter) {
            serializer.getPropertyPreFilters().add((PropertyPreFilter) filter);
        }
        if (filter instanceof NameFilter) {
            serializer.getNameFilters().add((NameFilter) filter);
        }
        if (filter instanceof ValueFilter) {
            serializer.getValueFilters().add((ValueFilter) filter);
        }
        if (filter instanceof PropertyFilter) {
            serializer.getPropertyFilters().add((PropertyFilter) filter);
        }
        if (filter instanceof BeforeFilter) {
            serializer.getBeforeFilters().add((BeforeFilter) filter);
        }
        if (filter instanceof AfterFilter) {
            serializer.getAfterFilters().add((AfterFilter) filter);
        }
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:23,代码来源:JSON.java


示例3: setFilter

import com.alibaba.fastjson.serializer.PropertyPreFilter; //导入依赖的package包/类
private static void setFilter(JSONSerializer serializer, SerializeFilter filter) {
    if (filter == null) {
        return;
    }
    
    if (filter instanceof PropertyPreFilter) {
        serializer.getPropertyPreFilters().add((PropertyPreFilter) filter);
    }

    if (filter instanceof NameFilter) {
        serializer.getNameFilters().add((NameFilter) filter);
    }

    if (filter instanceof ValueFilter) {
        serializer.getValueFilters().add((ValueFilter) filter);
    }

    if (filter instanceof PropertyFilter) {
        serializer.getPropertyFilters().add((PropertyFilter) filter);
    }

    if (filter instanceof BeforeFilter) {
        serializer.getBeforeFilters().add((BeforeFilter) filter);
    }

    if (filter instanceof AfterFilter) {
        serializer.getAfterFilters().add((AfterFilter) filter);
    }
}
 
开发者ID:uavorg,项目名称:uavstack,代码行数:30,代码来源:JSON.java


示例4: writeInternal

import com.alibaba.fastjson.serializer.PropertyPreFilter; //导入依赖的package包/类
@Override
protected void writeInternal(Object obj, Type type, HttpOutputMessage outputMessage)
		throws IOException, HttpMessageNotWritableException {
	Charset charset = getCharset(outputMessage.getHeaders());
	OutputStreamWriter out = new OutputStreamWriter(outputMessage.getBody(), charset);
	SerializeWriter writer = new SerializeWriter(out);
	JSONSerializer serializer = new JSONSerializer(writer, this.serializeConfig);
	serializer.config(SerializerFeature.DisableCircularReferenceDetect, true);

	RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
	if (requestAttributes instanceof ServletRequestAttributes) {
		Class<?> rootClass = filterClass(obj);
		if (rootClass != null) {
			String[] paths = ((ServletRequestAttributes) requestAttributes).getRequest()
					.getParameterValues("paths");
			if (paths != null && paths.length > 0) {
				rootClass = ClassUtils.getUserClass(rootClass);
				Map<Class<?>, PropertyPreFilter> propertyFilters = new HashMap<>();
				pathVisit(propertyFilters, Sets.newHashSet(paths), rootClass);

				for (Entry<Class<?>, PropertyPreFilter> entry : propertyFilters.entrySet()) {
					serializer.getPropertyPreFilters().add(entry.getValue());
				}
			} else {

				serializer.getPropertyFilters().add(DEFAULT_PROPERTY_FILTER);
			}
		} else {
			serializer.getPropertyFilters().add(DEFAULT_PROPERTY_FILTER);
		}
	}
	serializer.write(obj);
	writer.flush();
	out.close();
}
 
开发者ID:xiangxik,项目名称:java-platform,代码行数:36,代码来源:FastjsonHttpMessageConverter.java


示例5: test_namefilter

import com.alibaba.fastjson.serializer.PropertyPreFilter; //导入依赖的package包/类
public void test_namefilter() throws Exception {
    PropertyPreFilter filter = new PropertyPreFilter() {

        public boolean apply(JSONSerializer serializer, Object object, String name) {
            return name.equals("1001");
        }

    };


    Map map = new HashMap();
    map.put(1001, 0);
    map.put(1002, 1);
    
    String text = JSON.toJSONString(map, filter);

    Assert.assertEquals("{1001:0}", text);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:19,代码来源:PropertyPrefFilterTest_IntegerKey.java


示例6: pathVisit

import com.alibaba.fastjson.serializer.PropertyPreFilter; //导入依赖的package包/类
private void pathVisit(final Map<Class<?>, PropertyPreFilter> propertyFilters, final Set<String> paths,
		Class<?> beanClass) {
	if (paths == null || beanClass == null) {
		return;
	}

	Set<String> revisePaths = new HashSet<>();
	Map<String, Set<String>> references = new HashMap<>();
	for (String path : paths) {
		if (StringUtils.contains(path, ".")) {
			String referenceProperty = StringUtils.substringBefore(path, ".");
			revisePaths.add(referenceProperty);

			Set<String> referencePaths = references.get(referenceProperty);
			if (referencePaths == null) {
				referencePaths = new HashSet<>();
				references.put(referenceProperty, referencePaths);
			}
			referencePaths.add(StringUtils.substringAfter(path, "."));
		} else {
			revisePaths.add(path);
		}
	}

	if (revisePaths.size() > 0) {
		PropertyPreFilter preFilter = propertyFilters.get(beanClass);
		if (preFilter != null) {
			if (preFilter instanceof IncludesPropertyPreFilter) {
				((IncludesPropertyPreFilter) preFilter).getIncludes().addAll(revisePaths);
			}
		} else {
			propertyFilters.put(beanClass, new IncludesPropertyPreFilter(beanClass, revisePaths));
		}

	}

	if (references.size() > 0) {
		for (Entry<String, Set<String>> reference : references.entrySet()) {
			pathVisit(propertyFilters, reference.getValue(),
					PropertyUtil.getPropertyType(beanClass, reference.getKey()));
		}
	}
}
 
开发者ID:xiangxik,项目名称:java-platform,代码行数:44,代码来源:FastjsonHttpMessageConverter.java


示例7: toJSONString

import com.alibaba.fastjson.serializer.PropertyPreFilter; //导入依赖的package包/类
public static final String toJSONString(Object object, SerializeFilter filter, SerializerFeature... features) {
    SerializeWriter out = new SerializeWriter();

    try {
        JSONSerializer serializer = new JSONSerializer(out);
        for (com.alibaba.fastjson.serializer.SerializerFeature feature : features) {
            serializer.config(feature, true);
        }

        serializer.config(SerializerFeature.WriteDateUseDateFormat, true);

        if (filter != null) {
            if (filter instanceof PropertyPreFilter) {
                serializer.getPropertyPreFilters().add((PropertyPreFilter) filter);
            }

            if (filter instanceof NameFilter) {
                serializer.getNameFilters().add((NameFilter) filter);
            }

            if (filter instanceof ValueFilter) {
                serializer.getValueFilters().add((ValueFilter) filter);
            }

            if (filter instanceof PropertyFilter) {
                serializer.getPropertyFilters().add((PropertyFilter) filter);
            }

            if (filter instanceof BeforeFilter) {
                serializer.getBeforeFilters().add((BeforeFilter) filter);
            }
            
            if (filter instanceof AfterFilter) {
                serializer.getAfterFilters().add((AfterFilter) filter);
            }
        }

        serializer.write(object);

        return out.toString();
    } finally {
        out.close();
    }
}
 
开发者ID:liufeiit,项目名称:itmarry,代码行数:45,代码来源:JSON.java



注:本文中的com.alibaba.fastjson.serializer.PropertyPreFilter类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java LineSet类代码示例发布时间:2022-05-22
下一篇:
Java IdentityInfoEntity类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap