Java 类com.fasterxml.jackson.annotation.JsonAutoDetect 实例源码

项目:springboot_cwenao    文件:RedisConfig.java   
@Bean(name="redisTemplate")
public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory factory) {

    RedisTemplate<String, String> template = new RedisTemplate<>();


    RedisSerializer<String> redisSerializer = new StringRedisSerializer();

    Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
    ObjectMapper om = new ObjectMapper();
    om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
    om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
    jackson2JsonRedisSerializer.setObjectMapper(om);

    template.setConnectionFactory(factory);
    //key序列化方式
    template.setKeySerializer(redisSerializer);
    //value序列化
    template.setValueSerializer(jackson2JsonRedisSerializer);
    //value hashmap序列化
    template.setHashValueSerializer(jackson2JsonRedisSerializer);

    return template;
}
项目:GitHub    文件:JacksonConverterFactoryTest.java   
@Before public void setUp() {
  SimpleModule module = new SimpleModule();
  module.addSerializer(AnInterface.class, new AnInterfaceSerializer());
  module.addDeserializer(AnInterface.class, new AnInterfaceDeserializer());
  ObjectMapper mapper = new ObjectMapper();
  mapper.registerModule(module);
  mapper.configure(MapperFeature.AUTO_DETECT_GETTERS, false);
  mapper.configure(MapperFeature.AUTO_DETECT_SETTERS, false);
  mapper.configure(MapperFeature.AUTO_DETECT_IS_GETTERS, false);
  mapper.setVisibilityChecker(mapper.getSerializationConfig()
      .getDefaultVisibilityChecker()
      .withFieldVisibility(JsonAutoDetect.Visibility.ANY));

  Retrofit retrofit = new Retrofit.Builder()
      .baseUrl(server.url("/"))
      .addConverterFactory(JacksonConverterFactory.create(mapper))
      .build();
  service = retrofit.create(Service.class);
}
项目:springboot-shiro-cas-mybatis    文件:InternalConfigStateController.java   
@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;
}
项目:springboot_cwenao    文件:RedisConfig.java   
@Bean(name="redisTemplate")
public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory factory) {

    RedisTemplate<String, String> template = new RedisTemplate<>();


    RedisSerializer<String> redisSerializer = new StringRedisSerializer();

    Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
    ObjectMapper om = new ObjectMapper();
    om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
    om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
    jackson2JsonRedisSerializer.setObjectMapper(om);

    template.setConnectionFactory(factory);
    //key序列化方式
    template.setKeySerializer(redisSerializer);
    //value序列化
    template.setValueSerializer(jackson2JsonRedisSerializer);
    //value hashmap序列化
    template.setHashValueSerializer(jackson2JsonRedisSerializer);

    return template;
}
项目:GitHub    文件:JacksonConverterFactoryTest.java   
@Before public void setUp() {
  SimpleModule module = new SimpleModule();
  module.addSerializer(AnInterface.class, new AnInterfaceSerializer());
  module.addDeserializer(AnInterface.class, new AnInterfaceDeserializer());
  ObjectMapper mapper = new ObjectMapper();
  mapper.registerModule(module);
  mapper.configure(MapperFeature.AUTO_DETECT_GETTERS, false);
  mapper.configure(MapperFeature.AUTO_DETECT_SETTERS, false);
  mapper.configure(MapperFeature.AUTO_DETECT_IS_GETTERS, false);
  mapper.setVisibilityChecker(mapper.getSerializationConfig()
      .getDefaultVisibilityChecker()
      .withFieldVisibility(JsonAutoDetect.Visibility.ANY));

  Retrofit retrofit = new Retrofit.Builder()
      .baseUrl(server.url("/"))
      .addConverterFactory(JacksonConverterFactory.create(mapper))
      .build();
  service = retrofit.create(Service.class);
}
项目:JSON-framework-comparison    文件:RuntimeSampler.java   
public static ObjectMapper objectMapper() {
    return new ObjectMapper()
            // Property visibility
            .setDefaultPropertyInclusion(JsonInclude.Include.ALWAYS)
            .setDefaultVisibility(JsonAutoDetect.Value.construct(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.PROTECTED_AND_PUBLIC))
            .configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true)
            .setSerializationInclusion(JsonInclude.Include.NON_NULL)
            .configure(SerializationFeature.WRITE_NULL_MAP_VALUES, true)

            // Property naming and order
            .setPropertyNamingStrategy(PropertyNamingStrategy.LOWER_CAMEL_CASE)

            // Customised de/serializers

            // Formats, locals, encoding, binary data
            .setDateFormat(new SimpleDateFormat("MM/dd/yyyy"))
            .setDefaultPrettyPrinter(new DefaultPrettyPrinter())
            .setLocale(Locale.CANADA);
}
项目:springboot_op    文件:RedisConfiguration.java   
/**
 * RedisTemplate配置
 * @param factory
 * @return
 */
