jackson-core: Jackson bundles are missing OSGi's osgi.serviceloader metadata

Bundles need to include extra metadata to support java.util.ServiceLoader inside an OSGi framework. Jackson’s bundles are all missing this metadata.

In theory, it should just be a matter of applying Bnd’s @ServiceConsumer and @ServiceProvider annotations in the correct places as described here, where these annotations can be provided like this:

diff --git a/base/pom.xml b/base/pom.xml
index 6235a67..4972957 100644
--- a/base/pom.xml
+++ b/base/pom.xml
@@ -30,9 +30,17 @@ of Jackson: application code should only rely on `jackson-bom`
          parent pom, and then also allow override as need be
       -->
     <jackson-bom.version>${project.parent.version}</jackson-bom.version>
+
+    <version.bnd.annotation>6.3.1</version.bnd.annotation>
   </properties>
 
   <dependencies>
+    <dependency>
+      <groupId>biz.aQute.bnd</groupId>
+      <artifactId>biz.aQute.bnd.annotation</artifactId>
+      <version>${version.bnd.annotation}</version>
+      <scope>provided</scope>
+    </dependency>
     <dependency> <!-- all components use junit for testing -->
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>

I am struggling to wrap my head around your myriad of separate repositories, and so you may have a better way of providing this dependency.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 22 (18 by maintainers)

Commits related to this issue

Most upvoted comments

Ok good, thank you for confirming @rakeshk15.

This change will require the Aries SPIFly bundle and the jackson-core bundle will not resolve wherever Aries SPIFly bundle is missing.

The solution to that is to make the requirement optional, as has already been done with Woodstox. I’m sorry, I thought we already knew this?

So what would be the meaning of ServiceLoader for this particular component? (or for others, jackson-databind) It sounds like there is a problem to solve, I just want to understand what that is.

jackson-core contains META-INF/services/com.fasterxml.jackson.core.JsonFactory, which means that it “provides” the classes inside this file as ServiceLoader “services”. As a rule, the classes listed inside META-INF/services/* files need to be annotated as @ServiceProvider, and classes which directly invoke ServiceLoader.load(...) need to be annotated as @ServiceConsumer. These annotations instruct the Maven plugin to generate extra OSGi metadata inside the bundles, which can be used by OSGi’s Service Loader Mediator

The story becomes more complicated with jackson-databind because e.g. jackson-databind-xml uses XMLInputFactory.newFactory() etc which use ServiceLoader.load(...) indirectly. The Apache Aries SPI-Fly bundle supports extra OSGi metadata for cases like these. I know there is an issue with at least jackson-databind-xml and woodstox-core because I have tripped over it.