当前位置: 首页>>代码示例>>Java>>正文


Java FilterProvider类代码示例

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


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

示例1: initializeObjectMapper

import com.fasterxml.jackson.databind.ser.FilterProvider; //导入依赖的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.FilterProvider; //导入依赖的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());
}
 
开发者ID:liufeng0103,项目名称:bnade-web-ssh,代码行数:15,代码来源:AuctionServiceTest.java

示例3: createMapper

import com.fasterxml.jackson.databind.ser.FilterProvider; //导入依赖的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;
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:24,代码来源:ConfigSupport.java

示例4: testSerializeComment

import com.fasterxml.jackson.databind.ser.FilterProvider; //导入依赖的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>\""));
}
 
开发者ID:Alfresco,项目名称:alfresco-remote-api,代码行数:21,代码来源:JsonJacksonTests.java

示例5: testNullInComment

import com.fasterxml.jackson.databind.ser.FilterProvider; //导入依赖的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());
}
 
开发者ID:Alfresco,项目名称:alfresco-remote-api,代码行数:22,代码来源:JsonJacksonTests.java

示例6: renderSimpleBeanWithFilters

import com.fasterxml.jackson.databind.ser.FilterProvider; //导入依赖的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()));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:23,代码来源:MappingJackson2JsonViewTests.java

示例7: ensureThatSerializingASymbolWithoutProjectDoesNotCrash

import com.fasterxml.jackson.databind.ser.FilterProvider; //导入依赖的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);
}
 
开发者ID:LearnLib,项目名称:alex,代码行数:23,代码来源:WebSymbolTest.java

示例8: getObjectWriter

import com.fasterxml.jackson.databind.ser.FilterProvider; //导入依赖的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();
    }
 
开发者ID:osiam,项目名称:resource-server,代码行数:20,代码来源:AttributesRemovalHelper.java

示例9: FindConfigFileService

import com.fasterxml.jackson.databind.ser.FilterProvider; //导入依赖的package包/类
protected FindConfigFileService(final FilterProvider filterProvider,
                                final TextEncryptor textEncryptor,
                                final JsonSerializer<FieldPath> fieldPathSerializer,
                                final JsonDeserializer<FieldPath> fieldPathDeserializer) {

    final ObjectMapper objectMapper = new Jackson2ObjectMapperBuilder()
        .featuresToEnable(SerializationFeature.INDENT_OUTPUT)
        .mixIns(customMixins())
        .serializersByType(ImmutableMap.of(FieldPath.class, fieldPathSerializer))
        .deserializersByType(ImmutableMap.of(FieldPath.class, fieldPathDeserializer))
        .createXmlMapper(false)
        .build();

    setConfigFileLocation(CONFIG_FILE_LOCATION);
    setConfigFileName(CONFIG_FILE_NAME);
    setDefaultConfigFile(getDefaultConfigFile());
    setMapper(objectMapper);
    setTextEncryptor(textEncryptor);
    setFilterProvider(filterProvider);
}
 
开发者ID:hpe-idol,项目名称:find,代码行数:21,代码来源:FindConfigFileService.java

示例10: configureJSONExporter

import com.fasterxml.jackson.databind.ser.FilterProvider; //导入依赖的package包/类
protected void configureJSONExporter() {
    mapper = new ObjectMapper();
    
    // configure
    mapper.enable(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS);
    
    // set Mixins
    mapper.addMixInAnnotations(BaseNode.class, JsonExportBaseNodeMixin.class);
    mapper.addMixInAnnotations(TaskNode.class, JsonExportBaseNodeMixin.class);
    mapper.addMixInAnnotations(EventNode.class, JsonExportBaseNodeMixin.class);
    mapper.addMixInAnnotations(InfoNode.class, JsonExportBaseNodeMixin.class);
    mapper.addMixInAnnotations(SymLinkNode.class, JsonExportBaseNodeMixin.class);
    mapper.addMixInAnnotations(UrlResNode.class, JsonExportBaseNodeMixin.class);
    
    // add additional filters
    mapper.addMixInAnnotations(Object.class, PropertyFilterMixIn.class);
    String[] ignorableFieldNames = {"importTmpId", "fullSrc", "srcName"};
    FilterProvider filters = new SimpleFilterProvider().addFilter("filter properties by name",
                    SimpleBeanPropertyFilter.serializeAllExcept(ignorableFieldNames));
    writer = mapper.writer(filters);
}
 
开发者ID:das-praktische-schreinerlein,项目名称:your-all-in-one,代码行数:22,代码来源:JSONFullExporter.java

示例11: getPathsForProfile

