admin管理员组文章数量:1122846
I have a very simple REST app using JAX-RS, Tomcat 11, and Weld for CDI. It is pretty straightforward with only the following (ie no web.xml
or context.xml
):
- Class which extends
jakarta.ws.rs.core.Application
- Class with
@Path
and other associated annotations for the endpoints beans.xml
andpersistence.xml
(though not using JPA yet)- I'm using
org.jboss.weld.se:weld-se-core
v6.0.0.Beta4 for CDI.
In the class that defines the endpoints, I want to return an object that has a ZonedDateTime
field. I followed the directions to findAndAddModules()
in a @Produces
class:
@ApplicationScoped
public class SerializerConfig {
private static final Logger logger = Logger.getLogger(SerializerConfig.class.getName());
@Produces
public JsonMapper objectMapper() {
logger.info("PROVIDING!!!");
return JsonMapper.builder()
.findAndAddModules()
.build();
}
}
This class is never called (don't see "PROVIDING!!!" in my logs) when I simply return Response.ok(obj_with_date_time).build();
.
How can I get Weld to provider my instance of JsonMapper
to whatever Jersey code is called when returning Response.ok(obj_with_date_time).build();
?
My provider is called if I specifically @Inject
JsonMapper
as a field in my class, and manually perform the serialization: jsonMapper.writeValueAsString(obj_with_date_time);
本文标签: jerseyHow do you provide an ObjectMapper (or JsonMapper) in tomcat 11Stack Overflow
版权声明:本文标题:jersey - How do you provide an ObjectMapper (or JsonMapper) in tomcat 11 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736310192a1934287.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论