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


Java Include類代碼示例

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


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

示例1: testContentMerge76

import com.fasterxml.jackson.annotation.JsonInclude.Include; //導入依賴的package包/類
public void testContentMerge76()
{
    JsonInclude.Value v1 = JsonInclude.Value.empty()
            .withContentInclusion(JsonInclude.Include.ALWAYS)
            .withValueInclusion(JsonInclude.Include.NON_ABSENT);
    JsonInclude.Value v2 = JsonInclude.Value.empty()
            .withContentInclusion(JsonInclude.Include.NON_EMPTY)
            .withValueInclusion(JsonInclude.Include.USE_DEFAULTS);

    JsonInclude.Value v12 = v2.withOverrides(v1); // v1 priority
    JsonInclude.Value v21 = v1.withOverrides(v2); // v2 priority

    assertEquals(JsonInclude.Include.ALWAYS, v12.getContentInclusion());
    assertEquals(JsonInclude.Include.NON_ABSENT, v12.getValueInclusion());

    assertEquals(JsonInclude.Include.NON_EMPTY, v21.getContentInclusion());
    assertEquals(JsonInclude.Include.NON_ABSENT, v21.getValueInclusion());
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:19,代碼來源:IncludeTest.java

示例2: testFilters

import com.fasterxml.jackson.annotation.JsonInclude.Include; //導入依賴的package包/類
public void testFilters()
{
    JsonInclude.Value empty = JsonInclude.Value.empty();
    assertNull(empty.getValueFilter());
    assertNull(empty.getContentFilter());

    // note: filter class choices are arbitrary, just confirming assingments
    JsonInclude.Value v1 = empty.withValueFilter(String.class);
    assertEquals(JsonInclude.Include.CUSTOM, v1.getValueInclusion());
    assertEquals(String.class, v1.getValueFilter());
    assertNull(v1.withValueFilter(null).getValueFilter());
    assertNull(v1.withValueFilter(Void.class).getValueFilter());

    JsonInclude.Value v2 = empty.withContentFilter(Long.class);
    assertEquals(JsonInclude.Include.CUSTOM, v2.getContentInclusion());
    assertEquals(Long.class, v2.getContentFilter());
    assertNull(v2.withContentFilter(null).getContentFilter());
    assertNull(v2.withContentFilter(Void.class).getContentFilter());
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:20,代碼來源:IncludeTest.java

示例3: IiifObjectMapper

import com.fasterxml.jackson.annotation.JsonInclude.Include; //導入依賴的package包/類
public IiifObjectMapper() {
  this.checkJacksonVersion();

  // Don't include null properties
  this.setSerializationInclusion(Include.NON_NULL);

  // Both are needed to add `@context` to the top-level object
  this.disable(SerializationFeature.FAIL_ON_UNWRAPPED_TYPE_IDENTIFIERS);
  this.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);

  // Some array fields are unwrapped during serialization if they have only one value
  this.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);

  // Register the problem handler
  this.addHandler(new ProblemHandler());

  // Disable writing dates as timestamps
  this.registerModule(new JavaTimeModule());
  this.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);

  // Enable automatic detection of parameter names in @JsonCreators
  this.registerModule(new ParameterNamesModule());

  // Register the module
  this.registerModule(new IiifModule());
}
 
開發者ID:dbmdz,項目名稱:iiif-apis,代碼行數:27,代碼來源:IiifObjectMapper.java

示例4: createMapper

import com.fasterxml.jackson.annotation.JsonInclude.Include; //導入依賴的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

示例5: initJson