@Bean
@SuppressWarnings({"rawtypes", "unchecked"})
public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory factory) {
    StringRedisTemplate template = new StringRedisTemplate(factory);
    //定义value的序列化方式
    Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
    ObjectMapper om = new ObjectMapper();
    om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
    om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
    jackson2JsonRedisSerializer.setObjectMapper(om);

    template.setValueSerializer(jackson2JsonRedisSerializer);
    template.setHashValueSerializer(jackson2JsonRedisSerializer);
    template.afterPropertiesSet();
    return template;
}
项目:springboot-smart    文件:RedisConfiguration.java   
@Bean("redisTemplate")  //新家的这个注解 10-26 12:06
@SuppressWarnings({ "rawtypes", "unchecked" })
public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory redisFactory){
    StringRedisTemplate template = new StringRedisTemplate(redisFactory);
    Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new 
            Jackson2JsonRedisSerializer(Object.class);

    ObjectMapper om = new ObjectMapper();
    om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
    om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
    jackson2JsonRedisSerializer.setObjectMapper(om);

    template.setValueSerializer(jackson2JsonRedisSerializer);
    template.afterPropertiesSet();
    return template;
}
项目:nitrite-database    文件:LuceneService.java   
public LuceneService() {
    try {
        this.keySerializer = new ObjectMapper();
        keySerializer.setVisibility(
                keySerializer.getSerializationConfig().
                        getDefaultVisibilityChecker().
                        withFieldVisibility(JsonAutoDetect.Visibility.ANY).
                        withGetterVisibility(JsonAutoDetect.Visibility.NONE).
                        withIsGetterVisibility(JsonAutoDetect.Visibility.NONE)
        );

        indexDirectory = new RAMDirectory();
        analyzer = new StandardAnalyzer(Version.LUCENE_4_9);

        IndexWriterConfig iwc = new IndexWriterConfig(Version.LUCENE_4_9, analyzer);
        iwc.setOpenMode(IndexWriterConfig.OpenMode.CREATE_OR_APPEND);
        indexWriter = new IndexWriter(indexDirectory, iwc);
        commit();
    } catch (IOException e) {
        throw new IndexingException(errorMessage(
                "could not create full-text index", 0), e);
    } catch (VirtualMachineError vme) {
        handleVirtualMachineError(vme);
    }
}
项目:hippo    文件:GenerateTaxonomyTask.java   
@Override
public void execute() {

    Path taxonomyDefinitionImportPath = executionParameters.getTaxonomyDefinitionImportPath();
    Path taxonomyDefinitionOutputPath = executionParameters.getTaxonomyDefinitionOutputPath();
    assertRequiredArgs(taxonomyDefinitionImportPath, taxonomyDefinitionOutputPath);

    taxonomyMigrator.init();
    TaxonomyTerm taxonomyDefinition = taxonomyMigrator.getTaxonomyDefinition();

    // Write out the JSON files
    try {
        ObjectMapper mapper = new ObjectMapper();
        mapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
        File dir = taxonomyDefinitionOutputPath.toFile();
        dir.mkdirs();
        // Prefix is so taxonomy gets imported first, before any documents
        mapper.writeValue(new File(dir, "000000_" + "publication_taxonomy.json"), taxonomyDefinition);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
项目:Easy-WeChat    文件:ApiFactory.java   
public ApiFactory(String baseUrl) {
    HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
    logging.setLevel(HttpLoggingInterceptor.Level.BODY);

    this.okHttpClient = new OkHttpClient.Builder().readTimeout(60, TimeUnit.SECONDS)
                                                  .connectTimeout(60, TimeUnit.SECONDS)
                                                  .cookieJar(new SimpleCookieJar())
                                                  .addInterceptor(logging)
                                                  .build();
    this.retrofit = new Retrofit.Builder().baseUrl(baseUrl)
                                          .addConverterFactory(JacksonConverterFactory.create(
                                                  new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
                                                                    .setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.NONE)
                                                                    .setVisibility(PropertyAccessor.FIELD,
                                                                            JsonAutoDetect.Visibility.ANY))) // 配置Json序列化的时候只使用field name,不走getter setter
                                          .client(okHttpClient)
                                          .build();
}
项目:illuminati    文件:StringObjectUtils.java   
public static String objectToString (final Object object) {
    if (object == null) {
        return null;
    }

    try {
        final StringWriter stringWriter = new StringWriter();

        final ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.configure(SerializationFeature.INDENT_OUTPUT, true);
        objectMapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
        objectMapper.writeValue(stringWriter, object);

        return stringWriter.toString().replaceAll(System.getProperty("line.separator"), "");
    } catch (IOException ex) {
        STRINGUTIL_LOGGER.info("Sorry. had a error on during Object to String. ("+ex.toString()+")");
        return null;
    }
}
项目:action    文件:RedisUtil.java   
@Bean
public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory connectionFactory) {
    RedisTemplate<Object, Object> template = new RedisTemplate<>();
    template.setConnectionFactory(connectionFactory);

    //使用Jackson2JsonRedisSerializer来序列化和反序列化redis的value值
    Jackson2JsonRedisSerializer serializer = new Jackson2JsonRedisSerializer(Object.class);

    ObjectMapper mapper = new ObjectMapper();
    mapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
    mapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
    serializer.setObjectMapper(mapper);

    template.setValueSerializer(serializer);
    //使用StringRedisSerializer来序列化和反序列化redis的key值
    template.setKeySerializer(new StringRedisSerializer());
    template.afterPropertiesSet();
    return template;
}
项目:OperatieBRP    文件:BrpJsonObjectMapper.java   
private void configureerMapper() {
    // Configuratie
    this.disable(MapperFeature.AUTO_DETECT_CREATORS);
    this.disable(MapperFeature.AUTO_DETECT_FIELDS);
    this.disable(MapperFeature.AUTO_DETECT_GETTERS);
    this.disable(MapperFeature.AUTO_DETECT_IS_GETTERS);
    this.disable(MapperFeature.AUTO_DETECT_SETTERS);

    // Default velden niet als JSON exposen (expliciet annoteren!)
    setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.NONE);
    this.enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY);
    this.enable(MapperFeature.CAN_OVERRIDE_ACCESS_MODIFIERS);

    // serialization
    this.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
    setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
    this.enable(SerializationFeature.WRITE_ENUMS_USING_INDEX);

    // deserialization
    this.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
}
项目:OperatieBRP    文件:JsonMapper.java   
private static ObjectMapper initializeMapper() {
    return new ObjectMapper()
            .registerModule(new JavaTimeModule())

            .disable(MapperFeature.AUTO_DETECT_GETTERS)
            .disable(MapperFeature.AUTO_DETECT_CREATORS)
            .disable(MapperFeature.AUTO_DETECT_SETTERS)
            .disable(MapperFeature.AUTO_DETECT_IS_GETTERS)
            .disable(MapperFeature.AUTO_DETECT_FIELDS)
            .disable(MapperFeature.DEFAULT_VIEW_INCLUSION)
            .setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.NONE)
            .enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY)
            .enable(MapperFeature.CAN_OVERRIDE_ACCESS_MODIFIERS)

            // serialization
            .disable(SerializationFeature.FAIL_ON_EMPTY_BEANS)
            .enable(SerializationFeature.USE_EQUALITY_FOR_OBJECT_ID)
            .setSerializationInclusion(JsonInclude.Include.NON_EMPTY)
            .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)

            // deserialization
            .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
            .enable(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE);
}
项目:data-migration    文件:RedisConfiguration.java   
@Bean
public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory connectionFactory) {
    RedisTemplate<Object, Object> template = new RedisTemplate<>();
    template.setConnectionFactory(connectionFactory);

    //使用Jackson2JsonRedisSerializer来序列化和反序列化redis的value值
    Jackson2JsonRedisSerializer serializer = new Jackson2JsonRedisSerializer(Object.class);

    ObjectMapper mapper = new ObjectMapper();
    mapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
    mapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
    serializer.setObjectMapper(mapper);

    template.setValueSerializer(serializer);
    //使用StringRedisSerializer来序列化和反序列化redis的key值
    template.setKeySerializer(new StringRedisSerializer());
    template.afterPropertiesSet();
    return template;
}
项目:lodsve-framework    文件:RedisCacheConfiguration.java   
@Bean
public RedisTemplate<Object, Object> redisCacheRedisTemplate() {
    RedisTemplate<Object, Object> template = new RedisTemplate<>();

    template.setConnectionFactory(connectionFactory);

    Jackson2JsonRedisSerializer<Object> jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer<>(Object.class);
    ObjectMapper om = new ObjectMapper();
    om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
    om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
    jackson2JsonRedisSerializer.setObjectMapper(om);
    template.setKeySerializer(jackson2JsonRedisSerializer);
    template.setValueSerializer(jackson2JsonRedisSerializer);

    return template;
}
项目:orbit-dynamodb    文件:DynamoDBConnection.java   
private void initializeMapper(DynamoDBConfiguration dynamoDBConfiguration)
{
    final SimpleModule serializersModule = createSerializersForMapper();

    mapper = new ObjectMapper();

    mapper.registerModule(new ActorReferenceModule(DefaultDescriptorFactory.get()));
    mapper.registerModule(serializersModule);

    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);

    mapper.setVisibility(mapper.getSerializationConfig().getDefaultVisibilityChecker()
            .withFieldVisibility(JsonAutoDetect.Visibility.ANY)
            .withGetterVisibility(JsonAutoDetect.Visibility.NONE)
            .withIsGetterVisibility(JsonAutoDetect.Visibility.NONE)
            .withSetterVisibility(JsonAutoDetect.Visibility.NONE)
            .withCreatorVisibility(JsonAutoDetect.Visibility.NONE));

    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

    if (dynamoDBConfiguration.getMapperConfigurer() != null) {
        mapper = dynamoDBConfiguration.getMapperConfigurer().configure(mapper);
    }
}
项目:CarmenRest-VertX    文件:CarmenRestVertx.java   
static String toString(Object o) {
    ObjectMapper mapper = new ObjectMapper();

    mapper.setVisibility(mapper.getSerializationConfig().getDefaultVisibilityChecker()
            .withFieldVisibility(JsonAutoDetect.Visibility.ANY)
            .withGetterVisibility(JsonAutoDetect.Visibility.NONE)
            .withSetterVisibility(JsonAutoDetect.Visibility.NONE)
            .withCreatorVisibility(JsonAutoDetect.Visibility.NONE));

    String toret = "";

    try {
        toret = mapper.writeValueAsString(o);
    } catch (JsonProcessingException e) {
        e.printStackTrace();
    }

    return toret;
}
项目:CarmenRest-VertX    文件:Address.java   
public String toJson(boolean pretty) {
    ObjectMapper mapper = new ObjectMapper();

    mapper.setVisibility(mapper.getSerializationConfig().getDefaultVisibilityChecker()
               .withFieldVisibility(JsonAutoDetect.Visibility.ANY)
               .withGetterVisibility(JsonAutoDetect.Visibility.NONE)
               .withSetterVisibility(JsonAutoDetect.Visibility.NONE)
               .withCreatorVisibility(JsonAutoDetect.Visibility.NONE));

    String toret = "";

    if (pretty) {
        mapper.enable(SerializationFeature.INDENT_OUTPUT);
    }

    try {
        toret = mapper.writeValueAsString(this);
    } catch (JsonProcessingException e) {
        e.printStackTrace();
    }

    return toret;
}
项目:CarmenRest-VertX    文件:Choir.java   
public String toJson(boolean pretty) {
    ObjectMapper mapper = new ObjectMapper();

    mapper.setVisibility(mapper.getSerializationConfig().getDefaultVisibilityChecker()
               .withFieldVisibility(JsonAutoDetect.Visibility.ANY)
               .withGetterVisibility(JsonAutoDetect.Visibility.NONE)
               .withSetterVisibility(JsonAutoDetect.Visibility.NONE)
               .withCreatorVisibility(JsonAutoDetect.Visibility.NONE));

    String toret = "";

    if (pretty) {
        mapper.enable(SerializationFeature.INDENT_OUTPUT);
    }

    try {
        toret = mapper.writeValueAsString(this);
    } catch (JsonProcessingException e) {
        e.printStackTrace();
    }

    return toret;
}
项目:todolist    文件:CacheConfig.java   
@Bean
public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory factory) throws UnknownHostException {
    RedisTemplate<Object, Object> template = new RedisTemplate<>();
    template.setConnectionFactory(factory);

    Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
    ObjectMapper mapper = new ObjectMapper();
    mapper.findAndRegisterModules();
    mapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.NONE);
    mapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
    jackson2JsonRedisSerializer.setObjectMapper(mapper);

    template.setValueSerializer(jackson2JsonRedisSerializer);
    template.setKeySerializer(new StringRedisSerializer());

    template.afterPropertiesSet();

    return template;
}
项目:bitshadow    文件:BitShadowWebService.java   
@Override
public void initialize(Bootstrap<BitShadowConfiguration> bootstrap) {
    bootstrap.addBundle(GuiceBundle.builder()
            .modules(new BitShadowWebModule())
            .build()
    );
    bootstrap.addBundle(new SwaggerBundle<BitShadowConfiguration>() {
        @Override
        protected SwaggerBundleConfiguration getSwaggerBundleConfiguration(BitShadowConfiguration configuration) {
            return configuration.swaggerBundleConfiguration;
        }
    });

    bootstrap.getObjectMapper()
            .configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false)
            .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
            .setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.NONE)
            .setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY)
            .findAndRegisterModules();
}
项目:autorest-clientruntime-for-java    文件:PollingState.java   
/**
 * Initializes an object mapper.
 *
 * @param mapper the mapper to initialize
 * @return the initialized mapper
 */
