Java 类com.fasterxml.jackson.annotation.JsonInclude.Include 实例源码

项目:GitHub    文件:IncludeTest.java   
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());
}
项目:GitHub    文件:IncludeTest.java   
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());
}
项目:iiif-apis    文件:IiifObjectMapper.java   
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());
}
项目:JRediClients    文件:ConfigSupport.java   
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;
}
项目:netto_rpc    文件:AbstractServiceChannelHandler.java   
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);
    }

}
项目:server    文件:ObjectMapperProvider.java   
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;

    }
项目:Equella    文件:RestEasyServlet.java   
@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());

}
项目:delay-queue    文件:RedisDelayQueue.java   
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;
}
项目:AppCoins-ethereumj    文件:RetrofitModule.java   
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;
}
项目:lambda-forest    文件:JsonResponseBodySerializerStrategy.java   
@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;
}
项目:Mastering-Mesos    文件:JavaUtilsTest.java   
@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);
}
项目:spring-boot-starter-kit    文件:GenericErrorContainerTest.java   
@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());
}
项目:spring4-understanding    文件:Jackson2ObjectMapperFactoryBeanTests.java   
@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());
}
项目:mentor    文件:MentorModule.java   
@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)
        ;
}
项目:documentare-simdoc    文件:JsonHelper.java   
/**
 * 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;
}
项目:codehelper.generator    文件:MapperBuilder.java   
private static void configure(ObjectMapper om, Object feature, boolean state) {
    if (feature instanceof SerializationFeature)
        om.configure((SerializationFeature) feature, state);
    else if (feature instanceof DeserializationFeature)
        om.configure((DeserializationFeature) feature, state);
    else if (feature instanceof JsonParser.Feature)
        om.configure((JsonParser.Feature) feature, state);
    else if (feature instanceof JsonGenerator.Feature)
        om.configure((JsonGenerator.Feature) feature, state);
    else if (feature instanceof MapperFeature)
        om.configure((MapperFeature) feature, state);
    else if (feature instanceof Include) {
        if (state) {
            om.setSerializationInclusion((Include) feature);
        }
    }
}
项目:Sqawsh    文件:BackupManager.java   
@Override
public final void initialise(IBookingManager bookingManager, IRuleManager ruleManager,
    LambdaLogger logger) throws Exception {
  this.ruleManager = ruleManager;
  this.bookingManager = bookingManager;
  this.logger = logger;
  databaseBackupBucketName = getEnvironmentVariable("DatabaseBackupBucket");
  adminSnsTopicArn = getEnvironmentVariable("AdminSNSTopicArn");
  region = Region.getRegion(Regions.fromName(getEnvironmentVariable("AWS_REGION")));

  // Prepare to serialise bookings and booking rules as JSON.
  mapper = new ObjectMapper();
  mapper.setSerializationInclusion(Include.NON_EMPTY);
  mapper.setSerializationInclusion(Include.NON_NULL);

  initialised = true;
}
项目:Sparkplug    文件:SparkplugExample.java   
public void messageArrived(String topic, MqttMessage message) throws Exception {
    Topic sparkplugTopic = TopicUtil.parseTopic(topic);
    ObjectMapper mapper = new ObjectMapper();
    mapper.setSerializationInclusion(Include.NON_NULL);

    SparkplugBPayloadDecoder decoder = new SparkplugBPayloadDecoder();
    SparkplugBPayload inboundPayload = decoder.buildFromByteArray(message.getPayload());

    if (sparkplugTopic.isType(MessageType.NBIRTH)) {
        try {
            System.out.println("\n\nRecieved Node Birth");
            System.out.println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(inboundPayload));
            System.out.print("\n\n> ");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
项目:Sparkplug    文件:SparkplugListener.java   
@Override
public void messageArrived(String topic, MqttMessage message) throws Exception {
    Topic sparkplugTopic = TopicUtil.parseTopic(topic);
    ObjectMapper mapper = new ObjectMapper();
    mapper.setSerializationInclusion(Include.NON_NULL);

    System.out.println("Message Arrived on Sparkplug topic " + sparkplugTopic.toString());

    SparkplugBPayloadDecoder decoder = new SparkplugBPayloadDecoder();
    SparkplugBPayload inboundPayload = decoder.buildFromByteArray(message.getPayload());

    // Convert the message to JSON and print to system.out
    try {
        String payloadString = mapper.writeValueAsString(inboundPayload);
        System.out.println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(inboundPayload));
    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:JglTF    文件:GltfUtilsV2.java   
/**
 * Creates a deep copy of the given {@link GlTF}.<br>
 * <br>
 * Note: Some details about the copy are not specified. E.g. whether
 * values that are mapped to <code>null</code> are still contained
 * in the copy. The goal of this method is to create a copy that is,
 * as far as reasonably possible, "structurally equivalent" to the
 * given input.
 * 
 * @param gltf The input 
 * @return The copy
 * @throws GltfException If the copy can not be created
 */
