-
Notifications
You must be signed in to change notification settings - Fork 322
Add Jackson 3 support as org.msgpack.jackson3:jackson-dataformat-msgpack #1012
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
9b818d3
531d3d0
7b7dd8a
4f6851a
8ac72a7
ac96122
aa8cbfc
3b3ea6a
98e90f5
32d1c71
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -115,10 +115,22 @@ val buildSettings = Seq[Setting[?]]( | |||
| Test / compile := Def.uncached((Test / compile).dependsOn(Test / jcheckStyle).value) | ||||
| ) | ||||
|
|
||||
| val junitJupiter = "org.junit.jupiter" % "junit-jupiter" % "5.14.4" % "test" | ||||
| val junitVintage = "org.junit.vintage" % "junit-vintage-engine" % "5.14.4" % "test" | ||||
| val junitJupiter = "org.junit.jupiter" % "junit-jupiter" % "5.14.4" % "test" | ||||
| val junitVintage = "org.junit.vintage" % "junit-vintage-engine" % "5.14.4" % "test" | ||||
| val junitInterface = "com.github.sbt" % "junit-interface" % "0.13.3" % "test" | ||||
|
|
||||
| // Project settings | ||||
| val isJava17Plus: Boolean = { | ||||
| val v = sys.props.getOrElse("java.specification.version", "1.8") | ||||
| // getOrElse(false): non-numeric versions (e.g. early-access "17-ea") fail safe | ||||
| // by not compiling the Jackson 3 module (msgpack-jackson) rather than making an | ||||
| // optimistic guess. | ||||
| if (v.startsWith("1.")) | ||||
| false | ||||
| else | ||||
| scala.util.Try(v.toInt >= 17).getOrElse(false) | ||||
| } | ||||
|
|
||||
| lazy val root = Project(id = "msgpack-java", base = file(".")) | ||||
| .settings( | ||||
| buildSettings, | ||||
|
|
@@ -127,7 +139,14 @@ lazy val root = Project(id = "msgpack-java", base = file(".")) | |||
| publish := {}, | ||||
| publishLocal := {} | ||||
| ) | ||||
| .aggregate(msgpackCore, msgpackJackson) | ||||
| .aggregate( | ||||
| Seq[ProjectReference](msgpackCore, msgpackJackson) ++ ( | ||||
| if (isJava17Plus) | ||||
| Seq[ProjectReference](msgpackJackson3, msgpackJackson3Benchmark) | ||||
| else | ||||
| Nil | ||||
| ): _* | ||||
| ) | ||||
|
|
||||
| lazy val msgpackCore = Project(id = "msgpack-core", base = file("msgpack-core")) | ||||
| .enablePlugins(SbtOsgi) | ||||
|
|
@@ -170,21 +189,72 @@ lazy val msgpackCore = Project(id = "msgpack-core", base = file("msgpack-core")) | |||
| ) | ||||
| ) | ||||
|
|
||||
| // Jackson 2.x module. Keeps the same Maven coordinates (org.msgpack:jackson-dataformat-msgpack) | ||||
| // and Java package as the 0.9.x line, so existing Jackson 2.x users need no changes. | ||||
| // Maintenance mode: Jackson 2.x dependency bumps and bug fixes only. | ||||
| lazy val msgpackJackson = Project(id = "msgpack-jackson", base = file("msgpack-jackson")) | ||||
| .enablePlugins(SbtOsgi) | ||||
| .settings( | ||||
| buildSettings, | ||||
| name := "jackson-dataformat-msgpack", | ||||
| description := "Jackson extension that adds support for MessagePack", | ||||
| description := "Jackson 2.x extension that adds support for MessagePack", | ||||
| OsgiKeys.bundleSymbolicName := "org.msgpack.msgpack-jackson", | ||||
| OsgiKeys.exportPackage := Seq("org.msgpack.jackson", "org.msgpack.jackson.dataformat"), | ||||
| libraryDependencies ++= | ||||
| Seq( | ||||
| "com.fasterxml.jackson.core" % "jackson-databind" % "2.22.1", | ||||
| junitJupiter, | ||||
| junitVintage, | ||||
| "org.apache.commons" % "commons-math3" % "3.6.1" % "test" | ||||
| "com.github.sbt.junit" % "jupiter-interface" % JupiterKeys.jupiterVersion.value % "test", | ||||
| "org.apache.commons" % "commons-math3" % "3.6.1" % "test" | ||||
| ), | ||||
| testOptions += Tests.Argument(TestFrameworks.JUnit, "-v") | ||||
| ) | ||||
| .dependsOn(msgpackCore) | ||||
|
|
||||
| // Jackson 3.x module. Published under a new groupId (org.msgpack.jackson3) with a new | ||||
| // Java package (org.msgpack.jackson3.dataformat), following JLBP-6: the Maven coordinates | ||||
| // and the Java package are renamed together, so this artifact can coexist on the same | ||||
| // classpath with the Jackson 2.x artifact (org.msgpack:jackson-dataformat-msgpack). | ||||
| lazy val msgpackJackson3 = Project(id = "msgpack-jackson3", base = file("msgpack-jackson3")) | ||||
| .enablePlugins(SbtOsgi) | ||||
| .settings( | ||||
| buildSettings, | ||||
| organization := "org.msgpack.jackson3", | ||||
| name := "jackson-dataformat-msgpack", | ||||
| // sbt derives build output paths from moduleName, which would collide with the | ||||
| // Jackson 2 module publishing the same artifactId; use the project id instead | ||||
| outputPath := s"${platform.value}/u/msgpack-jackson3", | ||||
| description := "Jackson 3.x extension that adds support for MessagePack", | ||||
| OsgiKeys.bundleSymbolicName := "org.msgpack.jackson3.jackson-dataformat-msgpack", | ||||
| OsgiKeys.exportPackage := Seq("org.msgpack.jackson3", "org.msgpack.jackson3.dataformat"), | ||||
| OsgiKeys.importPackage := Seq("!android.os", "!sun.*"), | ||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bnd drops any referenced package that matches nothing in this list, so with only exclusions the bundle gets no
Suggested change
|
||||
| Test / fork := true, | ||||
| javacOptions := Seq("--release", "17"), | ||||
| doc / javacOptions := Seq("--release", "17", "-Xdoclint:none"), | ||||
| libraryDependencies ++= | ||||
| Seq("tools.jackson.core" % "jackson-databind" % "3.1.2", junitInterface), | ||||
| testOptions += Tests.Argument(TestFrameworks.JUnit, "-v") | ||||
| ) | ||||
| .dependsOn(msgpackCore) | ||||
|
|
||||
| // JMH benchmarks for the Jackson 3.x module. Kept in a separate, unpublished project as | ||||
| // sbt-jmh recommends: JmhPlugin adds jmh-core and the code generators to | ||||
| // libraryDependencies unscoped, so enabling it on a published module would leak them into | ||||
| // that module's POM as compile dependencies of every consumer. | ||||
| lazy val msgpackJackson3Benchmark = Project( | ||||
| id = "msgpack-jackson3-benchmark", | ||||
| base = file("msgpack-jackson3-benchmark") | ||||
| ).enablePlugins(JmhPlugin) | ||||
| .settings( | ||||
| buildSettings, | ||||
| description := "JMH benchmarks for the Jackson 3.x MessagePack integration", | ||||
| publish / skip := true, | ||||
| javacOptions := Seq("--release", "17"), | ||||
| Jmh / javaOptions ++= | ||||
| Seq( | ||||
| "--add-opens=java.base/java.nio=ALL-UNNAMED", | ||||
| "--add-opens=java.base/sun.nio.ch=ALL-UNNAMED" | ||||
| ) | ||||
| ) | ||||
| .dependsOn(msgpackJackson3) | ||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| // | ||
| // MessagePack for Java | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| // | ||
| package org.msgpack.jackson3.dataformat.benchmark; | ||
|
|
||
| import org.msgpack.jackson3.dataformat.MessagePackFactory; | ||
| import org.msgpack.jackson3.dataformat.MessagePackMapper; | ||
| import org.msgpack.jackson3.dataformat.benchmark.model.MediaItem; | ||
| import org.msgpack.jackson3.dataformat.benchmark.model.MediaItems; | ||
| import org.openjdk.jmh.annotations.Scope; | ||
| import org.openjdk.jmh.annotations.State; | ||
| import tools.jackson.databind.ObjectMapper; | ||
| import tools.jackson.databind.json.JsonMapper; | ||
|
|
||
| @State(Scope.Thread) | ||
| public class BenchmarkState | ||
| { | ||
| public final ObjectMapper msgpackMapper = MessagePackMapper.builder(new MessagePackFactory()).build(); | ||
| public final ObjectMapper jsonMapper = JsonMapper.builder().build(); | ||
|
|
||
| public final byte[] msgpackBytes; | ||
| public final byte[] jsonBytes; | ||
|
|
||
| public BenchmarkState() | ||
| { | ||
| try { | ||
| MediaItem item = MediaItems.stdMediaItem(); | ||
| msgpackBytes = msgpackMapper.writeValueAsBytes(item); | ||
| jsonBytes = jsonMapper.writeValueAsBytes(item); | ||
| } | ||
| catch (Exception e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| // | ||
| // MessagePack for Java | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| // | ||
| package org.msgpack.jackson3.dataformat.benchmark; | ||
|
|
||
| import org.msgpack.jackson3.dataformat.benchmark.model.MediaItem; | ||
| import org.openjdk.jmh.annotations.Benchmark; | ||
| import org.openjdk.jmh.annotations.BenchmarkMode; | ||
| import org.openjdk.jmh.annotations.Fork; | ||
| import org.openjdk.jmh.annotations.Measurement; | ||
| import org.openjdk.jmh.annotations.Mode; | ||
| import org.openjdk.jmh.annotations.OutputTimeUnit; | ||
| import org.openjdk.jmh.annotations.Scope; | ||
| import org.openjdk.jmh.annotations.State; | ||
| import org.openjdk.jmh.annotations.Warmup; | ||
|
|
||
| import java.util.concurrent.TimeUnit; | ||
|
|
||
| @BenchmarkMode(Mode.Throughput) | ||
| @OutputTimeUnit(TimeUnit.SECONDS) | ||
| @State(Scope.Thread) | ||
| @Fork(2) | ||
| @Warmup(iterations = 5, time = 1) | ||
| @Measurement(iterations = 5, time = 1) | ||
| public class MsgpackReadBenchmark | ||
| { | ||
| private final BenchmarkState state = new BenchmarkState(); | ||
|
|
||
| @Benchmark | ||
| public Object readPojoMsgpack() throws Exception | ||
| { | ||
| return state.msgpackMapper.readValue(state.msgpackBytes, MediaItem.class); | ||
| } | ||
|
|
||
| @Benchmark | ||
| public Object readPojoJson() throws Exception | ||
| { | ||
| return state.jsonMapper.readValue(state.jsonBytes, MediaItem.class); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is meant to skip
msgpack-jackson3, which compiles with--release 17, when the target JDK is older. Butjava.specification.versionis the JDK running sbt, not the one compiling. Since #998 those are two different JDKs wheneverTEST_JAVA_HOMEis set, and sbt 2 requires its own to be 17+, so this is always true and the module is never skipped.Before #998 there was no
TEST_JAVA_HOMEand one JDK did both, so it worked.TEST_JAVA_HOME=<jdk8> ./sbt clean compilefails withjavac: invalid flag: --release. Thecleanmatters, stale classes hide it.Minor: the comment says "the Jackson 3 module (msgpack-jackson)", which is the Jackson 2 module now.