当前位置: 首页>>代码示例>>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;未经允许,请勿转载。