static GlTF copy(GlTF gltf)
{
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.setSerializationInclusion(Include.NON_NULL);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try
    {
        objectMapper.writeValue(baos, gltf);
        return objectMapper.readValue(baos.toByteArray(), GlTF.class);
    } 
    catch (IOException e)
    {
        throw new GltfException("Could not copy glTF", e);
    }
}
项目:tacs_2016_1C_grupo4    文件:MongoDBAbstractDao.java   
@SuppressWarnings("unchecked")
@Override
public boolean save(T obj) {
    boolean saved = false;
    ObjectMapper mapper = new ObjectMapper();
    mapper.setSerializationInclusion(Include.NON_NULL);
    if (obj.getId() != null)
        return saved;
    obj.setId(this.nextId);
    try {
        collection.insertOne(Document.parse(mapper.writeValueAsString(obj)));
        saved = true;
    } catch (JsonProcessingException e) {
        e.printStackTrace();
    }
    if (saved) {
        this.nextId++;
    }
    return saved;
}
项目:tacs_2016_1C_grupo4    文件:MongoDBAbstractDao.java   
@Override
public boolean update(T obj) {
    ObjectMapper mapper = new ObjectMapper();
    mapper.setSerializationInclusion(Include.NON_NULL);

    BasicDBObject query = new BasicDBObject();
    query.put("_id", obj.getId());

    try {
        collection.updateOne(query, new Document("$set", Document.parse(mapper.writeValueAsString(obj))));
    } catch (JsonProcessingException e) {

        e.printStackTrace();
    }
    return true;
}
项目:JglTF    文件:GltfUtilsV1.java   
/**
 * Creates a deep copy of the given {@link GlTF}.<br>
 * <br>
 * Note: Some details about the copy are not specified. E.g. whether
 * values that are mapped to <code>null</code> are still contained
 * in the copy. The goal of this method is to create a copy that is,
 * as far as reasonably possible, "structurally equivalent" to the
 * given input.
 * 
 * @param gltf The input 
 * @return The copy
 * @throws GltfException If the copy can not be created
 */
static GlTF copy(GlTF gltf)
{
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.setSerializationInclusion(Include.NON_NULL);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try
    {
        objectMapper.writeValue(baos, gltf);
        return objectMapper.readValue(baos.toByteArray(), GlTF.class);
    } 
    catch (IOException e)
    {
        throw new GltfException("Could not copy glTF", e);
    }
}
项目:GitHub    文件:IncludeTest.java   
public void testEquality() {
    assertTrue(EMPTY.equals(EMPTY));

    JsonInclude.Value v1 = JsonInclude.Value.construct(Include.NON_ABSENT, null);
    JsonInclude.Value v2 = JsonInclude.Value.construct(Include.NON_ABSENT, null);
    JsonInclude.Value v3 = JsonInclude.Value.construct(Include.NON_ABSENT, Include.NON_EMPTY);

    assertTrue(v1.equals(v2));
    assertTrue(v2.equals(v1));

    assertFalse(v1.equals(v3));
    assertFalse(v3.equals(v1));
    assertFalse(v2.equals(v3));
    assertFalse(v3.equals(v2));
}
项目:GitHub    文件:IncludeTest.java   
public void testFromAnnotation()
{
    JsonInclude ann = Bogus.class.getAnnotation(JsonInclude.class);
    JsonInclude.Value v = JsonInclude.Value.from(ann);
    assertEquals(Include.NON_EMPTY, v.getValueInclusion());
    assertEquals(Include.NON_DEFAULT, v.getContentInclusion());
}
项目:GitHub    文件:IncludeTest.java   
public void testFromAnnotationWithCustom()
    {
        JsonInclude ann = Custom.class.getAnnotation(JsonInclude.class);
        JsonInclude.Value v = JsonInclude.Value.from(ann);
        assertEquals(Include.CUSTOM, v.getValueInclusion());
        assertEquals(Include.CUSTOM, v.getContentInclusion());
        assertEquals(Integer.class, v.getValueFilter());
        assertEquals(Long.class, v.getContentFilter());

        assertEquals(
"JsonInclude.Value(value=CUSTOM,content=CUSTOM,valueFilter=java.lang.Integer.class,contentFilter=java.lang.Long.class)",
                v.toString());
    }
