本文整理汇总了Java中com.fasterxml.jackson.databind.ser.PropertyFilter类的典型用法代码示例。如果您正苦于以下问题:Java PropertyFilter类的具体用法?Java PropertyFilter怎么用?Java PropertyFilter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PropertyFilter类属于com.fasterxml.jackson.databind.ser包,在下文中一共展示了PropertyFilter类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test
import com.fasterxml.jackson.databind.ser.PropertyFilter; //导入依赖的package包/类
@Test
public void test() throws Exception {
SomeObject someObject = new SomeObject(1, 2, 3);
PropertyFilter withoutB = SimpleBeanPropertyFilter.serializeAllExcept("b");
String actual = mapper.writeValueAsString(someObject);
Assert.assertEquals(1, parser.parse(actual).read("$.a", Integer.class).intValue());
Assert.assertEquals(2, parser.parse(actual).read("$.b", Integer.class).intValue());
Assert.assertEquals(3, parser.parse(actual).read("$.c", Integer.class).intValue());
actual = mapper.writer(new DynamicFilterProvider(withoutB)).writeValueAsString(someObject);
Assert.assertEquals(1, parser.parse(actual).read("$.a", Integer.class).intValue());
Assert.assertNull(parser.parse(actual).read("$.b"));
Assert.assertEquals(3, parser.parse(actual).read("$.c", Integer.class).intValue());
actual = mapper.writeValueAsString(someObject);
Assert.assertEquals(1, parser.parse(actual).read("$.a", Integer.class).intValue());
Assert.assertEquals(2, parser.parse(actual).read("$.b", Integer.class).intValue());
Assert.assertEquals(3, parser.parse(actual).read("$.c", Integer.class).intValue());
actual = mapper.writer(new DynamicFilterProvider()).writeValueAsString(someObject);
Assert.assertEquals(1, parser.parse(actual).read("$.a", Integer.class).intValue());
Assert.assertEquals(2, parser.parse(actual).read("$.b", Integer.class).intValue());
Assert.assertEquals(3, parser.parse(actual).read("$.c", Integer.class).intValue());
}
示例2: propertyFilterResponseBodyAdvice
import com.fasterxml.jackson.databind.ser.PropertyFilter; //导入依赖的package包/类
@Bean
public DynamicFilterResponseBodyAdvice propertyFilterResponseBodyAdvice() {
DynamicFilterResponseBodyAdvice advice = new DynamicFilterResponseBodyAdvice();
advice.addResolvers(new DynamicFilterResolver<WithoutAB>() {
@Override
public PropertyFilter apply(WithoutAB t) {
return SimpleBeanPropertyFilter.serializeAllExcept("a", "b");
}
});
return advice;
}
示例3: findPropertyFilter
import com.fasterxml.jackson.databind.ser.PropertyFilter; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public PropertyFilter findPropertyFilter(final Object filterId, final Object valueToFilter) {
if (filterId instanceof String) {
final String id = (String) filterId;
// FilterId should represent a class only in case of root entity is marshalled.
if (id.equals(root.getEntityClass().getName())) {
stack.clear();
return stack.push(root);
}
while (!stack.isEmpty()) {
final FilteringPropertyFilter peek = stack.peek();
final FilteringPropertyFilter subfilter = peek.findSubfilter(id);
if (subfilter != null) {
stack.push(subfilter);
// Need special handling for maps here - map keys can be filtered as well so we just say that every key is
// allowed.
if (valueToFilter instanceof Map) {
final Map<String, ?> map = (Map<String, ?>) valueToFilter;
return new FilteringPropertyFilter(Map.class, map.keySet(),
Collections.emptyMap());
}
return subfilter;
} else {
stack.pop();
}
}
}
return SimpleBeanPropertyFilter.filterOutAllExcept();
}
示例4: assertConfiguredWithMatcher
import com.fasterxml.jackson.databind.ser.PropertyFilter; //导入依赖的package包/类
private void assertConfiguredWithMatcher(ObjectMapper mapper, Matcher matcher) {
AnnotationIntrospector introspector = mapper.getSerializationConfig().getAnnotationIntrospector();
Object filterId = introspector.findFilterId((Annotated) AnnotatedClass.construct(
TestObject.class, introspector, mapper.getDeserializationConfig()));
assertNotNull(filterId);
PropertyFilter propertyFilter =
mapper.getSerializationConfig().getFilterProvider().findPropertyFilter(filterId, new TestObject());
assertNotNull(propertyFilter);
assertTrue(propertyFilter instanceof JacksonMatcherFilter);
assertEquals(matcher, ((JacksonMatcherFilter) propertyFilter).getMatcher());
}
示例5: resolveFilter
import com.fasterxml.jackson.databind.ser.PropertyFilter; //导入依赖的package包/类
protected Optional<PropertyFilter> resolveFilter(MethodParameter returnType) {
return resolvers.values().stream().map(resolver -> resolver.resolve(returnType))
.filter(Objects::nonNull).findFirst();
}
示例6: apply
import com.fasterxml.jackson.databind.ser.PropertyFilter; //导入依赖的package包/类
@Override
public PropertyFilter apply(SerializeAllExcept annotation) {
return SimpleBeanPropertyFilter.serializeAllExcept(annotation.value());
}
示例7: apply
import com.fasterxml.jackson.databind.ser.PropertyFilter; //导入依赖的package包/类
@Override
public PropertyFilter apply(FilterOutAllExcept annotation) {
return SimpleBeanPropertyFilter.filterOutAllExcept(annotation.value());
}
示例8: resolve
import com.fasterxml.jackson.databind.ser.PropertyFilter; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public final PropertyFilter resolve(MethodParameter methodParameter) {
return Optional.ofNullable(methodParameter.getMethodAnnotation((Class<A>) getType()))
.map(this::apply).orElse(null);
}
示例9: apply
import com.fasterxml.jackson.databind.ser.PropertyFilter; //导入依赖的package包/类
@Override
public PropertyFilter apply(WithoutAB t) {
return null;
}
示例10: registerFilterProvider
import com.fasterxml.jackson.databind.ser.PropertyFilter; //导入依赖的package包/类
private void registerFilterProvider() {
PropertyFilter apiMembershipTypeFilter = new ApiPermissionFilter();
mapper.setFilterProvider(new SimpleFilterProvider(Collections.singletonMap("apiMembershipTypeFilter", apiMembershipTypeFilter)));
}
示例11: setUp
import com.fasterxml.jackson.databind.ser.PropertyFilter; //导入依赖的package包/类
@Before
public void setUp() {
PropertyFilter apiMembershipTypeFilter = new ApiPermissionFilter();
objectMapper.setFilterProvider(new SimpleFilterProvider(Collections.singletonMap("apiMembershipTypeFilter", apiMembershipTypeFilter)));
}
示例12: setUp
import com.fasterxml.jackson.databind.ser.PropertyFilter; //导入依赖的package包/类
@Before
public void setUp() throws TechnicalException {
PropertyFilter apiMembershipTypeFilter = new ApiPermissionFilter();
objectMapper.setFilterProvider(new SimpleFilterProvider(Collections.singletonMap("apiMembershipTypeFilter", apiMembershipTypeFilter)));
Api api = new Api();
api.setId(API_ID);
api.setDescription("Gravitee.io");
when(apiRepository.findById(API_ID)).thenReturn(Optional.of(api));
PageEntity page = new PageEntity();
page.setName("My Title");
page.setOrder(1);
page.setType(PageType.MARKDOWN.toString());
page.setContent("Read the doc");
when(pageService.findApiPagesByApi(API_ID)).thenReturn(Collections.singletonList(new PageListItem()));
when(pageService.findById(any())).thenReturn(page);
Membership membership = new Membership();
membership.setUserId("johndoe");
membership.setReferenceId(API_ID);
membership.setReferenceType(MembershipReferenceType.API);
membership.setRoles(Collections.singletonMap(RoleScope.API.getId(), SystemRole.PRIMARY_OWNER.name()));
when(membershipRepository.findByReferenceAndRole(eq(MembershipReferenceType.API), eq(API_ID), any(), any()))
.thenReturn(Collections.singleton(membership));
MemberEntity memberEntity = new MemberEntity();
memberEntity.setUsername(membership.getUserId());
memberEntity.setRole(SystemRole.PRIMARY_OWNER.name());
when(membershipService.getMembers(eq(MembershipReferenceType.API), eq(API_ID), eq(RoleScope.API)))
.thenReturn(Collections.singleton(memberEntity));
UserEntity userEntity = new UserEntity();
userEntity.setUsername(memberEntity.getUsername());
when(userService.findByName(memberEntity.getUsername(), false)).thenReturn(userEntity);
api.setGroups(Collections.singleton("my-group"));
GroupEntity groupEntity = new GroupEntity();
groupEntity.setId("my-group");
groupEntity.setName("My Group");
when(groupService.findByIds(api.getGroups())).thenReturn(Collections.singleton(groupEntity));
PlanEntity publishedPlan = new PlanEntity();
publishedPlan.setId("plan-id");
publishedPlan.setApis(Collections.singleton(API_ID));
publishedPlan.setDescription("free plan");
publishedPlan.setType(PlanType.API);
publishedPlan.setSecurity(PlanSecurityType.API_KEY);
publishedPlan.setValidation(PlanValidationType.AUTO);
publishedPlan.setStatus(PlanStatus.PUBLISHED);
Map<String, Path> paths = new HashMap<>();
Path path = new Path();
path.setPath("/");
io.gravitee.definition.model.Rule rule = new io.gravitee.definition.model.Rule();
rule.setEnabled(true);
rule.setMethods(Collections.singletonList(HttpMethod.GET));
Policy policy = new Policy();
policy.setName("rate-limit");
String ls = System.lineSeparator();
policy.setConfiguration("{" + ls +
" \"rate\": {" + ls +
" \"limit\": 1," + ls +
" \"periodTime\": 1," + ls +
" \"periodTimeUnit\": \"SECONDS\"" + ls +
" }" + ls +
" }");
rule.setPolicy(policy);
path.setRules(Collections.singletonList(rule));
paths.put("/", path);
publishedPlan.setPaths(paths);
PlanEntity closedPlan = new PlanEntity();
closedPlan.setId("closedPlan-id");
closedPlan.setApis(Collections.singleton(API_ID));
closedPlan.setDescription("free closedPlan");
closedPlan.setType(PlanType.API);
closedPlan.setSecurity(PlanSecurityType.API_KEY);
closedPlan.setValidation(PlanValidationType.AUTO);
closedPlan.setStatus(PlanStatus.CLOSED);
closedPlan.setPaths(paths);
Set<PlanEntity> set = new HashSet<>();
set.add(publishedPlan);
set.add(closedPlan);
when(planService.findByApi(API_ID)).thenReturn(set);
}
示例13: defaultFiler
import com.fasterxml.jackson.databind.ser.PropertyFilter; //导入依赖的package包/类
public JsonMapper defaultFiler(PropertyFilter bpf){
// this.filterProvider.setDefaultFilter(bpf);
this.filterProvider.setDefaultFilter(bpf);
return this;
}
示例14: DynamicFilterProvider
import com.fasterxml.jackson.databind.ser.PropertyFilter; //导入依赖的package包/类
/**
* Construct a {@code PropertyFilterHolder} for given {@code delegate}
*
* @param delegate PropertyFilter
* @throws NullPointerException if {@code delegate} is {@code null}
*/
public DynamicFilterProvider(PropertyFilter delegate) {
this.delegate = requireNonNull(delegate);
addFilter(FILTER_ID, this);
}