This is an automated email from the ASF dual-hosted git repository. cziegeler pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-johnzon.git
The following commit(s) were added to refs/heads/master by this push: new 7c7db8e SLING-12182 : Provide wrapper for Apache Johnzon 2.0 7c7db8e is described below commit 7c7db8e0a89597c4ce7820f9166a0383a3af32df Author: Carsten Ziegeler <cziege...@apache.org> AuthorDate: Wed Dec 6 10:39:44 2023 +0100 SLING-12182 : Provide wrapper for Apache Johnzon 2.0 --- .gitignore | 1 + README.md | 2 +- pom.xml | 33 +-- .../{javax => jakarta}/json/spi/JsonProvider.java | 235 ++++++--------------- 4 files changed, 69 insertions(+), 202 deletions(-) diff --git a/.gitignore b/.gitignore index 5b783ed..f1ae2e6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ /target .idea +.vscode .classpath .metadata .project diff --git a/README.md b/README.md index f3d6e74..1403613 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ This module is part of the [Apache Sling](https://sling.apache.org) project. -[Apache Johnzon](https://johnzon.apache.org/) powered javax.json library. +[Apache Johnzon](https://johnzon.apache.org/) powered jakarta.json library. This wrapper allows to use [JSON-P 1.1](https://jcp.org/aboutJava/communityprocess/pr/jsr374/index.html) with Apache Johnzon in an OSGi container without requiring an OSGi ServiceLoader Mediator implementation like [SPI Fly](https://aries.apache.org/modules/spi-fly.html) by overwriting the [JSONProvider](https://github.com/apache/sling-org-apache-sling-commons-johnzon/blob/master/src/main/java/javax/json/spi/JsonProvider.java) to always load Apache Johnzon and not relying on the Service Loader. diff --git a/pom.xml b/pom.xml index 98bf55e..0ce30fd 100644 --- a/pom.xml +++ b/pom.xml @@ -15,15 +15,15 @@ <parent> <groupId>org.apache.sling</groupId> <artifactId>sling-bundle-parent</artifactId> - <version>51</version> + <version>52</version> <relativePath /> </parent> <artifactId>org.apache.sling.commons.johnzon</artifactId> - <version>1.2.17-SNAPSHOT</version> + <version>2.0.0-SNAPSHOT</version> <name>Apache Sling Commons Johnzon Wrapper Library</name> - <description>Apache Johnzon powered javax.json library</description> + <description>Apache Johnzon powered jakarta.json library</description> <properties> <sling.java.version>8</sling.java.version> @@ -47,44 +47,27 @@ <id>bnd-process</id> <configuration> <bnd><![CDATA[ -Export-Package: javax.json.*;-split-package:=first,org.apache.johnzon.core.* +Export-Package: jakarta.json.*;-split-package:=first,org.apache.johnzon.core.* Import-Package: -# Taken over from the embedded geronimo-json_1.1_spec -Provide-Capability: osgi.contract;osgi.contract=JavaJSONP;uses:="javax.json,javax.json.spi,javax.json.stream";version:List<Version>="1.1,1.0" ]]></bnd> </configuration> </execution> </executions> </plugin> - <plugin> - <groupId>biz.aQute.bnd</groupId> - <artifactId>bnd-baseline-maven-plugin</artifactId> - <configuration> - <skip>true</skip> - </configuration> - </plugin> - <plugin> - <groupId>org.apache.rat</groupId> - <artifactId>apache-rat-plugin</artifactId> - <configuration> - <excludes> - </excludes> - </configuration> - </plugin> </plugins> </build> <dependencies> <dependency> - <groupId>org.apache.geronimo.specs</groupId> - <artifactId>geronimo-json_1.1_spec</artifactId> - <version>1.3</version> + <groupId>jakarta.json</groupId> + <artifactId>jakarta.json-api</artifactId> + <version>2.1.1</version> <scope>provided</scope><!-- due to https://github.com/bndtools/bnd/issues/3843 --> </dependency> <dependency> <groupId>org.apache.johnzon</groupId> <artifactId>johnzon-core</artifactId> - <version>1.2.21</version> + <version>2.0.0</version> <scope>provided</scope> </dependency> <!-- OSGi annotations (OSGi R7) --> diff --git a/src/main/java/javax/json/spi/JsonProvider.java b/src/main/java/jakarta/json/spi/JsonProvider.java similarity index 50% rename from src/main/java/javax/json/spi/JsonProvider.java rename to src/main/java/jakarta/json/spi/JsonProvider.java index 430a788..c702b63 100644 --- a/src/main/java/javax/json/spi/JsonProvider.java +++ b/src/main/java/jakarta/json/spi/JsonProvider.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package javax.json.spi; +package jakarta.json.spi; import java.io.InputStream; import java.io.OutputStream; @@ -26,28 +26,27 @@ import java.math.BigDecimal; import java.math.BigInteger; import java.util.Collection; import java.util.Map; - -import javax.json.JsonArray; -import javax.json.JsonArrayBuilder; -import javax.json.JsonBuilderFactory; -import javax.json.JsonMergePatch; -import javax.json.JsonNumber; -import javax.json.JsonObject; -import javax.json.JsonObjectBuilder; -import javax.json.JsonPatch; -import javax.json.JsonPatchBuilder; -import javax.json.JsonPointer; -import javax.json.JsonReader; -import javax.json.JsonReaderFactory; -import javax.json.JsonString; -import javax.json.JsonStructure; -import javax.json.JsonValue; -import javax.json.JsonWriter; -import javax.json.JsonWriterFactory; -import javax.json.stream.JsonGenerator; -import javax.json.stream.JsonGeneratorFactory; -import javax.json.stream.JsonParser; -import javax.json.stream.JsonParserFactory; +import jakarta.json.JsonArray; +import jakarta.json.JsonArrayBuilder; +import jakarta.json.JsonBuilderFactory; +import jakarta.json.JsonMergePatch; +import jakarta.json.JsonNumber; +import jakarta.json.JsonObject; +import jakarta.json.JsonObjectBuilder; +import jakarta.json.JsonPatch; +import jakarta.json.JsonPatchBuilder; +import jakarta.json.JsonPointer; +import jakarta.json.JsonReader; +import jakarta.json.JsonReaderFactory; +import jakarta.json.JsonString; +import jakarta.json.JsonStructure; +import jakarta.json.JsonValue; +import jakarta.json.JsonWriter; +import jakarta.json.JsonWriterFactory; +import jakarta.json.stream.JsonGenerator; +import jakarta.json.stream.JsonGeneratorFactory; +import jakarta.json.stream.JsonParser; +import jakarta.json.stream.JsonParserFactory; import org.osgi.annotation.versioning.ProviderType; @@ -85,214 +84,98 @@ public abstract class JsonProvider { public abstract JsonWriter createWriter(OutputStream out); - public abstract JsonWriterFactory createWriterFactory(Map<String, ?> config); + public abstract JsonWriterFactory createWriterFactory(Map<String,?> config); - public abstract JsonReaderFactory createReaderFactory(Map<String, ?> config); + public abstract JsonReaderFactory createReaderFactory(Map<String,?> config); - /** - * Create an empty JsonObjectBuilder - * @since 1.0 - */ public abstract JsonObjectBuilder createObjectBuilder(); - /** - * Creates a JSON object builder, initialized with the specified JsonObject. - * @since 1.1 - */ - public JsonObjectBuilder createObjectBuilder(JsonObject jsonObject) { + public JsonObjectBuilder createObjectBuilder(JsonObject object) { throw new UnsupportedOperationException(); } - /** - * Creates a JSON object builder, initialized with the specified Map. - * @since 1.1 - */ - public JsonObjectBuilder createObjectBuilder(Map<String, Object> map) { + public JsonObjectBuilder createObjectBuilder(Map<String, ?> map) { throw new UnsupportedOperationException(); } public abstract JsonArrayBuilder createArrayBuilder(); - public JsonArrayBuilder createArrayBuilder(JsonArray initialData) { + public JsonArrayBuilder createArrayBuilder(JsonArray array) { throw new UnsupportedOperationException(); } - public JsonArrayBuilder createArrayBuilder(Collection<?> initialData) { + public JsonPointer createPointer(String jsonPointer) { throw new UnsupportedOperationException(); } - /** - * Create a {@link JsonPointer} based on the given path string - * - * @since 1.1 - */ - public JsonPointer createPointer(String path) { + public JsonPatchBuilder createPatchBuilder() { throw new UnsupportedOperationException(); } - public abstract JsonBuilderFactory createBuilderFactory(Map<String, ?> config); - - - public JsonString createValue(String value) { + public JsonPatchBuilder createPatchBuilder(JsonArray array) { throw new UnsupportedOperationException(); } - public JsonNumber createValue(int value) { + public JsonPatch createPatch(JsonArray array) { throw new UnsupportedOperationException(); } - public JsonNumber createValue(long value) { + public JsonPatch createDiff(JsonStructure source, JsonStructure target) { throw new UnsupportedOperationException(); } - public JsonNumber createValue(double value) { + public JsonMergePatch createMergePatch(JsonValue patch) { throw new UnsupportedOperationException(); } - public JsonNumber createValue(BigDecimal value) { + public JsonMergePatch createMergeDiff(JsonValue source, JsonValue target) { throw new UnsupportedOperationException(); } - public JsonNumber createValue(BigInteger value) { + public JsonArrayBuilder createArrayBuilder(Collection<?> collection) { throw new UnsupportedOperationException(); } - /** - * Create a {@link JsonPatch} as defined in - * <a href="https://tools.ietf.org/html/rfc6902">RFC-6902</a>. - * - * @param array with the patch operations - * @return the JsonPatch based on the given operations - * - * @see #createDiff(JsonStructure, JsonStructure) - * - * @since 1.1 - */ - public JsonPatch createPatch(JsonArray array) { + public abstract JsonBuilderFactory createBuilderFactory(Map<String,?> config); + + public JsonString createValue(String value) { throw new UnsupportedOperationException(); } - /** - * Create a {@link JsonPatch} by comparing the source to the target as defined in - * <a href="https://tools.ietf.org/html/rfc6902">RFC-6902</a>. - * - * Applying this {@link JsonPatch} to the source you will give you the target. - * - * @see #createPatch(JsonArray) - * - * @since 1.1 - */ - public JsonPatch createDiff(JsonStructure source, JsonStructure target) { + public JsonNumber createValue(int value) { throw new UnsupportedOperationException(); } - /** - * Create a new JsonPatchBuilder - * @since 1.1 - */ - public JsonPatchBuilder createPatchBuilder() { + public JsonNumber createValue(long value) { throw new UnsupportedOperationException(); } - /** - * Create a new JsonPatchBuilder from initial data. - * @param initialData the initial patch operations - * @since 1.1 - */ - public JsonPatchBuilder createPatchBuilder(JsonArray initialData) { + public JsonNumber createValue(double value) { throw new UnsupportedOperationException(); } - /** - * Create a merge patch based on the given JsonValue. - * - * If you have the following JsonMergePatch: - * - * <pre> - * { - * "a":"z", - * "c": { - * "f": null - * } - * } - * </pre> - * - * and apply it to the following JSON - * - * <pre> - * { - * "a": "b", - * "c": { - * "d": "e", - * "f": "g" - * } - * } - * </pre> - * - * you will get the following result: - * - * <pre> - * { - * "a": "z", - * "c": { - * "d": "e", - * } - * } - * </pre> - * - * @see #createMergeDiff(JsonValue, JsonValue) - * - * @since 1.1 - */ - public JsonMergePatch createMergePatch(JsonValue patch) { + public JsonNumber createValue(BigDecimal value) { throw new UnsupportedOperationException(); } - - /** - * Create a merge patch by comparing the source to the target. - * Applying this JsonMergePatch to the source will give you the target. - * A MergePatch is a JsonValue as defined in http://tools.ietf.org/html/rfc7396 - * - * If you have a JSON like - * <pre> - * { - * "a": "b", - * "c": { - * "d": "e", - * "f": "g" - * } - * } - * </pre> - * - * and comparing it with - * - * <pre> - * { - * "a": "z", - * "c": { - * "d": "e", - * } - * } - * </pre> - * - * you will get the following JsonMergePatch: - * - * <pre> - * { - * "a":"z", - * "c": { - * "f": null - * } - * } - * </pre> - * - * @see #createMergePatch(JsonValue) - * - * @since 1.1 - */ - public JsonMergePatch createMergeDiff(JsonValue source, JsonValue target) { + public JsonNumber createValue(BigInteger value) { throw new UnsupportedOperationException(); } + + public JsonNumber createValue(Number number) { + if (number instanceof Integer) { + return createValue(number.intValue()); + } else if (number instanceof Long) { + return createValue(number.longValue()); + } else if (number instanceof Double) { + return createValue(number.doubleValue()); + } else if (number instanceof BigInteger) { + return createValue((BigInteger) number); + } else if (number instanceof BigDecimal) { + return createValue((BigDecimal) number); + } else { + throw new UnsupportedOperationException(number + " type is not known"); + } + } }