项目:GitHub    文件:IncludeTest.java   
public void testStdOverrides() {
    assertEquals("JsonInclude.Value(value=NON_ABSENT,content=USE_DEFAULTS)",
            JsonInclude.Value.construct(Include.NON_ABSENT, null).toString());
    int x = EMPTY.hashCode();
    if (x == 0) {
        fail();
    }
    assertFalse(EMPTY.equals(null));
    assertFalse(EMPTY.equals(""));
}
项目:GitHub    文件:IncludeTest.java   
public void testSimpleMerge()
{
    JsonInclude.Value empty = JsonInclude.Value.empty();

    assertEquals(Include.USE_DEFAULTS, empty.getValueInclusion());
    assertEquals(Include.USE_DEFAULTS, empty.getContentInclusion());

    JsonInclude.Value v2 = empty.withValueInclusion(Include.NON_ABSENT);

    assertEquals(Include.NON_ABSENT, v2.getValueInclusion());
    assertEquals(Include.USE_DEFAULTS, v2.getContentInclusion());

    JsonInclude.Value v3 = new JsonInclude.Value(Include.NON_EMPTY, Include.ALWAYS,
            null, null);
    assertEquals(Include.NON_EMPTY, v3.getValueInclusion());
    assertEquals(Include.ALWAYS, v3.getContentInclusion());

    // Ok; but then overrides, which should skip 'USE_DEFAULT' overrides
    JsonInclude.Value merged = v3.withOverrides(empty);
    // no overrides with "empty":
    assertEquals(v3.getValueInclusion(), merged.getValueInclusion());
    assertEquals(v3.getContentInclusion(), merged.getContentInclusion());

    // but other values ought to be overridden (value, yes, content, no because it's default)
    merged = JsonInclude.Value.merge(v3, v2);
    assertEquals(v2.getValueInclusion(), merged.getValueInclusion());
    assertEquals(v3.getContentInclusion(), merged.getContentInclusion());

    merged = JsonInclude.Value.mergeAll(empty, v3);
    assertEquals(v3.getValueInclusion(), merged.getValueInclusion());
    assertEquals(v3.getContentInclusion(), merged.getContentInclusion());
}
项目:framework    文件:JsonMapper.java   
/**
 * 创建只输出初始值被改变的属性到Json字符串的Mapper, 最节约的存储方式,建议在内部接口中使用。
 */