private static ObjectMapper initMapper(ObjectMapper mapper) {
    mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false)
            .configure(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS, true)
            .configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, true)
            .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
            .configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true)
            .setSerializationInclusion(JsonInclude.Include.NON_NULL)
            .registerModule(new JodaModule())
            .registerModule(ByteArraySerializer.getModule())
            .registerModule(Base64UrlSerializer.getModule())
            .registerModule(DateTimeSerializer.getModule())
            .registerModule(DateTimeRfc1123Serializer.getModule())
            .registerModule(HeadersSerializer.getModule());
    mapper.setVisibility(mapper.getSerializationConfig().getDefaultVisibilityChecker()
            .withFieldVisibility(JsonAutoDetect.Visibility.ANY)
            .withSetterVisibility(JsonAutoDetect.Visibility.NONE)
            .withGetterVisibility(JsonAutoDetect.Visibility.NONE)
            .withIsGetterVisibility(JsonAutoDetect.Visibility.NONE));
    return mapper;
}
项目:autorest-clientruntime-for-java    文件:JacksonAdapter.java   
/**
 * Initializes an instance of JacksonMapperAdapter with default configurations
 * applied to the object mapper.
 *
 * @param mapper the object mapper to use.
 */
private static ObjectMapper initializeObjectMapper(ObjectMapper mapper) {
    mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false)
            .configure(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS, true)
            .configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, true)
            .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
            .configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true)
            .setSerializationInclusion(JsonInclude.Include.NON_NULL)
            .registerModule(new JodaModule())
            .registerModule(ByteArraySerializer.getModule())
            .registerModule(Base64UrlSerializer.getModule())
            .registerModule(DateTimeSerializer.getModule())
            .registerModule(DateTimeRfc1123Serializer.getModule())
            .registerModule(HeadersSerializer.getModule());
    mapper.setVisibility(mapper.getSerializationConfig().getDefaultVisibilityChecker()
            .withFieldVisibility(JsonAutoDetect.Visibility.ANY)
            .withSetterVisibility(JsonAutoDetect.Visibility.NONE)
            .withGetterVisibility(JsonAutoDetect.Visibility.NONE)
            .withIsGetterVisibility(JsonAutoDetect.Visibility.NONE));
    return mapper;
}
项目:cas4.1.9    文件:InternalConfigStateController.java   
@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;
}
项目:WebCrawler    文件:WebApp.java   
@Override
public void initialize(Bootstrap<AppConfiguration> bootstrap) {
    bootstrap.setConfigurationSourceProvider(
            new SubstitutingSourceProvider(bootstrap.getConfigurationSourceProvider(),
                    new EnvironmentVariableSubstitutor()
            )
    );

    /* Configure objectMapper to instantiate immutable configuration correctly */
    ObjectMapper objectMapper = bootstrap.getObjectMapper();
    objectMapper.registerModule(new JSR310Module());
    bootstrap.getObjectMapper()
            .setVisibilityChecker(objectMapper.getSerializationConfig().getDefaultVisibilityChecker()
                    .withFieldVisibility(JsonAutoDetect.Visibility.ANY)
                    .withGetterVisibility(JsonAutoDetect.Visibility.NONE)
                    .withSetterVisibility(JsonAutoDetect.Visibility.NONE)
                    .withCreatorVisibility(JsonAutoDetect.Visibility.NONE));

    /* Host static resources */
    bootstrap.addBundle((new AssetsBundle("/assets", "/", "index.html", "static")));

    /* Enable WebSockets support */
    bootstrap.addBundle(websocketBundle = new WebsocketBundle<>());
}
项目:WebCrawler    文件:CliApp.java   
@Override
public void run(final String... arguments) throws Exception {
    final Bootstrap<AppConfiguration> bootstrap = new Bootstrap<>(this);
    bootstrap.addCommand(command);
    initialize(bootstrap);

    ObjectMapper objectMapper = bootstrap.getObjectMapper();
    bootstrap.getObjectMapper()
            .setVisibilityChecker(objectMapper.getSerializationConfig().getDefaultVisibilityChecker()
            .withFieldVisibility(JsonAutoDetect.Visibility.ANY)
            .withGetterVisibility(JsonAutoDetect.Visibility.NONE)
            .withSetterVisibility(JsonAutoDetect.Visibility.NONE)
            .withCreatorVisibility(JsonAutoDetect.Visibility.NONE));

    final Cli cli = new Cli(new JarLocation(getClass()), bootstrap, System.out, System.err);
    if (!cli.run(arguments)) {
        System.exit(1);
    }
}
项目:vertx-jspare    文件:EnvironmentLoader.java   
/**
 * Register.
 */
