This is an automated email from the ASF dual-hosted git repository.
jlmonteiro pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/johnzon.git
The following commit(s) were added to refs/heads/master by this push:
new d8357f8c JOHNZON-394 Make Johnzon JSON Pointer compatible by default
d8357f8c is described below
commit d8357f8c8b28b3ac563350f21c4fe472aee2b476
Author: Jean-Louis Monteiro <[email protected]>
AuthorDate: Wed Jan 11 13:55:41 2023 +0100
JOHNZON-394 Make Johnzon JSON Pointer compatible by default
Signed-off-by: Jean-Louis Monteiro <[email protected]>
---
.../johnzon/core/DefaultJsonPointerFactory.java | 38 -----------
.../org/apache/johnzon/core/JsonPointerImpl.java | 12 +---
.../org/apache/johnzon/core/JsonProviderImpl.java | 16 +----
.../johnzon/core/spi/JsonPointerFactory.java | 36 -----------
.../org/apache/johnzon/core/JsonPointerTest.java | 13 ----
.../core}/StrictJsonPointerFactoryTest.java | 11 ++--
johnzon-jsonp-strict/pom.xml | 73 ----------------------
.../jsonp/strict/StrictJsonPointerFactory.java | 51 ---------------
.../org.apache.johnzon.core.spi.JsonPointerFactory | 1 -
pom.xml | 1 -
10 files changed, 9 insertions(+), 243 deletions(-)
diff --git
a/johnzon-core/src/main/java/org/apache/johnzon/core/DefaultJsonPointerFactory.java
b/johnzon-core/src/main/java/org/apache/johnzon/core/DefaultJsonPointerFactory.java
deleted file mode 100644
index e2991345..00000000
---
a/johnzon-core/src/main/java/org/apache/johnzon/core/DefaultJsonPointerFactory.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.apache.johnzon.core;
-
-import org.apache.johnzon.core.spi.JsonPointerFactory;
-
-import jakarta.json.JsonPointer;
-import jakarta.json.spi.JsonProvider;
-
-/**
- * This is not a standard factory but allows Johnzon to support an extended
version of JSon Pointer.
- * By default, we support an extended usage of /- when used with
replace/remove/get. But in the johnzon-jsonp-strict
- * module, it's overridden so we can pass the JSONP TCK in standalone
environments or TomEE or else.
- */
-public class DefaultJsonPointerFactory implements JsonPointerFactory {
-
- @Override
- public JsonPointer createPointer(final JsonProvider provider, final String
path) {
- return new JsonPointerImpl(provider, path);
- }
-
-}
diff --git
a/johnzon-core/src/main/java/org/apache/johnzon/core/JsonPointerImpl.java
b/johnzon-core/src/main/java/org/apache/johnzon/core/JsonPointerImpl.java
index b55ec8dc..57912d0b 100644
--- a/johnzon-core/src/main/java/org/apache/johnzon/core/JsonPointerImpl.java
+++ b/johnzon-core/src/main/java/org/apache/johnzon/core/JsonPointerImpl.java
@@ -476,7 +476,7 @@ public class JsonPointerImpl implements JsonPointer {
return jsonArray.size();
} else if (!addOperation && referenceToken.equals("-")) {
- final int arrayIndex = jsonArray.size() - minusShift();
+ final int arrayIndex = jsonArray.size();
validateArraySize(referenceToken, jsonArray, arrayIndex,
jsonArray.size());
return arrayIndex;
}
@@ -493,16 +493,6 @@ public class JsonPointerImpl implements JsonPointer {
}
}
- /**
- * This method can be overridden in sub classes.
- * It's main goal is to support patch operation using "-" to replace,
remove last element which is forbidden in JsonPointer
- *
- * @return the shift to apply on minus. For backward compatibility it's 1.
We can have a strict JSONP compliancy with the dedicated module.
- */
- protected int minusShift() {
- return 1;
- }
-
private void validateJsonPointer(JsonValue target, int size) throws
NullPointerException, JsonException {
if (target == null) {
throw new NullPointerException("target must not be null");
diff --git
a/johnzon-core/src/main/java/org/apache/johnzon/core/JsonProviderImpl.java
b/johnzon-core/src/main/java/org/apache/johnzon/core/JsonProviderImpl.java
index 317dbbf5..dc664fe1 100644
--- a/johnzon-core/src/main/java/org/apache/johnzon/core/JsonProviderImpl.java
+++ b/johnzon-core/src/main/java/org/apache/johnzon/core/JsonProviderImpl.java
@@ -18,8 +18,6 @@
*/
package org.apache.johnzon.core;
-import org.apache.johnzon.core.spi.JsonPointerFactory;
-
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Reader;
@@ -29,9 +27,7 @@ import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Collection;
import java.util.Map;
-import java.util.ServiceLoader;
import java.util.function.Supplier;
-import java.util.stream.StreamSupport;
import jakarta.json.JsonArray;
import jakarta.json.JsonArrayBuilder;
@@ -56,8 +52,6 @@ import jakarta.json.stream.JsonGeneratorFactory;
import jakarta.json.stream.JsonParser;
import jakarta.json.stream.JsonParserFactory;
-import static java.util.Comparator.comparing;
-
public class JsonProviderImpl extends JsonProvider implements Serializable {
private final Supplier<BufferStrategy.BufferProvider<char[]>>
bufferProvider = new Cached<>(() ->
BufferStrategyFactory.valueOf(System.getProperty(AbstractJsonFactory.BUFFER_STRATEGY,
"QUEUE"))
@@ -69,14 +63,6 @@ public class JsonProviderImpl extends JsonProvider
implements Serializable {
private final JsonWriterFactory writerFactory = new
JsonWriterFactoryImpl(null);
private final Supplier<JsonBuilderFactory> builderFactory = new
Cached<>(() ->
new JsonBuilderFactoryImpl(null, bufferProvider.get(),
RejectDuplicateKeysMode.DEFAULT));
- private final JsonPointerFactory jsonPointerFactory;
-
- public JsonProviderImpl() {
- jsonPointerFactory =
StreamSupport.stream(ServiceLoader.load(JsonPointerFactory.class).spliterator(),
false)
- .min(comparing(JsonPointerFactory::ordinal))
- .orElseGet(DefaultJsonPointerFactory::new);
- }
-
@Override
public JsonParser createParser(final InputStream in) {
return parserFactory.createParser(in);
@@ -216,7 +202,7 @@ public class JsonProviderImpl extends JsonProvider
implements Serializable {
@Override
public JsonPointer createPointer(String path) {
- return jsonPointerFactory.createPointer(this, path);
+ return new JsonPointerImpl(this, path);
}
@Override
diff --git
a/johnzon-core/src/main/java/org/apache/johnzon/core/spi/JsonPointerFactory.java
b/johnzon-core/src/main/java/org/apache/johnzon/core/spi/JsonPointerFactory.java
deleted file mode 100644
index 0b62f4ed..00000000
---
a/johnzon-core/src/main/java/org/apache/johnzon/core/spi/JsonPointerFactory.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.apache.johnzon.core.spi;
-
-import jakarta.json.JsonPointer;
-import jakarta.json.spi.JsonProvider;
-
-/**
- * Factory to create JsonPointer instances. We have a default one in Johnzon,
but the aim is tom being able to
- * override it in some edge cases. It uses a usual service loader mechanism to
load and sort the factories using
- * the ordinal.
- */
-public interface JsonPointerFactory {
-
- JsonPointer createPointer(JsonProvider provider, String path);
-
- default int ordinal() {
- return 0;
- }
-}
diff --git
a/johnzon-core/src/test/java/org/apache/johnzon/core/JsonPointerTest.java
b/johnzon-core/src/test/java/org/apache/johnzon/core/JsonPointerTest.java
index 1c75e8c7..ca9e7049 100644
--- a/johnzon-core/src/test/java/org/apache/johnzon/core/JsonPointerTest.java
+++ b/johnzon-core/src/test/java/org/apache/johnzon/core/JsonPointerTest.java
@@ -506,19 +506,6 @@ public class JsonPointerTest {
assertEquals("[[\"bar\",\"qux\",\"baz\",\"xyz\"]]", result.toString());
}
- @Test
- public void testRemoveLastArrayElementSimpleWithPatch() {
- JsonPointerImpl jsonPointer = new
JsonPointerImpl(JsonProvider.provider(), "/-");
- JsonStructure target = Json.createArrayBuilder()
- .add("bar")
- .add("qux")
- .add("baz")
- .build();
-
- JsonStructure result = jsonPointer.remove(target);
- assertEquals("[\"bar\",\"qux\"]", result.toString());
- }
-
@Test(expected = JsonException.class)
public void testRemoveLastArrayElementFromEmptySimple() {
final JsonPointerImpl jsonPointer = new
JsonPointerImpl(JsonProvider.provider(), "/-");
diff --git
a/johnzon-jsonp-strict/src/test/java/org/apache/johnzon/jsonp/strict/StrictJsonPointerFactoryTest.java
b/johnzon-core/src/test/java/org/apache/johnzon/core/StrictJsonPointerFactoryTest.java
similarity index 94%
rename from
johnzon-jsonp-strict/src/test/java/org/apache/johnzon/jsonp/strict/StrictJsonPointerFactoryTest.java
rename to
johnzon-core/src/test/java/org/apache/johnzon/core/StrictJsonPointerFactoryTest.java
index 37feedb2..a3e5597d 100644
---
a/johnzon-jsonp-strict/src/test/java/org/apache/johnzon/jsonp/strict/StrictJsonPointerFactoryTest.java
+++
b/johnzon-core/src/test/java/org/apache/johnzon/core/StrictJsonPointerFactoryTest.java
@@ -16,19 +16,22 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.johnzon.jsonp.strict;
-
-import org.apache.johnzon.core.JsonPointerImpl;
-import org.junit.Test;
+package org.apache.johnzon.core;
import jakarta.json.Json;
import jakarta.json.JsonException;
import jakarta.json.JsonPointer;
import jakarta.json.JsonStructure;
import jakarta.json.spi.JsonProvider;
+import org.junit.Test;
import static org.junit.Assert.assertEquals;
+/**
+ * This test class was originally located in the johnzon-jsonp-strict module
to bring full JSON Pointer
+ * compatibility. Since in version 2.0 it's the default in Johnzon to be
compliant, this test migrated to core
+ * as it does provide some interesting code coverage
+ */
public class StrictJsonPointerFactoryTest {
@Test
public void validMinusUsage() {
diff --git a/johnzon-jsonp-strict/pom.xml b/johnzon-jsonp-strict/pom.xml
deleted file mode 100644
index 10b11d36..00000000
--- a/johnzon-jsonp-strict/pom.xml
+++ /dev/null
@@ -1,73 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you 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.
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <parent>
- <artifactId>johnzon</artifactId>
- <groupId>org.apache.johnzon</groupId>
- <version>2.0.0-SNAPSHOT</version>
- </parent>
- <modelVersion>4.0.0</modelVersion>
-
- <artifactId>johnzon-jsonp-strict</artifactId>
- <name>Johnzon :: JSON-P Strict JSON Pointer Implementation (spec
compliant)</name>
- <packaging>bundle</packaging>
-
- <properties>
-
<staging.directory>${project.parent.reporting.outputDirectory}</staging.directory>
- </properties>
-
- <dependencies>
- <dependency>
- <groupId>org.apache.johnzon</groupId>
- <artifactId>johnzon-core</artifactId>
- <version>${project.version}</version>
- </dependency>
- </dependencies>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-shade-plugin</artifactId>
- </plugin>
- <plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-bundle-plugin</artifactId>
- <configuration>
- <instructions>
- <Import-Package>
- *
- </Import-Package>
- <Require-Capability>
-
osgi.extender;filter:="(osgi.extender=osgi.serviceloader.registrar)"
- </Require-Capability>
- <_contract>
- !JavaAnnotation,
- !JavaCDI,
- !JavaJAXRS,
- JavaJSONP
- </_contract>
-
<Provide-Capability>osgi.serviceloader;osgi.serviceloader=org.apache.johnzon.core.spi.JsonPointerFactory</Provide-Capability>
- </instructions>
- </configuration>
- </plugin>
- </plugins>
- </build>
-</project>
diff --git
a/johnzon-jsonp-strict/src/main/java/org/apache/johnzon/jsonp/strict/StrictJsonPointerFactory.java
b/johnzon-jsonp-strict/src/main/java/org/apache/johnzon/jsonp/strict/StrictJsonPointerFactory.java
deleted file mode 100644
index f9b11f2d..00000000
---
a/johnzon-jsonp-strict/src/main/java/org/apache/johnzon/jsonp/strict/StrictJsonPointerFactory.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.apache.johnzon.jsonp.strict;
-
-import org.apache.johnzon.core.JsonPointerImpl;
-import org.apache.johnzon.core.spi.JsonPointerFactory;
-
-import jakarta.json.JsonPointer;
-import jakarta.json.spi.JsonProvider;
-
-/**
- * This aims at replacing the {@link
org.apache.johnzon.core.DefaultJsonPointerFactory} in order to force Johnzon
- * to comply with the specification and pass the TCK.
- */
-public class StrictJsonPointerFactory implements JsonPointerFactory {
-
- @Override
- public JsonPointer createPointer(final JsonProvider provider, final String
path) {
- return new StrictJsonPointerImpl(provider, path);
- }
-
- /**
- * This overrides the default shift and puts Johnzon into a standard
behavior to pass the TCK
- */
- private static class StrictJsonPointerImpl extends JsonPointerImpl {
- public StrictJsonPointerImpl(final JsonProvider provider, final String
path) {
- super(provider, path);
- }
-
- protected int minusShift() {
- return 0;
- }
- }
-
-}
diff --git
a/johnzon-jsonp-strict/src/main/resources/META-INF/services/org.apache.johnzon.core.spi.JsonPointerFactory
b/johnzon-jsonp-strict/src/main/resources/META-INF/services/org.apache.johnzon.core.spi.JsonPointerFactory
deleted file mode 100644
index 088626a7..00000000
---
a/johnzon-jsonp-strict/src/main/resources/META-INF/services/org.apache.johnzon.core.spi.JsonPointerFactory
+++ /dev/null
@@ -1 +0,0 @@
-org.apache.johnzon.jsonp.strict.StrictJsonPointerFactory
diff --git a/pom.xml b/pom.xml
index 9ef2aa96..521f2d10 100644
--- a/pom.xml
+++ b/pom.xml
@@ -68,7 +68,6 @@
<module>johnzon-jsonschema</module>
<module>johnzon-osgi</module>
<module>johnzon-jsonlogic</module>
- <module>johnzon-jsonp-strict</module>
</modules>
<dependencyManagement>