本文整理汇总了Java中org.codehaus.jackson.map.AnnotationIntrospector.Pair方法的典型用法代码示例。如果您正苦于以下问题:Java AnnotationIntrospector.Pair方法的具体用法?Java AnnotationIntrospector.Pair怎么用?Java AnnotationIntrospector.Pair使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.codehaus.jackson.map.AnnotationIntrospector
的用法示例。
在下文中一共展示了AnnotationIntrospector.Pair方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.codehaus.jackson.map.AnnotationIntrospector; //导入方法依赖的package包/类
public static void main(String[] args) throws JsonMappingException {
ObjectMapper jsonMapper = new ObjectMapper();
AnnotationIntrospector introspector = new AnnotationIntrospector.Pair(new JaxbAnnotationIntrospector(),
new JacksonAnnotationIntrospector());
jsonMapper.setAnnotationIntrospector(introspector);
JsonSchema schema = jsonMapper.generateJsonSchema(Testi.class);
if(Testi.class.getAnnotation(XmlRootElement.class)!=null
&& !Testi.class.getAnnotation(XmlRootElement.class).name().equals("##default"))
schema.getSchemaNode().put("name", Testi.class.getAnnotation(XmlRootElement.class).name());
else if(Testi.class.getAnnotation(XmlType.class)!=null
&& !Testi.class.getAnnotation(XmlType.class).name().equals("##default"))
schema.getSchemaNode().put("name", Testi.class.getAnnotation(XmlType.class).name());
else
schema.getSchemaNode().put("name", Testi.class.getSimpleName());
String schemaJson = schema.toString();
System.out.println(schemaJson);
}
示例2: getObjectMapper
import org.codehaus.jackson.map.AnnotationIntrospector; //导入方法依赖的package包/类
@Bean(name="defaultObjectMapper")
public ObjectMapper getObjectMapper() {
if(defaultObjectMapper==null) {
ObjectMapper mapper = new ObjectMapper();
AnnotationIntrospector primary = new JaxbAnnotationIntrospector();
AnnotationIntrospector secondary = new JacksonAnnotationIntrospector();
AnnotationIntrospector pair = new AnnotationIntrospector.Pair(primary, secondary);
mapper.getDeserializationConfig().setAnnotationIntrospector(pair);
mapper.getDeserializationConfig().set(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.getSerializationConfig().setAnnotationIntrospector(pair);
mapper.getSerializationConfig().setSerializationInclusion(JsonSerialize.Inclusion.NON_NULL);
mapper.configure(SerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPS, false);
mapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true);
this.defaultObjectMapper = mapper;
}
return defaultObjectMapper;
}
示例3: updateGenerator
import org.codehaus.jackson.map.AnnotationIntrospector; //导入方法依赖的package包/类
/**
* Update the generator with a default codec and pretty printer
*
* @param jsonFactory Factory to set as codec
* @param jsonGenerator Generator to configure
*/
private static void updateGenerator(JsonFactory jsonFactory, JsonGenerator jsonGenerator) {
ObjectMapper mapper = new ObjectMapper(jsonFactory);
//Update the annotation interceptor to also include jaxb annotations as a second choice
AnnotationIntrospector primary = new JacksonAnnotationIntrospector();
AnnotationIntrospector secondary = new JaxbAnnotationIntrospector() {
/**
* BUG FIX:
* By contract, if findSerializationInclusion didn't encounter any annotations that should change the
* inclusion value, it should return the default value it has received; but actually returns null, which
* overrides the NON_NULL option we set.
* The doc states issue JACKSON-256 which was supposed to be fixed in 1.5.0. *twilight zone theme song*
*/
@Override
public JsonSerialize.Inclusion findSerializationInclusion(Annotated a, JsonSerialize.Inclusion defValue) {
JsonSerialize.Inclusion inclusion = super.findSerializationInclusion(a, defValue);
if (inclusion == null) {
return defValue;
}
return inclusion;
}
};
AnnotationIntrospector pair = new AnnotationIntrospector.Pair(primary, secondary);
mapper.getSerializationConfig().setAnnotationIntrospector(pair);
mapper.getSerializationConfig().setSerializationInclusion(JsonSerialize.Inclusion.NON_NULL);
jsonGenerator.setCodec(mapper);
jsonGenerator.useDefaultPrettyPrinter();
}
示例4: updateParser
import org.codehaus.jackson.map.AnnotationIntrospector; //导入方法依赖的package包/类
/**
* Update the parser with a default codec
*
* @param jsonFactory Factory to set as codec
* @param jsonParser Parser to configure
*/
private static void updateParser(JsonFactory jsonFactory, JsonParser jsonParser) {
AnnotationIntrospector primary = new JacksonAnnotationIntrospector();
AnnotationIntrospector secondary = new JaxbAnnotationIntrospector();
AnnotationIntrospector pair = new AnnotationIntrospector.Pair(primary, secondary);
ObjectMapper mapper = new ObjectMapper(jsonFactory);
mapper.getSerializationConfig().setAnnotationIntrospector(pair);
mapper.getDeserializationConfig().setAnnotationIntrospector(pair);
mapper.getDeserializationConfig().disable(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES);
jsonParser.setCodec(mapper);
}
示例5: JsonProvider
import org.codehaus.jackson.map.AnnotationIntrospector; //导入方法依赖的package包/类
public JsonProvider() {
ObjectMapper mapper = getMapper();
//Update the annotation interceptor to also include jaxb annotations as a second choice
AnnotationIntrospector primary = new JacksonAnnotationIntrospector();
AnnotationIntrospector secondary = new JaxbAnnotationIntrospector();
AnnotationIntrospector pair = new AnnotationIntrospector.Pair(primary, secondary);
mapper.getSerializationConfig().setAnnotationIntrospector(pair);
mapper.getSerializationConfig().setSerializationInclusion(JsonSerialize.Inclusion.NON_NULL);
mapper.getDeserializationConfig().setAnnotationIntrospector(pair);
//Ignore missing properties
mapper.getDeserializationConfig().disable(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES);
}
示例6: JacksonJaxbContextResolver
import org.codehaus.jackson.map.AnnotationIntrospector; //导入方法依赖的package包/类
public JacksonJaxbContextResolver() {
this.objectMapper = new ObjectMapper();
final AnnotationIntrospector primary = new JacksonAnnotationIntrospector();
final AnnotationIntrospector secondary = new JaxbAnnotationIntrospector();
final AnnotationIntrospector pair = new AnnotationIntrospector.Pair(primary, secondary);
this.objectMapper.getDeserializationConfig().setAnnotationIntrospector(pair);
this.objectMapper.getSerializationConfig().setAnnotationIntrospector(pair);
}
示例7: ObjectMapperFactoryBean
import org.codehaus.jackson.map.AnnotationIntrospector; //导入方法依赖的package包/类
public ObjectMapperFactoryBean() {
this.objectMapper = new ObjectMapper();
this.objectMapper.setSerializationInclusion(Inclusion.NON_NULL);
this.objectMapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
AnnotationIntrospector primary = new JacksonAnnotationIntrospector();
AnnotationIntrospector secondary = new JaxbAnnotationIntrospector();
AnnotationIntrospector pair = new AnnotationIntrospector.Pair(primary, secondary);
this.objectMapper.setAnnotationIntrospector(pair);
}
示例8: locateMapper
import org.codehaus.jackson.map.AnnotationIntrospector; //导入方法依赖的package包/类
@Override
public ObjectMapper locateMapper(Class<?> type, MediaType mediaType) {
ObjectMapper mapper = super.locateMapper(type, mediaType);
AnnotationIntrospector introspector = new AnnotationIntrospector.Pair(
new JaxbAnnotationIntrospector(),
new JacksonAnnotationIntrospector()
);
mapper.setAnnotationIntrospector(introspector);
//mapper.setSerializationInclusion(Inclusion.NON_NULL);
return mapper;
}
示例9: createJsonMapper
import org.codehaus.jackson.map.AnnotationIntrospector; //导入方法依赖的package包/类
/**
* Creates json mapper.
*
* @return json mapper
*/
public static ObjectMapper createJsonMapper() {
final AnnotationIntrospector jaxb = new JaxbAnnotationIntrospector();
final AnnotationIntrospector jackson = new JacksonAnnotationIntrospector();
final AnnotationIntrospector pair = new AnnotationIntrospector.Pair(jackson, jaxb);
final ObjectMapper mapper = new ObjectMapper();
mapper.getDeserializationConfig().withAnnotationIntrospector(pair);
mapper.getSerializationConfig().withAnnotationIntrospector(pair);
return mapper;
}
示例10: createJsonMapper
import org.codehaus.jackson.map.AnnotationIntrospector; //导入方法依赖的package包/类
public static ObjectMapper createJsonMapper() {
final AnnotationIntrospector jaxb = new JaxbAnnotationIntrospector();
final AnnotationIntrospector jackson = new JacksonAnnotationIntrospector();
final AnnotationIntrospector pair = new AnnotationIntrospector.Pair(jackson, jaxb);
final ObjectMapper mapper = new ObjectMapper();
mapper.getDeserializationConfig().withAnnotationIntrospector(pair);
mapper.getSerializationConfig().withAnnotationIntrospector(pair);
return mapper;
}
示例11: createJaxbJacksonAnnotationIntrospector
import org.codehaus.jackson.map.AnnotationIntrospector; //导入方法依赖的package包/类
private static Pair createJaxbJacksonAnnotationIntrospector() {
AnnotationIntrospector jaxbIntrospector = new JaxbAnnotationIntrospector();
AnnotationIntrospector jacksonIntrospector = new JacksonAnnotationIntrospector();
return new AnnotationIntrospector.Pair(jacksonIntrospector, jaxbIntrospector);
}