當前位置: 首頁>>代碼示例>>Java>>正文


Java SimpleBeanPropertyFilter類代碼示例

本文整理匯總了Java中com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter的典型用法代碼示例。如果您正苦於以下問題:Java SimpleBeanPropertyFilter類的具體用法?Java SimpleBeanPropertyFilter怎麽用?Java SimpleBeanPropertyFilter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


SimpleBeanPropertyFilter類屬於com.fasterxml.jackson.databind.ser.impl包,在下文中一共展示了SimpleBeanPropertyFilter類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: renderSimpleBeanWithFilters

import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter; //導入依賴的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

示例2: findAllTest2

import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter; //導入依賴的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.impl.SimpleBeanPropertyFilter; //導入依賴的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: test

import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter; //導入依賴的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());
}
 
開發者ID:shihyuho,項目名稱:jackson-dynamic-filter,代碼行數:26,代碼來源:DynamicFilterProviderTest.java

示例5: testReadRdf

import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter; //導入依賴的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));
}
 
開發者ID:phenopackets,項目名稱:phenopacket-reference-implementation,代碼行數:17,代碼來源:RdfTest.java

示例6: ensureThatSerializingASymbolWithoutProjectDoesNotCrash

import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter; //導入依賴的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

示例7: JsonManager

import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter; //導入依賴的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);
}
 
開發者ID:conveyal,項目名稱:gtfs-lib,代碼行數:22,代碼來源:JsonManager.java

示例8: createTest

import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter; //導入依賴的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);

}
 
開發者ID:oncoblocks,項目名稱:centromere,代碼行數:24,代碼來源:CrudControllerIntegrationTests.java

示例9: getObjectWriter

import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter; //導入依賴的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

示例10: filterProvider

import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter; //導入依賴的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));
}
 
開發者ID:hpe-idol,項目名稱:find,代碼行數:19,代碼來源:ConfigFileConfiguration.java

示例11: configureJSONExporter

import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter; //導入依賴的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

示例12: getPathsForProfile

import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter; //導入依賴的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

示例13: testPath

import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter; //導入依賴的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

示例14: newWriter

import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter; //導入依賴的package包/類
ObjectWriter newWriter(final boolean locationInfo, final boolean properties, final boolean compact) {
    final SimpleFilterProvider filters = new SimpleFilterProvider();
    final Set<String> except = new HashSet<>(2);
    if (!locationInfo) {
        except.add(this.getPropertNameForSource());
    }
    if (!properties) {
        except.add(this.getPropertNameForContextMap());
    }
    except.add(this.getPropertNameForNanoTime());
    filters.addFilter(Log4jLogEvent.class.getName(), SimpleBeanPropertyFilter.serializeAllExcept(except));
    final ObjectWriter writer = this.newObjectMapper().writer(compact ? this.newCompactPrinter() : this.newPrettyPrinter());
    return writer.with(filters);
}
 
開發者ID:apache,項目名稱:logging-log4j2,代碼行數:15,代碼來源:JacksonFactory.java

示例15: objectToJsonExclude

import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter; //導入依賴的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


注:本文中的com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。