import com.fasterxml.jackson.annotation.JsonInclude.Include; //導入依賴的package包/類
private void initJson() {
	this.objectMapper = new ObjectMapper();
	objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
	objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);

	objectMapper.setSerializationInclusion(Include.NON_NULL);
	// objectMapper.setSerializationInclusion(Include.NON_DEFAULT);

	// ServiceRequestJacksonDeserializer deserializer = new
	// ServiceRequestJacksonDeserializer(ServiceRequest.class,
	// objectMapper);
	this.argDeser = new ArgsDeserializer(this.objectMapper);
	// SimpleModule simpleModule = new SimpleModule();
	//
	// simpleModule.addDeserializer(Object[].class, this.argDeser);
	// objectMapper.registerModule(simpleModule);

	for (String key : serviceBeans.keySet()) {
		NettoServiceBean bean = serviceBeans.get(key);
		Class<?> clazz = bean.getObject().getClass();
		this.argDeser.registerMethodParameterTypes(key, clazz);
	}

}
 
開發者ID:sylinklee,項目名稱:netto_rpc,代碼行數:25,代碼來源:AbstractServiceChannelHandler.java

示例6: createDefaultMapper

import com.fasterxml.jackson.annotation.JsonInclude.Include; //導入依賴的package包/類
public static ObjectMapper createDefaultMapper() {

		final ObjectMapper mapper = new ObjectMapper();
		mapper.setSerializationInclusion(Include.NON_NULL);
		mapper.configure(SerializationFeature.INDENT_OUTPUT, false);
		mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
		mapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);

		SimpleModule module = new SimpleModule();
		module.addSerializer(Transaction.class, new TransactionSerializer());
		module.addDeserializer(Transaction.class, new TransactionDeserializer());
		module.addSerializer(Difficulty.class, new DifficultySerializer());
		module.addDeserializer(Difficulty.class, new DifficultyDeserializer());
		module.addSerializer(Block.class, new BlockSerializer());
		module.addDeserializer(Block.class, new BlockDeserializer());
		mapper.registerModule(module);

		return mapper;

	}
 
開發者ID:EonTechnology,項目名稱:server,代碼行數:21,代碼來源:ObjectMapperProvider.java

示例7: extendMapper

import com.fasterxml.jackson.annotation.JsonInclude.Include; //導入依賴的package包/類
@Override
public void extendMapper(ObjectMapper mapper)
{
	SimpleModule restModule = new SimpleModule("RestModule", new Version(1, 0, 0, null));
	// TODO this probably should be somewhere else, but it can't be in
	// com.tle.core.jackson
	// as that would make it dependent on equella i18n
	restModule.addSerializer(new I18NSerializer());
	mapper.registerModule(restModule);
	mapper.registerModule(new JavaTypesModule());

	mapper.registerModule(new RestStringsModule());
	mapper.setSerializationInclusion(Include.NON_NULL);

	// dev mode!
	if( DebugSettings.isDebuggingMode() )
	{
		mapper.configure(SerializationFeature.INDENT_OUTPUT, true);
	}
	mapper.setDateFormat(new ISO8061DateFormatWithTZ());

}
 
開發者ID:equella,項目名稱:Equella,代碼行數:23,代碼來源:RestEasyServlet.java

示例8: RedisDelayQueue

import com.fasterxml.jackson.annotation.JsonInclude.Include; //導入依賴的package包/類
public RedisDelayQueue(String redisKeyPrefix, String queueName, JedisCluster jedisCluster, int unackTime,
		DelayQueueProcessListener delayQueueProcessListener) {
	om = new ObjectMapper();
	om.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
	om.configure(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES, false);
	om.configure(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, false);
	om.setSerializationInclusion(Include.NON_NULL);
	om.setSerializationInclusion(Include.NON_EMPTY);
	om.disable(SerializationFeature.INDENT_OUTPUT);
	this.redisKeyPrefix = redisKeyPrefix;
	this.messageStoreKey = redisKeyPrefix + ".MESSAGE." + queueName;
	this.unackTime = unackTime;
	this.jedisCluster = jedisCluster;
	realQueueName = redisKeyPrefix + ".QUEUE." + queueName;
	this.delayQueueProcessListener = delayQueueProcessListener;
}
 
