本文整理汇总了Java中com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider类的典型用法代码示例。如果您正苦于以下问题:Java SimpleFilterProvider类的具体用法?Java SimpleFilterProvider怎么用?Java SimpleFilterProvider使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SimpleFilterProvider类属于com.fasterxml.jackson.databind.ser.impl包,在下文中一共展示了SimpleFilterProvider类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initializeObjectMapper
import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider; //导入依赖的package包/类
@Override
protected ObjectMapper initializeObjectMapper() {
final ObjectMapper mapper = super.initializeObjectMapper();
final FilterProvider filters = new SimpleFilterProvider()
.addFilter("beanObjectFilter", new CasSimpleBeanObjectFilter());
mapper.setFilters(filters);
mapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
mapper.configure(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS, false);
mapper.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false);
mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
mapper.addMixIn(Object.class, CasSimpleBeanObjectFilter.class);
mapper.disable(SerializationFeature.INDENT_OUTPUT);
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
return mapper;
}
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:20,代码来源:InternalConfigStateController.java
示例2: findAllTest2
import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider; //导入依赖的package包/类
@Test
public void findAllTest2() throws Exception {
Auction auction = new Auction();
auction.setRealmId(1);
auction.setItemId(124105);
List<Auction> auctions = auctionService.findAll(auction);
ObjectMapper mapper = new ObjectMapper();
FilterProvider filters = new SimpleFilterProvider().addFilter("auctionFilter",
SimpleBeanPropertyFilter.filterOutAllExcept("owner"));
MappingJacksonValue mappingJacksonValue = new MappingJacksonValue(auctions);
mappingJacksonValue.setFilters(filters);
System.out.println(mappingJacksonValue.getValue());
}
示例3: createMapper
import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider; //导入依赖的package包/类
private ObjectMapper createMapper(JsonFactory mapping, ClassLoader classLoader) {
ObjectMapper mapper = new ObjectMapper(mapping);
mapper.addMixIn(MasterSlaveServersConfig.class, MasterSlaveServersConfigMixIn.class);
mapper.addMixIn(SingleServerConfig.class, SingleSeverConfigMixIn.class);
mapper.addMixIn(Config.class, ConfigMixIn.class);
mapper.addMixIn(CodecProvider.class, ClassMixIn.class);
mapper.addMixIn(ResolverProvider.class, ClassMixIn.class);
mapper.addMixIn(Codec.class, ClassMixIn.class);
mapper.addMixIn(RedissonNodeInitializer.class, ClassMixIn.class);
mapper.addMixIn(LoadBalancer.class, ClassMixIn.class);
FilterProvider filterProvider = new SimpleFilterProvider()
.addFilter("classFilter", SimpleBeanPropertyFilter.filterOutAllExcept());
mapper.setFilterProvider(filterProvider);
mapper.setSerializationInclusion(Include.NON_NULL);
if (classLoader != null) {
TypeFactory tf = TypeFactory.defaultInstance()
.withClassLoader(classLoader);
mapper.setTypeFactory(tf);
}
return mapper;
}
示例4: testSerializeComment
import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider; //导入依赖的package包/类
@Test
public void testSerializeComment() throws IOException
{
final Comment aComment = new Comment();
aComment.setContent("<b>There it is</b>");
ByteArrayOutputStream out = new ByteArrayOutputStream();
jsonHelper.withWriter(out, new Writer()
{
@Override
public void writeContents(JsonGenerator generator, ObjectMapper objectMapper)
throws JsonGenerationException, JsonMappingException, IOException
{
FilterProvider fp = new SimpleFilterProvider().addFilter(
JacksonHelper.DEFAULT_FILTER_NAME, new ReturnAllBeanProperties());
objectMapper.writer(fp).writeValue(generator, aComment);
}
});
assertTrue(out.toString().contains("{\"content\":\"<b>There it is</b>\""));
}
示例5: testNullInComment
import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider; //导入依赖的package包/类
@Test
public void testNullInComment() throws IOException
{
final Comment aComment = new Comment();
aComment.setContent(null);
ByteArrayOutputStream out = new ByteArrayOutputStream();
jsonHelper.withWriter(out, new Writer()
{
@Override
public void writeContents(JsonGenerator generator, ObjectMapper objectMapper)
throws JsonGenerationException, JsonMappingException, IOException
{
FilterProvider fp = new SimpleFilterProvider().addFilter(
JacksonHelper.DEFAULT_FILTER_NAME, new ReturnAllBeanProperties());
objectMapper.writer(fp).writeValue(generator, aComment);
}
});
assertEquals("Null values should not be output.", "{\"canEdit\":false,\"canDelete\":false}",
out.toString());
}
示例6: renderSimpleBeanWithFilters
import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider; //导入依赖的package包/类
@Test
public void renderSimpleBeanWithFilters() throws Exception {
TestSimpleBeanFiltered bean = new TestSimpleBeanFiltered();
bean.setProperty1("value");
bean.setProperty2("value");
Map<String, Object> model = new HashMap<String, Object>();
model.put("bindingResult", mock(BindingResult.class, "binding_result"));
model.put("foo", bean);
FilterProvider filters = new SimpleFilterProvider().addFilter("myJacksonFilter",
SimpleBeanPropertyFilter.serializeAllExcept("property2"));
model.put(FilterProvider.class.getName(), filters);
view.setUpdateContentLength(true);
view.render(model, request, response);
String content = response.getContentAsString();
assertTrue(content.length() > 0);
assertEquals(content.length(), response.getContentLength());
assertThat(content, containsString("\"property1\":\"value\""));
assertThat(content, not(containsString("\"property2\":\"value\"")));
assertFalse(content.contains(FilterProvider.class.getName()));
}
示例7: getDefaultObjectMapper
import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider; //导入依赖的package包/类
private ObjectMapper getDefaultObjectMapper(boolean xml, boolean details, TreeNode<String, Boolean> perms) {
if (perms == null) {
throw new NullPointerException("Permissions may not be null");
}
ObjectMapper om = xml ? new XmlMapper() : new ObjectMapper();
om.setSerializationInclusion(JsonInclude.Include.NON_NULL);
SimpleModule mod = new SimpleModule();
for (Map.Entry<Class, BaseSerializer> entry : serializers.entrySet()) {
mod.addSerializer(entry.getKey(), entry.getValue());
}
mod.addDeserializer(ItemStack.class, new ItemStackDeserializer());
mod.addDeserializer(BlockState.class, new BlockStateDeserializer());
mod.addDeserializer(ItemStackSnapshot.class, new ItemStackSnapshotDeserializer());
mod.addDeserializer(Location.class, new LocationDeserializer());
om.registerModule(mod);
SimpleFilterProvider filterProvider = new SimpleFilterProvider();
filterProvider.addFilter(BaseFilter.ID, new BaseFilter(details, perms));
om.setFilterProvider(filterProvider);
om.setAnnotationIntrospector(new AnnotationIntrospector(details));
return om;
}
示例8: testReadRdf
import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider; //导入依赖的package包/类
@Test
public void testReadRdf() throws IOException, JsonLdError {
// FIXME this does not really test the output
PhenoPacket packet = YamlReader
.readFile("src/test/resources/context/phenopacket-with-context.yaml");
Model model = RdfGenerator.toRdf(packet, null);
String packetID = packet.getId();
PhenoPacket newPacket = RdfReader.readModel(model,
ContextUtil.expandIdentifierAsValue(packetID, packet));
ObjectMapper m = new ObjectMapper();
m.setSerializationInclusion(JsonInclude.Include.NON_NULL);
m.setFilterProvider(new SimpleFilterProvider().addFilter(
"PhenoPacketClass", SimpleBeanPropertyFilter.serializeAll()));
ObjectWriter writer = m.writerWithDefaultPrettyPrinter();
System.out.println(writer.writeValueAsString(newPacket));
}
示例9: ensureThatSerializingASymbolWithoutProjectDoesNotCrash
import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider; //导入依赖的package包/类
@Test
public void ensureThatSerializingASymbolWithoutProjectDoesNotCrash() throws JsonProcessingException {
String expectedJson = "{\"actions\":["
+ "{\"type\":\"web_click\",\"disabled\":false,\"negated\":false,\"ignoreFailure\":false,"
+ "\"errorOutput\":null,\"node\":null,\"doubleClick\":false},"
+ "{\"type\":\"web_checkForText\",\"disabled\":false,\"negated\":false,\"ignoreFailure\":false,"
+ "\"errorOutput\":null,\"value\":\"F[oO0]+\",\"regexp\":true},"
+ "{\"type\":\"wait\",\"disabled\":false,\"negated\":false,\"ignoreFailure\":false,"
+ "\"errorOutput\":null,\"duration\":" + ONE_SECOND + "}"
+ "],\"group\":2,\"id\":null,\"name\":\"WebSymbol\",\"project\":null,\"successOutput\":null}";
symbol.setProject(null);
ObjectMapper mapper = new ObjectMapper();
mapper.addMixInAnnotations(Object.class, PropertyFilterMixIn.class);
SimpleBeanPropertyFilter filter = SimpleBeanPropertyFilter.serializeAllExcept("hidden");
FilterProvider filters = new SimpleFilterProvider().addFilter("filter properties by name", filter);
String json = mapper.writer(filters).writeValueAsString(symbol);
assertEquals(expectedJson, json);
}
示例10: JsonManager
import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider; //导入依赖的package包/类
/**
* Create a new JsonManager
* @param theClass The class to create a json manager for (yes, also in the diamonds).
*/
public JsonManager (Class<T> theClass) {
this.theClass = theClass;
this.mapper = new ObjectMapper();
mapper.addMixInAnnotations(Rectangle2D.class, Rectangle2DMixIn.class);
mapper.registerModule(new GeoJsonModule());
SimpleModule deser = new SimpleModule();
deser.addDeserializer(LocalDate.class, new JacksonSerializers.LocalDateStringDeserializer());
deser.addSerializer(LocalDate.class, new JacksonSerializers.LocalDateStringSerializer());
deser.addDeserializer(Rectangle2D.class, new Rectangle2DDeserializer());
mapper.registerModule(deser);
mapper.getSerializerProvider().setNullKeySerializer(new JacksonSerializers.MyDtoNullKeySerializer());
filters = new SimpleFilterProvider();
filters.addFilter("bbox", SimpleBeanPropertyFilter.filterOutAllExcept("west", "east", "south", "north"));
this.writer = mapper.writer(filters);
}
示例11: createTest
import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider; //导入依赖的package包/类
@Test
public void createTest() throws Exception {
EntrezGene
gene = new EntrezGene(6L, "GeneF", 9606, "", "10", "", "", "protein-coding", null, null, null);
objectMapper.setFilterProvider(new SimpleFilterProvider().addFilter("fieldFilter",
SimpleBeanPropertyFilter.serializeAllExcept()).setFailOnUnknownId(false));
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
mockMvc.perform(post(BASE_URL)
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsBytes(gene)))
.andExpect(status().isCreated())
.andExpect(jsonPath("$", hasKey("entrezGeneId")))
.andExpect(jsonPath("$.entrezGeneId", is(6)));
mockMvc.perform(get(BASE_URL + "/{id}", 6L))
.andExpect(status().isOk())
.andExpect(jsonPath("$.entrezGeneId", is(6)));
geneRepository.delete(6L);
}
示例12: getObjectWriter
import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider; //导入依赖的package包/类
private ObjectWriter getObjectWriter(ObjectMapper mapper, String[] fieldsToReturn) {
if (fieldsToReturn.length != 0) {
mapper.addMixInAnnotations(
Object.class, PropertyFilterMixIn.class);
HashSet<String> givenFields = new HashSet<>();
givenFields.add("schemas");
Collections.addAll(givenFields, fieldsToReturn);
String[] finalFieldsToReturn = givenFields.toArray(new String[givenFields.size()]);
FilterProvider filters = new SimpleFilterProvider()
.addFilter("filter properties by name",
SimpleBeanPropertyFilter.filterOutAllExcept(
finalFieldsToReturn));
return mapper.writer(filters);
}
return mapper.writer();
}
示例13: filterProvider
import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider; //导入依赖的package包/类
@Bean
public SimpleFilterProvider filterProvider() {
final Set<String> set = ImmutableSet.of(
"indexProtocol",
"indexPort",
"serviceProtocol",
"servicePort",
"productType",
"productTypeRegex",
"indexErrorMessage",
"plaintextPassword",
"currentPassword"
);
final SimpleBeanPropertyFilter.SerializeExceptFilter filter = new SimpleBeanPropertyFilter.SerializeExceptFilter(set);
return new SimpleFilterProvider(ImmutableMap.of("configurationFilter", filter));
}
示例14: setUp
import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider; //导入依赖的package包/类
@Before
public void setUp() {
_objectMapper = new ObjectMapper();
_objectMapper.setAnnotationIntrospector(new StenoAnnotationIntrospector(_objectMapper));
// CHECKSTYLE.OFF: IllegalInstantiation - No Guava dependency here.
final Map<String, Object> filterMap = new HashMap<>();
// CHECKSTYLE.ON: IllegalInstantiation
filterMap.put(RedactionFilter.REDACTION_FILTER_ID, new RedactionFilter(false));
_objectMapper.setFilterProvider(new SimpleFilterProvider(filterMap));
// CHECKSTYLE.OFF: IllegalInstantiation - No Guava dependency here.
final Map<String, Object> beanMap = new HashMap<>();
// CHECKSTYLE.ON: IllegalInstantiation
beanMap.put("foo", "bar");
_redactedBean = new RedactedBean("string", 1234, 1.0d, new String[] {"string1", "string2"}, true, beanMap);
_nonRedactedBean = new NonRedactedBean("string", 1234, 1.0d, new String[] {"string1", "string2"}, true, beanMap);
}
示例15: testDeprecatedSerializeAsFieldWithNull
import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider; //导入依赖的package包/类
/**
* @deprecated Provided for test compatibility with deprecated method in Jackson.
*/
@Test
@Deprecated
public void testDeprecatedSerializeAsFieldWithNull() throws Exception {
final RedactionFilter mockFilter = Mockito.mock(RedactionFilter.class);
Mockito.doAnswer(new SerializeAsFieldAnswer(new RedactionFilter(true)))
.when(mockFilter).serializeAsField(
Mockito.any(),
Mockito.any(JsonGenerator.class),
Mockito.any(SerializerProvider.class),
Mockito.any(PropertyWriter.class));
// CHECKSTYLE.OFF: IllegalInstantiation - No Guava dependency here.
final Map<String, Object> filterMap = new HashMap<>();
// CHECKSTYLE.ON: IllegalInstantiation
filterMap.put(RedactionFilter.REDACTION_FILTER_ID, mockFilter);
_objectMapper.setFilters(new SimpleFilterProvider(filterMap));
final JsonNode actualTree = _objectMapper.valueToTree(_redactedBean);
final JsonNode expectedTree = readTree("testDeprecatedSerializeAsFieldWithNull.json");
Assert.assertEquals(expectedTree, actualTree);
}