import com.fasterxml.jackson.databind.ser.FilterProvider; //导入依赖的package包/类
@SuppressWarnings("deprecation")
@RequestMapping(value = "/api/path", method = RequestMethod.GET)
@ResponseBody
public String getPathsForProfile(Model model, String profileIdentifier,
                                 @RequestParam(value = "typeFilter[]", required = false) String[] typeFilter,
                                 @RequestParam(value = "clientUUID", defaultValue = Constants.PROFILE_CLIENT_DEFAULT_ID) String clientUUID) throws Exception {
    int profileId = ControllerUtils.convertProfileIdentifier(profileIdentifier);
    List<EndpointOverride> paths = PathOverrideService.getInstance().getPaths(profileId, clientUUID, typeFilter);

    HashMap<String, Object> jqReturn = Utils.getJQGridJSON(paths, "paths");

    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.addMixInAnnotations(Object.class, ViewFilters.GetPathFilter.class);
    String[] ignorableFieldNames = {"possibleEndpoints", "enabledEndpoints"};
    FilterProvider filters = new SimpleFilterProvider().addFilter("Filter properties from the PathController GET",
                                                                  SimpleBeanPropertyFilter.serializeAllExcept(ignorableFieldNames));

    ObjectWriter writer = objectMapper.writer(filters);

    return writer.writeValueAsString(jqReturn);
}
 
开发者ID:groupon,项目名称:odo,代码行数:22,代码来源:PathController.java

示例12: testPath

import com.fasterxml.jackson.databind.ser.FilterProvider; //导入依赖的package包/类
@RequestMapping(value = "/api/path/test", method = RequestMethod.GET)
@ResponseBody
public String testPath(@RequestParam String url, @RequestParam String profileIdentifier,
                       @RequestParam Integer requestType) throws Exception {
    int profileId = ControllerUtils.convertProfileIdentifier(profileIdentifier);

    List<EndpointOverride> trySelectedRequestPaths = PathOverrideService.getInstance().getSelectedPaths(Constants.OVERRIDE_TYPE_REQUEST,
                                                                                                        ClientService.getInstance().findClient("-1", profileId),
                                                                                                        ProfileService.getInstance().findProfile(profileId), url, requestType, true);

    HashMap<String, Object> jqReturn = Utils.getJQGridJSON(trySelectedRequestPaths, "paths");

    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.addMixInAnnotations(Object.class, ViewFilters.GetPathFilter.class);
    String[] ignorableFieldNames = {"possibleEndpoints", "enabledEndpoints"};
    FilterProvider filters = new SimpleFilterProvider().addFilter("Filter properties from the PathController GET",
                                                                  SimpleBeanPropertyFilter.serializeAllExcept(ignorableFieldNames));

    ObjectWriter writer = objectMapper.writer(filters);

    return writer.writeValueAsString(jqReturn);
}
 
开发者ID:groupon,项目名称:odo,代码行数:23,代码来源:PathController.java

示例13: objectToJsonExclude

import com.fasterxml.jackson.databind.ser.FilterProvider; //导入依赖的package包/类
public static String objectToJsonExclude(Object data,String filterName, String  ...exName) {
  	try {
          SimpleBeanPropertyFilter theFilter = SimpleBeanPropertyFilter
                  .serializeAllExcept(exName);
          FilterProvider filters = new SimpleFilterProvider()
                  .addFilter(filterName, theFilter);

          return MAPPER.writer(filters).writeValueAsString(data);
} catch (JsonProcessingException e) {
	e.printStackTrace();
}
  	return null;
  }
 
开发者ID:mmdsyl,项目名称:BLOG-Microservice,代码行数:14,代码来源:JsonUtils.java

示例14: testSerializeMultipleObjects

import com.fasterxml.jackson.databind.ser.FilterProvider; //导入依赖的package包/类
@Test
public void testSerializeMultipleObjects() throws IOException
{
    final Collection<Comment> allComments = new ArrayList<Comment>();
    Comment aComment = new Comment();
    aComment.setContent("<b>There it is</b>");
    allComments.add(aComment);
    aComment = new Comment();
    aComment.setContent("<p>I agree with the author</p>");
    allComments.add(aComment);

    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, allComments);
        }
    });
    assertTrue(out.toString().contains("content\":\"<b>There it is</b>"));
    assertTrue(out.toString().contains("content\":\"<p>I agree with the author</p>"));
}
 
开发者ID:Alfresco,项目名称:alfresco-remote-api,代码行数:28,代码来源:JsonJacksonTests.java

示例15: getErrorCode

import com.fasterxml.jackson.databind.ser.FilterProvider; //导入依赖的package包/类
@ExceptionHandler(CerebroException.class)
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
public String getErrorCode(final CerebroException exception) throws IOException {
    LOGGER.error("Service error", exception);
    ObjectMapper objectMapper = new ObjectMapper();
    FilterProvider filterProvider = new SimpleFilterProvider().addFilter("responseFilter",
        SimpleBeanPropertyFilter.filterOutAllExcept("errorCode", "errorMessage"));
    objectMapper.setFilterProvider(filterProvider);
    return objectMapper.writeValueAsString(exception);
}
 
开发者ID:voyages-sncf-technologies,项目名称:cerebro,代码行数:11,代码来源:CerebroController.java


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