本文整理匯總了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;
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
}
示例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);
}
}
示例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();
}
示例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;
}
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
}