開發者ID:MeiPian,項目名稱:delay-queue,代碼行數:17,代碼來源:RedisDelayQueue.java

示例9: provideObjectMapper

import com.fasterxml.jackson.annotation.JsonInclude.Include; //導入依賴的package包/類
public ObjectMapper provideObjectMapper() {
  ObjectMapper objectMapper = new ObjectMapper();
  objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
  objectMapper.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false);
  objectMapper.setSerializationInclusion(Include.NON_NULL);
  objectMapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
  objectMapper.configure(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL, true);
  objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);

  objectMapper.setDateFormat(provideDateFormat());

  return objectMapper;
}
 
開發者ID:Aptoide,項目名稱:AppCoins-ethereumj,代碼行數:14,代碼來源:RetrofitModule.java

示例10: serialize

import com.fasterxml.jackson.annotation.JsonInclude.Include; //導入依賴的package包/類
@Override
public String serialize(Object entity) throws HttpException {
    String json = null;
    
    try {
        
        ObjectMapper mapper = new ObjectMapper();            
        mapper.setSerializationInclusion(Include.NON_NULL);
        mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
        
        json = mapper.writeValueAsString(entity);   
        
    } catch (JsonProcessingException e) {           
        throw new InternalServerErrorException(e.getMessage(), e);      
    }
    
    return json;
}
 
開發者ID:tdsis,項目名稱:lambda-forest,代碼行數:19,代碼來源:JsonResponseBodySerializerStrategy.java

示例11: testSingularityTaskIdSerialization

import com.fasterxml.jackson.annotation.JsonInclude.Include; //導入依賴的package包/類
@Test
public void testSingularityTaskIdSerialization() throws Exception {
  ObjectMapper om = Jackson.newObjectMapper()
      .setSerializationInclusion(Include.NON_NULL)
      .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
      .registerModule(new ProtobufModule());

  SingularityTaskId taskId = new SingularityTaskId("rid", "did", 100, 1, "host", "rack");
  String id = taskId.getId();
  SingularityTaskId fromId = SingularityTaskId.valueOf(id);
  SingularityTaskId fromJson = om.readValue(om.writeValueAsBytes(taskId), SingularityTaskId.class);

  assertEquals(taskId, fromId);
  assertEquals(taskId, fromJson);
  assertEquals(fromId, fromJson);
}
 
開發者ID:PacktPublishing,項目名稱:Mastering-Mesos,代碼行數:17,代碼來源:JavaUtilsTest.java

示例12: testErrors

import com.fasterxml.jackson.annotation.JsonInclude.Include; //導入依賴的package包/類
@SuppressWarnings("serial")
@Test
public void testErrors() throws Exception {
  assertTrue(genericErrorContainer.getErrors().isEmpty());
  assertTrue(!genericErrorContainer.hasErrors());

  genericErrorContainer.addError(new ApiError("test1"));
  assertEquals(1, genericErrorContainer.getErrors().size());
  assertEquals("test1", genericErrorContainer.getErrors().get(0).getMessage());

  List<ApiError> errors = new ArrayList<ApiError>() {{add(new ApiError("test2"));}};
  genericErrorContainer.addErrors(errors);
  assertEquals(2, genericErrorContainer.getErrors().size());
  assertEquals("test1", genericErrorContainer.getErrors().get(0).getMessage());
  assertEquals("test2", genericErrorContainer.getErrors().get(1).getMessage());

  genericErrorContainer.setErrors(errors);
  assertEquals(1, genericErrorContainer.getErrors().size());
  assertEquals("test2", genericErrorContainer.getErrors().get(0).getMessage());

  assertTrue(genericErrorContainer.hasErrors());

  Field field = GenericErrorContainer.class.getDeclaredField("errors");
  assertNotNull(field.getAnnotation(JsonInclude.class));
  assertEquals(Include.ALWAYS, field.getAnnotation(JsonInclude.class).value());
}
 
