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