public void setup() {

  // Prepare Environment with VertxInject
  Environment.create();

  // Set default Json Mapper options
  Json.mapper.setAnnotationIntrospector(new JacksonLombokAnnotationIntrospector())
    .setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY).setSerializationInclusion(JsonInclude.Include.NON_NULL)
    .disable(SerializationFeature.FAIL_ON_EMPTY_BEANS)
    .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
    .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
    //Safe register VertxJsonModule on Mapper
    .registerModule(new Jdk8Module())
    .registerModule(new JavaTimeModule())
    .registerModule(new ParameterNamesModule())
    .registerModule(new VertxJsonModule());
}
项目:mutinack    文件:Mutinack.java   
private static void outputJSON(Parameters param, Collection<Mutinack> analyzers) {
    if (!param.outputJSONTo.isEmpty()) {
        ObjectMapper mapper = new ObjectMapper();
        SimpleModule module = new SimpleModule();
        mapper.registerModule(module).setVisibility(mapper.getSerializationConfig().getDefaultVisibilityChecker()
                .withFieldVisibility(JsonAutoDetect.Visibility.ANY)
                .withGetterVisibility(JsonAutoDetect.Visibility.NONE)
                .withSetterVisibility(JsonAutoDetect.Visibility.NONE)
                .withCreatorVisibility(JsonAutoDetect.Visibility.NONE)
                .withIsGetterVisibility(JsonAutoDetect.Visibility.NONE));
        RunResult root = getRunResult(param, analyzers);
        try {
            File originalOutputFile = new File(param.outputJSONTo);
            String parentDirectory = originalOutputFile.getParent();
            mapper.writerWithDefaultPrettyPrinter().writeValue(
                    new File((parentDirectory == null ? "" : (parentDirectory + '/')) +
                        param.jsonFilePathExtraPrefix + originalOutputFile.getName()), root);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
项目:hawkular-bus    文件:BasicMessageObjectMapperTest.java   
@Override
protected ObjectMapper buildObjectMapperForSerialization() {
    final ObjectMapper mapper = new ObjectMapper();
    mapper.setVisibilityChecker(mapper.getSerializationConfig().getDefaultVisibilityChecker()
            .withFieldVisibility(JsonAutoDetect.Visibility.PUBLIC_ONLY)
            .withGetterVisibility(
                    (SUPPORT_GETTER_SETTER)
                            ? JsonAutoDetect.Visibility.PUBLIC_ONLY
                            : JsonAutoDetect.Visibility.NONE)
            .withSetterVisibility(
                    (SUPPORT_GETTER_SETTER)
                            ? JsonAutoDetect.Visibility.PUBLIC_ONLY
                            : JsonAutoDetect.Visibility.NONE)
            .withCreatorVisibility(JsonAutoDetect.Visibility.NONE));
    return mapper;
}
项目:hawkular-commons    文件:BasicMessageObjectMapperTest.java   
@Override
protected ObjectMapper buildObjectMapperForSerialization() {
    final ObjectMapper mapper = new ObjectMapper();
    mapper.setVisibilityChecker(mapper.getSerializationConfig().getDefaultVisibilityChecker()
            .withFieldVisibility(JsonAutoDetect.Visibility.PUBLIC_ONLY)
            .withGetterVisibility(
                    (SUPPORT_GETTER_SETTER)
                            ? JsonAutoDetect.Visibility.PUBLIC_ONLY
                            : JsonAutoDetect.Visibility.NONE)
            .withSetterVisibility(
                    (SUPPORT_GETTER_SETTER)
                            ? JsonAutoDetect.Visibility.PUBLIC_ONLY
                            : JsonAutoDetect.Visibility.NONE)
            .withCreatorVisibility(JsonAutoDetect.Visibility.NONE));
    return mapper;
}
项目:teavm-flavour    文件:ClassInformationProvider.java   
private void getAutoDetectModes(ClassInformation information, ReflectClass<?> cls) {
    ClassInformation parent = information.parent;
    if (parent != null) {
        information.getterVisibility = parent.getterVisibility;
        information.isGetterVisibility = parent.isGetterVisibility;
        information.setterVisibility = parent.setterVisibility;
        information.fieldVisibility = parent.fieldVisibility;
        information.creatorVisibility = parent.creatorVisibility;
    }

    JsonAutoDetect annot = cls.getAnnotation(JsonAutoDetect.class);
    if (annot != null) {
        information.getterVisibility = getVisibility(annot.getterVisibility(), information.getterVisibility);
        information.isGetterVisibility = getVisibility(annot.isGetterVisibility(), information.isGetterVisibility);
        information.setterVisibility = getVisibility(annot.setterVisibility(), information.setterVisibility);
        information.fieldVisibility = getVisibility(annot.fieldVisibility(), information.fieldVisibility);
        information.creatorVisibility = getVisibility(annot.creatorVisibility(), information.creatorVisibility);
    }
}
项目:teavm-flavour    文件:ClassInformationProvider.java   
private Visibility getVisibility(JsonAutoDetect.Visibility visibility, Visibility defaultVisibility) {
    switch (visibility) {
        case DEFAULT:
            return defaultVisibility;
        case ANY:
            return Visibility.ANY;
        case NON_PRIVATE:
            return Visibility.NON_PRIVATE;
        case NONE:
            return Visibility.NONE;
        case PROTECTED_AND_PUBLIC:
            return Visibility.PROTECTED_AND_PUBLIC;
        case PUBLIC_ONLY:
            return Visibility.PUBLIC_ONLY;
    }
    throw new AssertionError("Unsupported visibility:" + visibility);
}
项目:marketo-rest-sdk-java    文件:ObjectMapperProvider.java   
@Override
public ObjectMapper getContext(Class<?> type) {
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    objectMapper.configure(DeserializationFeature.FAIL_ON_INVALID_SUBTYPE, false);
    objectMapper.configure(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL, true);
    objectMapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true);
    objectMapper.setVisibility(objectMapper.getSerializationConfig().getDefaultVisibilityChecker()
            .withFieldVisibility(JsonAutoDetect.Visibility.ANY)
            .withGetterVisibility(JsonAutoDetect.Visibility.NONE)
            .withSetterVisibility(JsonAutoDetect.Visibility.NONE));
    objectMapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'Z"));

    objectMapper.registerModule(new SimpleModule()
            .addDeserializer(Void.TYPE, new VoidDeserializer()));

    return objectMapper;
}
项目:bitshadow    文件:BitShadowWebService.java   
@Override
public void initialize(Bootstrap<BitShadowConfiguration> bootstrap) {
    bootstrap.addBundle(GuiceBundle.builder()
            .modules(new BitShadowWebModule())
            .build()
    );
    bootstrap.addBundle(new SwaggerBundle<BitShadowConfiguration>() {
        @Override
        protected SwaggerBundleConfiguration getSwaggerBundleConfiguration(BitShadowConfiguration configuration) {
            return configuration.swaggerBundleConfiguration;
        }
    });

    bootstrap.getObjectMapper()
            .configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false)
            .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
            .setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.NONE)
            .setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY)
            .findAndRegisterModules();
}
项目:invesdwin-nowicket    文件:RdpConfig.java   
@Override
public String toJSON() {

    final ObjectMapper mapper = new ObjectMapper();
    mapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
    final ByteArrayOutputStream stream = new ByteArrayOutputStream();
    String json = null;
    try {
        mapper.writeValue(stream, this);
        json = new String(stream.toByteArray(), "UTF-8");
    } catch (final IOException e) {
        Err.process(e);
    }

    //TODO serialize Object as JSON
    return json;
}
项目:argos-dashboard    文件:StreamController.java   
@Autowired
public StreamController(ClusterRegistry registry, Observable<Boolean> shutdown) {
    Objects.requireNonNull(registry);
    Objects.requireNonNull(shutdown);
    ObjectMapper om = new ObjectMapper();
    om.enable(MapperFeature.AUTO_DETECT_FIELDS);
    om.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
    om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);


    Observable<HystrixClusterMetrics> metricsObs = registry.observe();

    streamObservable = metricsObs
            .takeUntil(shutdown)
            .map(d -> {
                try {
                    return om.writeValueAsString(d);
                } catch (JsonProcessingException e) {
                    throw new RuntimeException(e);
                }
            })
            .share();
}
项目:streamline    文件:NotificationBoltFluxComponent.java   
@Override
protected void generateComponent() {
    notificationSink = (NotificationSink) conf.get(StormTopologyLayoutConstants.STREAMLINE_COMPONENT_CONF_KEY);
    String boltId = "notificationBolt" + UUID_FOR_COMPONENTS;
    String boltClassName = "com.hortonworks.streamline.streams.runtime.storm.bolt.notification.NotificationBolt";
    String[] constructorArgNames = {TopologyLayoutConstants.JSON_KEY_NOTIFICATION_SINK_JSON};
    try {
        if (notificationSink == null) {
            throw new RuntimeException("Error generating flux, notificationSink = " + notificationSink);
        }
        ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.NONE);
        objectMapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
        String notificationSinkJsonStr = objectMapper.writeValueAsString(notificationSink);
        conf.put(TopologyLayoutConstants.JSON_KEY_NOTIFICATION_SINK_JSON, notificationSinkJsonStr);
    } catch (JsonProcessingException ex) {
        throw new RuntimeException(ex);
    }
    List<Object> boltConstructorArgs = getConstructorArgsYaml(constructorArgNames);
    String[] configMethodNames = {"withNotificationStoreClass"};
    String[] configKeys = {TopologyLayoutConstants.JSON_KEY_NOTIFICATION_STORE_CLASS};
    List configMethods = getConfigMethodsYaml(configMethodNames, configKeys);
    component = createComponent(boltId, boltClassName, null, boltConstructorArgs, configMethods);
    addParallelismToComponent();
}
项目:restvertx    文件:RestVertx.java   
static String toString(Object o) {
    ObjectMapper mapper = new ObjectMapper();

    mapper.setVisibility(mapper.getSerializationConfig().getDefaultVisibilityChecker()
            .withFieldVisibility(JsonAutoDetect.Visibility.ANY)
            .withGetterVisibility(JsonAutoDetect.Visibility.NONE)
            .withSetterVisibility(JsonAutoDetect.Visibility.NONE)
            .withCreatorVisibility(JsonAutoDetect.Visibility.NONE));

    String toret = "";

    try {
        toret = mapper.writeValueAsString(o);
    } catch (JsonProcessingException e) {
        e.printStackTrace();
    }

    return toret;
}