本文整理匯總了Java中com.fasterxml.jackson.databind.ObjectMapper.enableDefaultTypingAsProperty方法的典型用法代碼示例。如果您正苦於以下問題:Java ObjectMapper.enableDefaultTypingAsProperty方法的具體用法?Java ObjectMapper.enableDefaultTypingAsProperty怎麽用?Java ObjectMapper.enableDefaultTypingAsProperty使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.fasterxml.jackson.databind.ObjectMapper
的用法示例。
在下文中一共展示了ObjectMapper.enableDefaultTypingAsProperty方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: importAnnotationQueries
import com.fasterxml.jackson.databind.ObjectMapper; //導入方法依賴的package包/類
private static AnnotationQueries importAnnotationQueries(String annotationFile){
//initialize JSON-Object mapper
ObjectMapper mapper = new ObjectMapper();
mapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.NONE);
//use all fields
mapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
//only include not null & non empty fields
mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
//store type of classess also
mapper.enableDefaultTypingAsProperty(ObjectMapper.DefaultTyping.NON_FINAL, "@class");
//ignore unknown properties
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.configure(DeserializationFeature.FAIL_ON_UNRESOLVED_OBJECT_IDS, false);
mapper.configure(DeserializationFeature.FAIL_ON_INVALID_SUBTYPE, false);
AnnotationQueries q = null;
try {
q = mapper.readValue(new FileInputStream(new File(annotationFile)), AnnotationQueries.class); //read JSON from URL
} catch (IOException e1) {
e1.printStackTrace();
}
return q;
}