java - Configure Jackson 2.x to NOT use @XmlElement field annotation for JSON field naming -
i have looked @ question , made work using
.configure(deserializationconfig.feature.use_annotations, true) .configure(serializationconfig.feature.use_annotations, true);
on custom objectmapper
json serialization works fine above configuration.
but problem want utilize jackson 2.x because of improve deserialization command , cannot find documentation indicating how configure jackson 2.x ignore jaxb annotations
any help appreciated.
update: tried objectmapper.configure(mapperfeature.use_annotations, false);
seems have no effect on jackson picking jaxb annotations.
second update: posted solution below answer.
the solution found creating objectmapper
, registering bailiwick of jersey within main method (i using springboot bailiwick of jersey finish solution).
if created objectmapper
in other class , tried register in main, neither constructor of class beingness called nor overridden getcontext()
method. created objectmapper within main method , registered provider jersey.
snippet:
objectmapper mapper = new objectmapper(); mapper.enable(mapperfeature.use_annotations); // create jsonprovider provide custom objectmapper jacksonjsonprovider provider = new jacksonjsonprovider(); provider.setmapper(mapper);
and
register(provider);
maven dependencies, annotations , jacksonjsonprovider available in different artifacts:
<dependency> <groupid>com.fasterxml.jackson.module</groupid> <artifactid>jackson-module-jaxb-annotations</artifactid> </dependency> <dependency> <groupid>com.fasterxml.jackson.jaxrs</groupid> <artifactid>jackson-jaxrs-json-provider</artifactid> </dependency>
hope helps.
java json jaxb jackson
No comments:
Post a Comment