本文整理汇总了Java中org.codehaus.jackson.xc.JaxbAnnotationIntrospector类的典型用法代码示例。如果您正苦于以下问题:Java JaxbAnnotationIntrospector类的具体用法?Java JaxbAnnotationIntrospector怎么用?Java JaxbAnnotationIntrospector使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JaxbAnnotationIntrospector类属于org.codehaus.jackson.xc包,在下文中一共展示了JaxbAnnotationIntrospector类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: CustomObjectMapper
import org.codehaus.jackson.xc.JaxbAnnotationIntrospector; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
public CustomObjectMapper()
{
super();
this.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
this.configure(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS, false);
this.configure(SerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPS, false);
this.setSerializationInclusion(JsonSerialize.Inclusion.NON_DEFAULT);
this.setSerializationInclusion(JsonSerialize.Inclusion.NON_NULL);
this.setSerializationInclusion(JsonSerialize.Inclusion.NON_EMPTY);
final AnnotationIntrospector introspector = new JaxbAnnotationIntrospector();
// make deserializer use JAXB annotations (only)
this.setAnnotationIntrospector(introspector);
// TODO leverage NamingStrategy to make reponse attributes more Java-like
//this.setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES);
}
示例2: JsonModelSerializer
import org.codehaus.jackson.xc.JaxbAnnotationIntrospector; //导入依赖的package包/类
public JsonModelSerializer(boolean doNullValues, Class<T> serializedType) {
super();
objectMapper = new ObjectMapper();
AnnotationIntrospector introspector = new JaxbAnnotationIntrospector();
// make serializer use JAXB annotations (only)
SerializationConfig sc = objectMapper.getSerializationConfig().withAnnotationIntrospector(introspector);
sc.with(SerializationConfig.Feature.INDENT_OUTPUT);
if (!doNullValues) {
sc.without(SerializationConfig.Feature.WRITE_NULL_MAP_VALUES);
sc.without(SerializationConfig.Feature.WRITE_EMPTY_JSON_ARRAYS);
sc = sc.withSerializationInclusion(Inclusion.NON_EMPTY);
}
objectMapper.setSerializationConfig(sc);
// if (!doNullValues) {
// objectMapper.setSerializationInclusion(Inclusion.NON_EMPTY);
// }
}
示例3: buildJson
import org.codehaus.jackson.xc.JaxbAnnotationIntrospector; //导入依赖的package包/类
private String buildJson(Object object) {
ObjectMapper mapper = new ObjectMapper();
SerializationConfig serializationConfig = mapper.getSerializationConfig();
serializationConfig = serializationConfig.withSerializationInclusion(JsonSerialize.Inclusion.NON_NULL);
AnnotationIntrospector introspector = new JaxbAnnotationIntrospector();
mapper.setSerializationConfig(serializationConfig);
mapper.setAnnotationIntrospector(introspector);
try {
return mapper.writeValueAsString(object);
} catch (IOException e) {
log.warn("Can't marshal search criteria.");
throw new RuntimeException("Failed inFolder build criteria json.", e);
}
}
示例4: main
import org.codehaus.jackson.xc.JaxbAnnotationIntrospector; //导入依赖的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);
}
示例5: getObjectMapper
import org.codehaus.jackson.xc.JaxbAnnotationIntrospector; //导入依赖的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;
}
示例6: createObjectMapper
import org.codehaus.jackson.xc.JaxbAnnotationIntrospector; //导入依赖的package包/类
private ObjectMapper createObjectMapper() {
ObjectMapper mapper = new ObjectMapper();
mapper.setAnnotationIntrospector(new JaxbAnnotationIntrospector());
mapper.setSerializationInclusion(Inclusion.NON_NULL);
mapper.configure(Feature.CLOSE_CLOSEABLE, false);
return mapper;
}
示例7: createRESTClientProxy
import org.codehaus.jackson.xc.JaxbAnnotationIntrospector; //导入依赖的package包/类
@Override
protected <T> T createRESTClientProxy(String apiUrl, Class<T> proxy) {
URI i = null;
try {
i = new URI(apiUrl);
} catch (URISyntaxException ex) {
throw new RuntimeException(ex);
}
ResteasyClientBuilder builder = new ResteasyClientBuilder();
builder.connectionCheckoutTimeout(CONNECTION_SETUP_TO, TimeUnit.SECONDS);
builder.socketTimeout(CONNECTION_SETUP_TO, TimeUnit.SECONDS);
builder.httpEngine(new URLConnectionEngine());
ResteasyProviderFactory.getInstance().register(builder);
ResteasyClient client = builder.build();
client.register(new ClientRequestFilter() {
@Override
public void filter(ClientRequestContext requestContext) throws IOException {
requestContext.getHeaders().add("User-Agent", getImplementationName() + "=" + getVersion());
}
});
ObjectMapper mapper = new ObjectMapper();
JacksonJaxbJsonProvider jaxbProvider
= new JacksonJaxbJsonProvider(mapper, JacksonJaxbJsonProvider.DEFAULT_ANNOTATIONS);
mapper.setAnnotationIntrospector(new JaxbAnnotationIntrospector());
mapper.configure(Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
builder.register(jaxbProvider);
builder.register(proxy);
ResteasyWebTarget resteasyWebTarget = client.target(i);
return resteasyWebTarget.proxy(proxy);
}
示例8: CustomJsonProvider
import org.codehaus.jackson.xc.JaxbAnnotationIntrospector; //导入依赖的package包/类
public CustomJsonProvider(){
ObjectMapper mapper = new ObjectMapper();
mapper.configure(org.codehaus.jackson.map.DeserializationConfig.Feature.UNWRAP_ROOT_VALUE, true);
mapper.configure(org.codehaus.jackson.map.SerializationConfig.Feature.WRAP_ROOT_VALUE, true);
_mapperConfig.setMapper(mapper);
_mapperConfig.getConfiguredMapper().setAnnotationIntrospector(new JaxbAnnotationIntrospector());
}
示例9: CustomJsonProviderList
import org.codehaus.jackson.xc.JaxbAnnotationIntrospector; //导入依赖的package包/类
public CustomJsonProviderList(){
ObjectMapper mapper = new ObjectMapper();
mapper.configure(org.codehaus.jackson.map.DeserializationConfig.Feature.UNWRAP_ROOT_VALUE, true);
mapper.configure(org.codehaus.jackson.map.SerializationConfig.Feature.WRAP_ROOT_VALUE, false);
_mapperConfig.setMapper(mapper);
_mapperConfig.getConfiguredMapper().setAnnotationIntrospector(new JaxbAnnotationIntrospector());
}
示例10: CustomJsonProviderList
import org.codehaus.jackson.xc.JaxbAnnotationIntrospector; //导入依赖的package包/类
public CustomJsonProviderList(){
ObjectMapper mapper = new ObjectMapper();
mapper.configure(org.codehaus.jackson.map.DeserializationConfig.Feature.UNWRAP_ROOT_VALUE, true);
// Can not deserialize instance of ArrayList out of String
mapper.configure(org.codehaus.jackson.map.DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY,true);
//Remove extra root value for class that include only a list
mapper.configure(org.codehaus.jackson.map.SerializationConfig.Feature.WRAP_ROOT_VALUE, false);
_mapperConfig.setMapper(mapper);
_mapperConfig.getConfiguredMapper().setAnnotationIntrospector(new JaxbAnnotationIntrospector());
}
示例11: JsonModelDeserializer
import org.codehaus.jackson.xc.JaxbAnnotationIntrospector; //导入依赖的package包/类
public JsonModelDeserializer(Class<T> deserializedObjectType) {
super();
this.deserializedObjectType = deserializedObjectType;
objectMapper = new ObjectMapper();
AnnotationIntrospector introspector = new JaxbAnnotationIntrospector();
// make serializer use JAXB annotations (only)
objectMapper.setDeserializationConfig(objectMapper.getDeserializationConfig().withAnnotationIntrospector(introspector));
objectTypeXmlTagName = deserializedObjectType.getAnnotation(XmlRootElement.class).name();
}
示例12: updateGenerator
import org.codehaus.jackson.xc.JaxbAnnotationIntrospector; //导入依赖的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();
}
示例13: updateParser
import org.codehaus.jackson.xc.JaxbAnnotationIntrospector; //导入依赖的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);
}
示例14: JsonProvider
import org.codehaus.jackson.xc.JaxbAnnotationIntrospector; //导入依赖的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);
}
示例15: createObjectMapper
import org.codehaus.jackson.xc.JaxbAnnotationIntrospector; //导入依赖的package包/类
private ObjectMapper createObjectMapper() {
ObjectMapper mapper = new ObjectMapper();
mapper.setAnnotationIntrospector(new JaxbAnnotationIntrospector());
mapper.setSerializationInclusion(Inclusion.NON_NULL);
mapper.configure(Feature.CLOSE_CLOSEABLE, false);
mapper.configure(Feature.FLUSH_AFTER_WRITE_VALUE, false);
return mapper;
}