use of com.fasterxml.jackson.databind.ser.PropertyFilter in project jackson-databind by FasterXML.
the class MapSerializer method serialize.
/*
/**********************************************************
/* JsonSerializer implementation
/**********************************************************
*/
@Override
public void serialize(Map<?, ?> value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeStartObject(value);
if (!value.isEmpty()) {
if (_sortKeys || provider.isEnabled(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS)) {
value = _orderEntries(value, gen, provider);
}
PropertyFilter pf;
if ((_filterId != null) && (pf = findPropertyFilter(provider, _filterId, value)) != null) {
serializeFilteredFields(value, gen, provider, pf, _suppressableValue);
} else if ((_suppressableValue != null) || _suppressNulls) {
serializeOptionalFields(value, gen, provider, _suppressableValue);
} else if (_valueSerializer != null) {
serializeFieldsUsing(value, gen, provider, _valueSerializer);
} else {
serializeFields(value, gen, provider);
}
}
gen.writeEndObject();
}
use of com.fasterxml.jackson.databind.ser.PropertyFilter in project jackson-databind by FasterXML.
the class MapSerializer method serializeWithType.
@Override
public void serializeWithType(Map<?, ?> value, JsonGenerator gen, SerializerProvider provider, TypeSerializer typeSer) throws IOException {
typeSer.writeTypePrefixForObject(value, gen);
// [databind#631]: Assign current value, to be accessible by custom serializers
gen.setCurrentValue(value);
if (!value.isEmpty()) {
if (_sortKeys || provider.isEnabled(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS)) {
value = _orderEntries(value, gen, provider);
}
PropertyFilter pf;
if ((_filterId != null) && (pf = findPropertyFilter(provider, _filterId, value)) != null) {
serializeFilteredFields(value, gen, provider, pf, _suppressableValue);
} else if ((_suppressableValue != null) || _suppressNulls) {
serializeOptionalFields(value, gen, provider, _suppressableValue);
} else if (_valueSerializer != null) {
serializeFieldsUsing(value, gen, provider, _valueSerializer);
} else {
serializeFields(value, gen, provider);
}
}
typeSer.writeTypeSuffixForObject(value, gen);
}
use of com.fasterxml.jackson.databind.ser.PropertyFilter in project gravitee-management-rest-api by gravitee-io.
the class ObjectMapperResolver method registerFilterProvider.
private void registerFilterProvider() {
PropertyFilter apiMembershipTypeFilter = new ApiPermissionFilter();
mapper.setFilterProvider(new SimpleFilterProvider(Collections.singletonMap("apiMembershipTypeFilter", apiMembershipTypeFilter)));
}
use of com.fasterxml.jackson.databind.ser.PropertyFilter in project gravitee-management-rest-api by gravitee-io.
the class ServiceConfiguration method objectMapper.
@Bean
public ObjectMapper objectMapper() {
ObjectMapper objectMapper = new GraviteeMapper();
PropertyFilter apiMembershipTypeFilter = new ApiPermissionFilter();
objectMapper.setFilterProvider(new SimpleFilterProvider(Collections.singletonMap("apiMembershipTypeFilter", apiMembershipTypeFilter)));
return objectMapper;
}
use of com.fasterxml.jackson.databind.ser.PropertyFilter in project gravitee-management-rest-api by gravitee-io.
the class ApiService_ExportAsJsonTest method setUp.
@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.getId());
when(userService.findByUsername(memberEntity.getId(), 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);
}
Aggregations