開發者ID:tripsta,項目名稱:spring-boot-starter-kit,代碼行數:27,代碼來源:GenericErrorContainerTest.java

示例13: booleanSetters

import com.fasterxml.jackson.annotation.JsonInclude.Include; //導入依賴的package包/類
@Test
public void booleanSetters() {
	this.factory.setAutoDetectFields(false);
	this.factory.setAutoDetectGettersSetters(false);
	this.factory.setDefaultViewInclusion(false);
	this.factory.setFailOnEmptyBeans(false);
	this.factory.setIndentOutput(true);
	this.factory.afterPropertiesSet();

	ObjectMapper objectMapper = this.factory.getObject();

	assertFalse(objectMapper.getSerializationConfig().isEnabled(MapperFeature.AUTO_DETECT_FIELDS));
	assertFalse(objectMapper.getDeserializationConfig().isEnabled(MapperFeature.AUTO_DETECT_FIELDS));
	assertFalse(objectMapper.getSerializationConfig().isEnabled(MapperFeature.AUTO_DETECT_GETTERS));
	assertFalse(objectMapper.getDeserializationConfig().isEnabled(MapperFeature.AUTO_DETECT_SETTERS));
	assertFalse(objectMapper.getDeserializationConfig().isEnabled(MapperFeature.DEFAULT_VIEW_INCLUSION));
	assertFalse(objectMapper.getSerializationConfig().isEnabled(SerializationFeature.FAIL_ON_EMPTY_BEANS));
	assertTrue(objectMapper.getSerializationConfig().isEnabled(SerializationFeature.INDENT_OUTPUT));
	assertSame(Include.ALWAYS, objectMapper.getSerializationConfig().getSerializationInclusion());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:21,代碼來源:Jackson2ObjectMapperFactoryBeanTests.java

示例14: provideObjectMapper

import com.fasterxml.jackson.annotation.JsonInclude.Include; //導入依賴的package包/類
@Provides
@Singleton
ObjectMapper provideObjectMapper() {
	SimpleModule module = new SimpleModule();
       module.setSerializerModifier(new MentorSerializerModifier());
	return new ObjectMapper()
		.configure(SerializationFeature.WRAP_ROOT_VALUE, false)
		.configure(SerializationFeature.INDENT_OUTPUT, false)
		.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false)
		.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
		.configure(MapperFeature.USE_WRAPPER_NAME_AS_PROPERTY_NAME, true)
		.disable(MapperFeature.AUTO_DETECT_CREATORS)
		.disable(MapperFeature.AUTO_DETECT_FIELDS)
		.disable(MapperFeature.AUTO_DETECT_GETTERS)
		.disable(MapperFeature.AUTO_DETECT_IS_GETTERS)
		.setSerializationInclusion(Include.NON_NULL)
		.setDateFormat(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX"))
		.registerModule(module)
		;
}
 
開發者ID:vsite-hr,項目名稱:mentor,代碼行數:21,代碼來源:MentorModule.java

示例15: getJson

import com.fasterxml.jackson.annotation.JsonInclude.Include; //導入依賴的package包/類
/**
 * Serialize a Java object to a Json String
 *
 * @param doc the java Object to serialize to a Json String
 * @param prettyPrint
 * @return the Json String
 * @throws java.io.IOException
 */
public static String getJson ( final Object doc, final boolean prettyPrint ) throws IOException {

  final ObjectMapper mapper = new ObjectMapper();

  mapper.setSerializationInclusion(Include.NON_NULL);
  mapper.setSerializationInclusion(Include.NON_EMPTY);

  String json;
  if (prettyPrint) {
    final ObjectWriter writer = mapper.writerWithDefaultPrettyPrinter();
    json = writer.writeValueAsString(doc);
  } else {
    json = mapper.writeValueAsString(doc);
  }

  return json;
}
 
開發者ID:Orange-OpenSource,項目名稱:documentare-simdoc,代碼行數:26,代碼來源:JsonHelper.java


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