public static JsonMapper nonDefaultMapper() {
    if (mapper == null) {
        mapper = new JsonMapper(Include.NON_DEFAULT);
    }
    return mapper;
}
项目:spring-rest-commons-options    文件:WebMvcConfiguration.java   
YamlJackson2HttpMessageConverter() {
    super(new YAMLMapper().enable(Feature.MINIMIZE_QUOTES), MediaType.parseMediaType("application/x-yaml"));
    this.getObjectMapper().configure(JsonGenerator.Feature.QUOTE_FIELD_NAMES, false);
    this.getObjectMapper().configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
    this.getObjectMapper().enable(SerializationFeature.INDENT_OUTPUT);
    this.getObjectMapper().setSerializationInclusion(Include.NON_NULL);
}
项目:JRediClients    文件:JsonJacksonCodec.java   
protected void init(ObjectMapper objectMapper) {
    objectMapper.registerModule(new DefenceModule());

    objectMapper.setSerializationInclusion(Include.NON_NULL);
    objectMapper.setVisibilityChecker(objectMapper.getSerializationConfig().getDefaultVisibilityChecker()
            .withFieldVisibility(JsonAutoDetect.Visibility.ANY).withGetterVisibility(JsonAutoDetect.Visibility.NONE)
            .withSetterVisibility(JsonAutoDetect.Visibility.NONE)
            .withCreatorVisibility(JsonAutoDetect.Visibility.NONE));
    objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    objectMapper.configure(SerializationFeature.WRITE_BIGDECIMAL_AS_PLAIN, true);
    objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
    objectMapper.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true);
    objectMapper.addMixIn(Throwable.class, ThrowableMixIn.class);
}
项目:circus-train    文件:SnsListener.java   
SnsListener(AmazonSNSAsyncClient sns, ListenerConfig config, Clock clock) {
  this.clock = clock;
  LOG.info("Starting listener, topics: start={}, success={}, fail={}", config.getStartTopic(),
      config.getSuccessTopic(), config.getFailTopic());
  this.sns = sns;
  this.config = config;
  ObjectMapper mapper = new ObjectMapper();
  mapper.setSerializationInclusion(Include.NON_NULL);
  startWriter = mapper.writer();
}
项目:unitstack    文件:MessageUtils.java   
public MessageUtils() {
  xmlMapper = new ExtendedXmlMapper();
  xmlMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
  xmlMapper.setDateFormat(new ISO8601DateFormat());
  xmlMapper.registerModule(new JaxbAnnotationModule());
  xmlMapper.setSerializationInclusion(Include.NON_NULL);
}
项目:FactorioScript    文件:App.java   
public static String getStringFromBlueprintRoot(BlueprintRoot blueprintRoot) {
    ObjectMapper mapper = new ObjectMapper();
    mapper.setSerializationInclusion(Include.NON_NULL);
    String jsonInString = null;
    try {
        jsonInString = mapper.writeValueAsString(blueprintRoot);
    } catch (JsonProcessingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return jsonInString;
}
项目:azeroth    文件:JsonMapper.java   
public JsonMapper(Include include) {
    mapper = new ObjectMapper();
    //设置输出时包含属性的风格
    if (include != null) {
        mapper.setSerializationInclusion(include);
    }
    //设置输入时忽略在JSON字符串中存在但Java对象实际没有的属性
    mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
    //
    mapper.configure(Feature.ALLOW_UNQUOTED_FIELD_NAMES, false);
}
项目:conversationinsights-service    文件:TrainingDataProcessor.java   
public static String toString(TrainingDataModel model)
    throws JsonGenerationException, JsonMappingException, IOException {
  ObjectMapper objectMapper = new ObjectMapper();
  objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
  objectMapper.setSerializationInclusion(Include.NON_NULL);
  StringWriter sw = new StringWriter();
  objectMapper.writeValue(sw, model);
  return sw.toString();
}
项目:stroom-query    文件:TestVisComponentResultCreator.java   
private ObjectMapper createMapper(final boolean indent) {
    final SimpleModule module = new SimpleModule();
    module.addSerializer(Double.class, new MyDoubleSerialiser());

    final ObjectMapper mapper = new ObjectMapper();
    mapper.registerModule(module);
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    mapper.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false);
    mapper.configure(SerializationFeature.INDENT_OUTPUT, indent);
    mapper.setSerializationInclusion(Include.NON_NULL);

    return mapper;
}
项目:jackson-dataformat-velocypack    文件:VPackSerializeDeserializeTest.java   
@Test
public void dontSerializeNullValues() throws IOException {
    final TestEntityString entity = new TestEntityString();
    entity.setS(null);
    final ObjectMapper mapper = new VPackMapper();
    mapper.setSerializationInclusion(Include.NON_NULL);
    final VPackSlice vpack = new VPackSlice(mapper.writeValueAsBytes(entity));
    assertThat(vpack, is(notNullValue()));
    assertThat(vpack.isObject(), is(true));
    final VPackSlice s = vpack.get("s");
    assertThat(s.isNone(), is(true));
}
项目:jackson-dataformat-velocypack    文件:VPackSerializeDeserializeTest.java   
@Test
public void serializeNullValue() throws IOException {
    final TestEntityString entity = new TestEntityString();
    entity.setS(null);
    final ObjectMapper mapper = new VPackMapper();
    mapper.setSerializationInclusion(Include.ALWAYS);
    final VPackSlice vpack = new VPackSlice(mapper.writeValueAsBytes(entity));
    assertThat(vpack, is(notNullValue()));
    final VPackSlice s = vpack.get("s");
    assertThat(s.isNull(), is(true));
}
项目:athena    文件:ObjectMapperUtil.java   
/**
 * get ObjectMapper entity.
 * @return ObjectMapper entity
 */
public static ObjectMapper getObjectMapper() {
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper
            .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,
                       false);
    objectMapper.setSerializationInclusion(Include.NON_NULL);
    return objectMapper;
}