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


Java ObjectMapper.enableDefaultTyping方法代码示例

本文整理汇总了Java中com.fasterxml.jackson.databind.ObjectMapper.enableDefaultTyping方法的典型用法代码示例。如果您正苦于以下问题:Java ObjectMapper.enableDefaultTyping方法的具体用法?Java ObjectMapper.enableDefaultTyping怎么用?Java ObjectMapper.enableDefaultTyping使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.fasterxml.jackson.databind.ObjectMapper的用法示例。


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

示例1: redisTemplate

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的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: roundtrip

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
@Test
public void roundtrip() throws IOException {
  final ObjectMapper objectMapper = new ObjectMapper();

  objectMapper.enableDefaultTyping();
  objectMapper.registerModule(new GuavaModule());

  ImmutableOuterObject outer = ImmutableOuterObject.builder()
      .emptyObject(
          ImmutableEmptyObject
              .builder()
              .build())
      .build();

  String serialized = objectMapper.writeValueAsString(outer);

  check(objectMapper.readValue(serialized, ImmutableOuterObject.class)).is(outer);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:19,代码来源:DefaultTypingTest.java

示例3: redisTemplate

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的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:finefuture,项目名称:data-migration,代码行数:20,代码来源:RedisConfiguration.java

示例4: redisTemplate

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的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

示例5: redisTemplate

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的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

示例6: home

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
@RequestMapping("/")
@ResponseBody
public String home(@RequestParam(value = "name", defaultValue = "guest", required = false) String name) throws IOException {
    Random rand = new Random();
    int id = rand.nextInt();

    User webUser = new User(id, name);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject(webUser);
    oos.close();
    String webUserOISB64 = Base64.getEncoder().encodeToString(baos.toByteArray());

    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.WRAPPER_ARRAY);

    String webUserJackson = objectMapper.writeValueAsString(webUser);
    String webUserJacksonB64 = Base64.getEncoder().encodeToString(webUserJackson.getBytes("utf-8"));
    return String.format("<a href='/?name=test'>set your name</a></br><a href='ois?sess=%s'>look at yourself</a></br><a href='jackson?sess=%s'>look at yourself</a>", webUserOISB64, webUserJacksonB64);
}
 
开发者ID:GrrrDog,项目名称:ZeroNights-WebVillage-2017,代码行数:21,代码来源:DeserController.java

示例7: initializeObjectMapper

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
/**
 * Initialize object mapper.
 *
 * @return the object mapper
 */
protected ObjectMapper initializeObjectMapper() {
    final ObjectMapper mapper = new ObjectMapper();
    mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
    mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
    mapper.setVisibility(PropertyAccessor.SETTER, JsonAutoDetect.Visibility.PROTECTED_AND_PUBLIC);
    mapper.setVisibility(PropertyAccessor.GETTER, JsonAutoDetect.Visibility.PROTECTED_AND_PUBLIC);
    mapper.setVisibility(PropertyAccessor.IS_GETTER, JsonAutoDetect.Visibility.PROTECTED_AND_PUBLIC);
    mapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY);
    return mapper;
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:16,代码来源:AbstractJacksonBackedJsonSerializer.java

示例8: jsonSerialization

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
/**
 * Serialize all the class attributes
 * @return
 * @throws Exception 
 */
public JsonNode jsonSerialization() throws Exception
{        
    JsonNode jsonError;
    ObjectMapper mapper = new ObjectMapper();
    mapper.enableDefaultTyping();
    DateFormat myDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
    mapper.setDateFormat(myDateFormat);       
    jsonError = mapper.convertValue(this, JsonNode.class);
    return jsonError;
}
 
开发者ID:ejesposito,项目名称:CS6310O01,代码行数:16,代码来源:Role.java

示例9: redisTemplate

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
@Bean
public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory factory) {
    StringRedisTemplate template = new StringRedisTemplate(factory);
    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:ChinaLHR,项目名称:JavaQuarkBBS,代码行数:13,代码来源:RedisConfig.java

示例10: jacksonJsonRedisSerializer

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
@Bean
public Jackson2JsonRedisSerializer jacksonJsonRedisSerializer() {
    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);
    return jackson2JsonRedisSerializer;
}
 
开发者ID:luoxn28,项目名称:redis-info,代码行数:12,代码来源:RedisJsonConfig.java

示例11: jackson

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
@RequestMapping("/jackson")
@ResponseBody
public String jackson(@RequestParam(value = "sess") String session) throws IOException, ClassNotFoundException {

    String webUserJackson = new String(Base64.getDecoder().decode(session), "utf-8");
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.enableDefaultTyping();
    User webUser = (User) objectMapper.readValue(webUserJackson, Object.class);

    return "Hello " + webUser;
}
 
开发者ID:GrrrDog,项目名称:ZeroNights-WebVillage-2017,代码行数:12,代码来源:DeserController.java

示例12: jsonDesSerialization

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
/**
 * Des-Serialize an object who was in json format
 * @param jsonObject
 * @return
 * @throws Exception 
 */
public static Role jsonDesSerialization(JsonNode jsonObject) throws Exception
{
    Role object;
    ObjectMapper mapper = new ObjectMapper();
    mapper.enableDefaultTyping();
    DateFormat myDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
    mapper.setDateFormat(myDateFormat); 
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    object = mapper.convertValue(jsonObject,Role.class);
    return object;
}
 
开发者ID:ejesposito,项目名称:CS6310O01,代码行数:18,代码来源:Role.java

示例13: setSerializer

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
  private void setSerializer(RedisTemplate<String, Object> template) {
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.setKeySerializer(new StringRedisSerializer());
      //template.setValueSerializer(jackson2JsonRedisSerializer);		//-- 值序列化为json
      template.setValueSerializer(new RedisObjectSerializer());       //-- 默认序列化为byte[]
  }
 
开发者ID:ranji1221,项目名称:lemcloud,代码行数:12,代码来源:RedisConfig.java

示例14: marshal

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 *
 * @see marshalsec.MarshallerBase#marshal(java.lang.Object)
 */
@Override
public String marshal ( Object o ) throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    mapper.enableDefaultTyping();
    return mapper.writeValueAsString(o);
}
 
开发者ID:mbechler,项目名称:marshalsec,代码行数:12,代码来源:Jackson.java

示例15: unmarshal

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 *
 * @see marshalsec.MarshallerBase#unmarshal(java.lang.Object)
 */
@Override
public Object unmarshal ( String data ) throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    mapper.enableDefaultTyping();
    return mapper.readValue(data, Object.class);
}
 
开发者ID:mbechler,项目名称:marshalsec,代码行数:12,代码来源:Jackson.java


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