当前位置: 首页>>代码示例>>Java>>正文


Java JsonAutoDetect类代码示例

本文整理汇总了Java中com.fasterxml.jackson.annotation.JsonAutoDetect的典型用法代码示例。如果您正苦于以下问题:Java JsonAutoDetect类的具体用法?Java JsonAutoDetect怎么用?Java JsonAutoDetect使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


JsonAutoDetect类属于com.fasterxml.jackson.annotation包,在下文中一共展示了JsonAutoDetect类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: redisTemplate

import com.fasterxml.jackson.annotation.JsonAutoDetect; //导入依赖的package包/类
@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;
}
 
开发者ID:cwenao,项目名称:springboot_cwenao,代码行数:25,代码来源:RedisConfig.java

示例2: setUp

import com.fasterxml.jackson.annotation.JsonAutoDetect; //导入依赖的package包/类
@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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:20,代码来源:JacksonConverterFactoryTest.java

示例3: initializeObjectMapper

import com.fasterxml.jackson.annotation.JsonAutoDetect; //导入依赖的package包/类
@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;
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:20,代码来源:InternalConfigStateController.java

示例4: objectMapper

import com.fasterxml.jackson.annotation.JsonAutoDetect; //导入依赖的package包/类
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);
}
 
开发者ID:readlearncode,项目名称:JSON-framework-comparison,代码行数:20,代码来源:RuntimeSampler.java

示例5: redisTemplate

import com.fasterxml.jackson.annotation.JsonAutoDetect; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:SnailFastGo,项目名称:springboot_op,代码行数:22,代码来源:RedisConfiguration.java

示例6: redisTemplate

import com.fasterxml.jackson.annotation.JsonAutoDetect; //导入依赖的package包/类
@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;
}
 
开发者ID:duanyaxin,项目名称:springboot-smart,代码行数:17,代码来源:RedisConfiguration.java

示例7: LuceneService

import com.fasterxml.jackson.annotation.JsonAutoDetect; //导入依赖的package包/类
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);
    }
}
 
开发者ID:dizitart,项目名称:nitrite-database,代码行数:26,代码来源:LuceneService.java

示例8: execute

import com.fasterxml.jackson.annotation.JsonAutoDetect; //导入依赖的package包/类
@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);
    }
}
 
开发者ID:NHS-digital-website,项目名称:hippo,代码行数:23,代码来源:GenerateTaxonomyTask.java

示例9: ApiFactory

import com.fasterxml.jackson.annotation.JsonAutoDetect; //导入依赖的package包/类
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();
}
 
开发者ID:Lovelcp,项目名称:Easy-WeChat,代码行数:19,代码来源:ApiFactory.java

示例10: objectToString

import com.fasterxml.jackson.annotation.JsonAutoDetect; //导入依赖的package包/类
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;
    }
}
 
开发者ID:LeeKyoungIl,项目名称:illuminati,代码行数:20,代码来源:StringObjectUtils.java

示例11: redisTemplate

import com.fasterxml.jackson.annotation.JsonAutoDetect; //导入依赖的package包/类
@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;
}
 
开发者ID:fanqinghui,项目名称:action,代码行数:20,代码来源:RedisUtil.java

示例12: configureerMapper

import com.fasterxml.jackson.annotation.JsonAutoDetect; //导入依赖的package包/类
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);
}
 
开发者ID:MinBZK,项目名称:OperatieBRP,代码行数:22,代码来源:BrpJsonObjectMapper.java

示例13: initializeMapper

import com.fasterxml.jackson.annotation.JsonAutoDetect; //导入依赖的package包/类
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);
}
 
开发者ID:MinBZK,项目名称:OperatieBRP,代码行数:25,代码来源:JsonMapper.java

示例14: redisCacheRedisTemplate

import com.fasterxml.jackson.annotation.JsonAutoDetect; //导入依赖的package包/类
@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;
}
 
开发者ID:lodsve,项目名称:lodsve-framework,代码行数:17,代码来源:RedisCacheConfiguration.java

示例15: initializeMapper

import com.fasterxml.jackson.annotation.JsonAutoDetect; //导入依赖的package包/类
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);
    }
}
 
开发者ID:orbit,项目名称:orbit-dynamodb,代码行数:25,代码来源:DynamoDBConnection.java


注:本文中的com.fasterxml.jackson.annotation.JsonAutoDetect类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。