diff --git a/.github/workflows/dep_build_v2.yml b/.github/workflows/dep_build_v2.yml index 2f27651a..54758c09 100644 --- a/.github/workflows/dep_build_v2.yml +++ b/.github/workflows/dep_build_v2.yml @@ -19,9 +19,9 @@ jobs: env: JAVA_OPTS: "-XX:+TieredCompilation -XX:TieredStopAtLevel=1" steps: - - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - name: Set up JDK - uses: actions/setup-java@6a0805fcefea3d4657a47ac4c165951e33482018 # v4.2.2 + uses: actions/setup-java@7a6d8a8234af8eb26422e24e3006232cccaa061b # v4.6.0 with: distribution: 'temurin' java-version: ${{ matrix.java_version }} diff --git a/.github/workflows/dep_build_v3.yml b/.github/workflows/dep_build_v3.yml index 207b38f0..f4f980e1 100644 --- a/.github/workflows/dep_build_v3.yml +++ b/.github/workflows/dep_build_v3.yml @@ -15,15 +15,15 @@ jobs: strategy: fail-fast: false matrix: - java_version: ['8', '17', '21'] + java_version: ['17', '21'] env: JAVA_OPTS: "-XX:+TieredCompilation -XX:TieredStopAtLevel=1" steps: - - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 with: ref: master - name: Set up JDK - uses: actions/setup-java@6a0805fcefea3d4657a47ac4c165951e33482018 # v4.2.2 + uses: actions/setup-java@7a6d8a8234af8eb26422e24e3006232cccaa061b # v4.6.0 with: distribution: 'temurin' java-version: ${{ matrix.java_version }} diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 01b48a85..00039838 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -14,7 +14,7 @@ permissions: env: GUAVA_DEFAULT: '25.1-jre' - GUAVA_MIN: '20.0' + GUAVA_MIN: '22.0' GUAVA_MAX: '33.1.0-jre' jobs: build: @@ -32,9 +32,9 @@ jobs: env: JAVA_OPTS: "-XX:+TieredCompilation -XX:TieredStopAtLevel=1" steps: - - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - name: Set up JDK - uses: actions/setup-java@6a0805fcefea3d4657a47ac4c165951e33482018 # v4.2.2 + uses: actions/setup-java@7a6d8a8234af8eb26422e24e3006232cccaa061b # v4.6.0 with: distribution: 'temurin' java-version: ${{ matrix.java_version }} @@ -66,7 +66,7 @@ jobs: run: ./mvnw -B -q -ff -ntp test - name: Publish code coverage if: ${{ github.event_name != 'pull_request' && matrix.snapshot && endsWith(steps.projectVersion.outputs.version, '-SNAPSHOT') }} - uses: codecov/codecov-action@e28ff129e5465c2c0dcc6f003fc735cb6ae0c673 # v4.5.0 + uses: codecov/codecov-action@1e68e06f1dbfde0e4cefc87efeba9e4643565303 # v5.1.2 with: token: ${{ secrets.CODECOV_TOKEN }} file: ./target/site/jacoco/jacoco.xml diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties index 642d572c..b9b1153a 100644 --- a/.mvn/wrapper/maven-wrapper.properties +++ b/.mvn/wrapper/maven-wrapper.properties @@ -1,2 +1,18 @@ -distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip -wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar +# 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 +# +# https://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. +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip +wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.3.2/maven-wrapper-3.3.2.jar diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 6bff9862..00000000 --- a/.travis.yml +++ /dev/null @@ -1,12 +0,0 @@ -language: java - -jdk: - - openjdk8 - - openjdk11 - -branches: - only: - - "2.13" - - "master" - -script: mvn -B clean verify diff --git a/eclipse-collections/pom.xml b/eclipse-collections/pom.xml index 82db77a7..2d6322c4 100644 --- a/eclipse-collections/pom.xml +++ b/eclipse-collections/pom.xml @@ -9,7 +9,7 @@ com.fasterxml.jackson.datatype jackson-datatypes-collections - 2.18.5-SNAPSHOT + 2.19.0-SNAPSHOT jackson-datatype-eclipse-collections Jackson datatype: eclipse-collections diff --git a/eclipse-collections/src/main/java/com/fasterxml/jackson/datatype/eclipsecollections/ser/BooleanIterableSerializer.java b/eclipse-collections/src/main/java/com/fasterxml/jackson/datatype/eclipsecollections/ser/BooleanIterableSerializer.java index 4dd12d81..cbc1fa80 100644 --- a/eclipse-collections/src/main/java/com/fasterxml/jackson/datatype/eclipsecollections/ser/BooleanIterableSerializer.java +++ b/eclipse-collections/src/main/java/com/fasterxml/jackson/datatype/eclipsecollections/ser/BooleanIterableSerializer.java @@ -1,25 +1,18 @@ package com.fasterxml.jackson.datatype.eclipsecollections.ser; +import java.io.IOException; + import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.BeanProperty; -import com.fasterxml.jackson.databind.JavaType; -import com.fasterxml.jackson.databind.type.TypeFactory; -import java.io.IOException; + import org.eclipse.collections.api.BooleanIterable; import org.eclipse.collections.api.iterator.BooleanIterator; public final class BooleanIterableSerializer extends PrimitiveIterableSerializer { private static final long serialVersionUID = 1L; - private static final JavaType ELEMENT_TYPE = TypeFactory.defaultInstance().constructType(boolean.class); - public BooleanIterableSerializer(BeanProperty property, Boolean unwrapSingle) { - super(BooleanIterable.class, ELEMENT_TYPE, property, unwrapSingle); - } - - @Override - protected BooleanIterableSerializer withResolved(BeanProperty property, Boolean unwrapSingle) { - return new BooleanIterableSerializer(property, unwrapSingle); + super(BooleanIterable.class, elementType(boolean.class), property, unwrapSingle); } @Override diff --git a/eclipse-collections/src/main/java/com/fasterxml/jackson/datatype/eclipsecollections/ser/DoubleIterableSerializer.java b/eclipse-collections/src/main/java/com/fasterxml/jackson/datatype/eclipsecollections/ser/DoubleIterableSerializer.java index 1c809eed..ef828b4b 100644 --- a/eclipse-collections/src/main/java/com/fasterxml/jackson/datatype/eclipsecollections/ser/DoubleIterableSerializer.java +++ b/eclipse-collections/src/main/java/com/fasterxml/jackson/datatype/eclipsecollections/ser/DoubleIterableSerializer.java @@ -1,25 +1,18 @@ package com.fasterxml.jackson.datatype.eclipsecollections.ser; +import java.io.IOException; + import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.BeanProperty; -import com.fasterxml.jackson.databind.JavaType; -import com.fasterxml.jackson.databind.type.TypeFactory; -import java.io.IOException; + import org.eclipse.collections.api.DoubleIterable; import org.eclipse.collections.api.iterator.DoubleIterator; public final class DoubleIterableSerializer extends PrimitiveIterableSerializer { private static final long serialVersionUID = 1L; - private static final JavaType ELEMENT_TYPE = TypeFactory.defaultInstance().constructType(double.class); - public DoubleIterableSerializer(BeanProperty property, Boolean unwrapSingle) { - super(DoubleIterable.class, ELEMENT_TYPE, property, unwrapSingle); - } - - @Override - protected DoubleIterableSerializer withResolved(BeanProperty property, Boolean unwrapSingle) { - return new DoubleIterableSerializer(property, unwrapSingle); + super(DoubleIterable.class, elementType(double.class), property, unwrapSingle); } @Override diff --git a/eclipse-collections/src/main/java/com/fasterxml/jackson/datatype/eclipsecollections/ser/FloatIterableSerializer.java b/eclipse-collections/src/main/java/com/fasterxml/jackson/datatype/eclipsecollections/ser/FloatIterableSerializer.java index 863a6b7a..bc5ec343 100644 --- a/eclipse-collections/src/main/java/com/fasterxml/jackson/datatype/eclipsecollections/ser/FloatIterableSerializer.java +++ b/eclipse-collections/src/main/java/com/fasterxml/jackson/datatype/eclipsecollections/ser/FloatIterableSerializer.java @@ -1,25 +1,18 @@ package com.fasterxml.jackson.datatype.eclipsecollections.ser; +import java.io.IOException; + import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.BeanProperty; -import com.fasterxml.jackson.databind.JavaType; -import com.fasterxml.jackson.databind.type.TypeFactory; -import java.io.IOException; + import org.eclipse.collections.api.FloatIterable; import org.eclipse.collections.api.iterator.FloatIterator; public final class FloatIterableSerializer extends PrimitiveIterableSerializer { private static final long serialVersionUID = 1L; - private static final JavaType ELEMENT_TYPE = TypeFactory.defaultInstance().constructType(float.class); - public FloatIterableSerializer(BeanProperty property, Boolean unwrapSingle) { - super(FloatIterable.class, ELEMENT_TYPE, property, unwrapSingle); - } - - @Override - protected FloatIterableSerializer withResolved(BeanProperty property, Boolean unwrapSingle) { - return new FloatIterableSerializer(property, unwrapSingle); + super(FloatIterable.class, elementType(float.class), property, unwrapSingle); } @Override diff --git a/eclipse-collections/src/main/java/com/fasterxml/jackson/datatype/eclipsecollections/ser/IntIterableSerializer.java b/eclipse-collections/src/main/java/com/fasterxml/jackson/datatype/eclipsecollections/ser/IntIterableSerializer.java index 991098ce..4da7bc82 100644 --- a/eclipse-collections/src/main/java/com/fasterxml/jackson/datatype/eclipsecollections/ser/IntIterableSerializer.java +++ b/eclipse-collections/src/main/java/com/fasterxml/jackson/datatype/eclipsecollections/ser/IntIterableSerializer.java @@ -1,25 +1,18 @@ package com.fasterxml.jackson.datatype.eclipsecollections.ser; +import java.io.IOException; + import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.BeanProperty; -import com.fasterxml.jackson.databind.JavaType; -import com.fasterxml.jackson.databind.type.TypeFactory; -import java.io.IOException; + import org.eclipse.collections.api.IntIterable; import org.eclipse.collections.api.iterator.IntIterator; public final class IntIterableSerializer extends PrimitiveIterableSerializer { private static final long serialVersionUID = 1L; - private static final JavaType ELEMENT_TYPE = TypeFactory.defaultInstance().constructType(int.class); - public IntIterableSerializer(BeanProperty property, Boolean unwrapSingle) { - super(IntIterable.class, ELEMENT_TYPE, property, unwrapSingle); - } - - @Override - protected IntIterableSerializer withResolved(BeanProperty property, Boolean unwrapSingle) { - return new IntIterableSerializer(property, unwrapSingle); + super(IntIterable.class, elementType(int.class), property, unwrapSingle); } @Override diff --git a/eclipse-collections/src/main/java/com/fasterxml/jackson/datatype/eclipsecollections/ser/LongIterableSerializer.java b/eclipse-collections/src/main/java/com/fasterxml/jackson/datatype/eclipsecollections/ser/LongIterableSerializer.java index aba00ca0..c3c280aa 100644 --- a/eclipse-collections/src/main/java/com/fasterxml/jackson/datatype/eclipsecollections/ser/LongIterableSerializer.java +++ b/eclipse-collections/src/main/java/com/fasterxml/jackson/datatype/eclipsecollections/ser/LongIterableSerializer.java @@ -1,25 +1,18 @@ package com.fasterxml.jackson.datatype.eclipsecollections.ser; +import java.io.IOException; + import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.BeanProperty; -import com.fasterxml.jackson.databind.JavaType; -import com.fasterxml.jackson.databind.type.TypeFactory; -import java.io.IOException; + import org.eclipse.collections.api.LongIterable; import org.eclipse.collections.api.iterator.LongIterator; public final class LongIterableSerializer extends PrimitiveIterableSerializer { private static final long serialVersionUID = 1L; - private static final JavaType ELEMENT_TYPE = TypeFactory.defaultInstance().constructType(long.class); - public LongIterableSerializer(BeanProperty property, Boolean unwrapSingle) { - super(LongIterable.class, ELEMENT_TYPE, property, unwrapSingle); - } - - @Override - protected LongIterableSerializer withResolved(BeanProperty property, Boolean unwrapSingle) { - return new LongIterableSerializer(property, unwrapSingle); + super(LongIterable.class, elementType(long.class), property, unwrapSingle); } @Override diff --git a/eclipse-collections/src/main/java/com/fasterxml/jackson/datatype/eclipsecollections/ser/PrimitiveIterableSerializer.java b/eclipse-collections/src/main/java/com/fasterxml/jackson/datatype/eclipsecollections/ser/PrimitiveIterableSerializer.java index 2b286d62..753933e2 100644 --- a/eclipse-collections/src/main/java/com/fasterxml/jackson/datatype/eclipsecollections/ser/PrimitiveIterableSerializer.java +++ b/eclipse-collections/src/main/java/com/fasterxml/jackson/datatype/eclipsecollections/ser/PrimitiveIterableSerializer.java @@ -10,6 +10,8 @@ import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.jsontype.TypeSerializer; import com.fasterxml.jackson.databind.ser.ContainerSerializer; +import com.fasterxml.jackson.databind.type.TypeFactory; + import java.io.IOException; import org.eclipse.collections.api.PrimitiveIterable; @@ -31,8 +33,6 @@ public PrimitiveIterableSerializer( _unwrapSingle = unwrapSingle; } - protected abstract PrimitiveIterableSerializer withResolved(BeanProperty property, Boolean unwrapSingle); - @Override public boolean isEmpty(SerializerProvider prov, C value) { return value.isEmpty(); @@ -87,4 +87,9 @@ public void serializeWithType(C value, JsonGenerator g, SerializerProvider provi } protected abstract void serializeContents(C value, JsonGenerator gen) throws IOException; + + // @since 2.19 + protected static JavaType elementType(Class rawElementType) { + return TypeFactory.defaultInstance().constructType(rawElementType); + } } diff --git a/eclipse-collections/src/main/java/com/fasterxml/jackson/datatype/eclipsecollections/ser/ShortIterableSerializer.java b/eclipse-collections/src/main/java/com/fasterxml/jackson/datatype/eclipsecollections/ser/ShortIterableSerializer.java index 365a73a6..2d6c65c2 100644 --- a/eclipse-collections/src/main/java/com/fasterxml/jackson/datatype/eclipsecollections/ser/ShortIterableSerializer.java +++ b/eclipse-collections/src/main/java/com/fasterxml/jackson/datatype/eclipsecollections/ser/ShortIterableSerializer.java @@ -1,25 +1,18 @@ package com.fasterxml.jackson.datatype.eclipsecollections.ser; +import java.io.IOException; + import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.BeanProperty; -import com.fasterxml.jackson.databind.JavaType; -import com.fasterxml.jackson.databind.type.TypeFactory; -import java.io.IOException; + import org.eclipse.collections.api.ShortIterable; import org.eclipse.collections.api.iterator.ShortIterator; public final class ShortIterableSerializer extends PrimitiveIterableSerializer { private static final long serialVersionUID = 1L; - private static final JavaType ELEMENT_TYPE = TypeFactory.defaultInstance().constructType(short.class); - public ShortIterableSerializer(BeanProperty property, Boolean unwrapSingle) { - super(ShortIterable.class, ELEMENT_TYPE, property, unwrapSingle); - } - - @Override - protected ShortIterableSerializer withResolved(BeanProperty property, Boolean unwrapSingle) { - return new ShortIterableSerializer(property, unwrapSingle); + super(ShortIterable.class, elementType(short.class), property, unwrapSingle); } @Override diff --git a/eclipse-collections/src/test/java/com/fasterxml/jackson/datatype/eclipsecollections/DeserializerTest.java b/eclipse-collections/src/test/java/com/fasterxml/jackson/datatype/eclipsecollections/DeserializerTest.java index f990e2f6..28e9a1e6 100644 --- a/eclipse-collections/src/test/java/com/fasterxml/jackson/datatype/eclipsecollections/DeserializerTest.java +++ b/eclipse-collections/src/test/java/com/fasterxml/jackson/datatype/eclipsecollections/DeserializerTest.java @@ -167,21 +167,22 @@ import org.eclipse.collections.impl.factory.primitive.ShortSets; import org.eclipse.collections.impl.tuple.Tuples; import org.eclipse.collections.impl.tuple.primitive.PrimitiveTuples; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; public final class DeserializerTest extends ModuleTestBase { private void testCollection(T expected, String json, TypeReference type) throws IOException { ObjectMapper objectMapper = mapperWithModule(); T value = objectMapper.readValue(json, type); - Assert.assertEquals(expected, value); - Assert.assertTrue(objectMapper.getTypeFactory().constructType(type).getRawClass().isInstance(value)); + assertEquals(expected, value); + assertTrue(objectMapper.getTypeFactory().constructType(type).getRawClass().isInstance(value)); } private void testCollection(T expected, String json, Class type) throws IOException { T value = mapperWithModule().readValue(json, type); - Assert.assertEquals(expected, value); - Assert.assertTrue(type.isInstance(value)); + assertEquals(expected, value); + assertTrue(type.isInstance(value)); } @Test @@ -465,7 +466,7 @@ static void primitiveMaps0(ObjectMapper mapper, boolean serialize) throws Except .getMethod("ofAll", baseMapType) .invoke(immutableFactory, mutableSample); - Assert.assertEquals(mutableSample, immutableSample); + assertEquals(mutableSample, immutableSample); Function, JavaType> generify; if (key == Object.class || value == Object.class) { @@ -483,21 +484,21 @@ static void primitiveMaps0(ObjectMapper mapper, boolean serialize) throws Except mapper.writerFor(generify.apply(baseMapType)).writeValueAsString(mutableSample); String polyPrinted = mapper.writeValueAsString(mutableSample); // compare trees so property order doesn't matter - Assert.assertEquals(mapper.readTree(json), mapper.readTree(mutablePrinted)); - Assert.assertEquals(mapper.readTree(json), mapper.readTree(immutablePrinted)); - Assert.assertEquals(mapper.readTree(json), mapper.readTree(basePrinted)); - Assert.assertEquals(mapper.readTree(json), mapper.readTree(polyPrinted)); + assertEquals(mapper.readTree(json), mapper.readTree(mutablePrinted)); + assertEquals(mapper.readTree(json), mapper.readTree(immutablePrinted)); + assertEquals(mapper.readTree(json), mapper.readTree(basePrinted)); + assertEquals(mapper.readTree(json), mapper.readTree(polyPrinted)); } else { Object mutableParsed = mapper.readValue(json, generify.apply(mutableMapType)); Object immutableParsed = mapper.readValue(json, generify.apply(immutableMapType)); Object baseParsed = mapper.readValue(json, generify.apply(baseMapType)); - Assert.assertEquals(mutableSample, mutableParsed); - Assert.assertEquals(immutableSample, immutableParsed); - Assert.assertEquals(mutableSample, baseParsed); + assertEquals(mutableSample, mutableParsed); + assertEquals(immutableSample, immutableParsed); + assertEquals(mutableSample, baseParsed); - Assert.assertTrue(mutableMapType.isInstance(mutableParsed)); - Assert.assertTrue(immutableMapType.isInstance(immutableParsed)); - Assert.assertTrue(baseMapType.isInstance(baseParsed)); + assertTrue(mutableMapType.isInstance(mutableParsed)); + assertTrue(immutableMapType.isInstance(immutableParsed)); + assertTrue(baseMapType.isInstance(baseParsed)); } } } @@ -509,19 +510,19 @@ private static String capitalize(String simpleName) { @Test public void objectObjectMaps() throws IOException { - Assert.assertEquals( + assertEquals( mapperWithModule().readValue("{\"abc\":\"def\"}", new TypeReference>() {}), Maps.mutable.of("abc", "def") ); - Assert.assertEquals( + assertEquals( mapperWithModule().readValue("{\"abc\":\"def\"}", new TypeReference>() {}), Maps.immutable.of("abc", "def") ); - Assert.assertEquals( + assertEquals( mapperWithModule().readValue("{\"abc\":\"def\"}", new TypeReference>() {}), Maps.mutable.of("abc", "def") ); - Assert.assertEquals( + assertEquals( mapperWithModule().readValue("{\"abc\":\"def\"}", new TypeReference>() {}), Maps.mutable.of("abc", "def") @@ -544,7 +545,7 @@ private static Object randomSample(Class type) { @Test public void typeInfoObjectMap() throws IOException { - Assert.assertEquals( + assertEquals( mapperWithModule() .readValue("{\"map\":{\"0\":{\"@c\":\".DeserializerTest$B\"}}}", Container.class).map, IntObjectMaps.immutable.of(0, new B()) @@ -581,7 +582,7 @@ public void typeInfoNestedMapList() throws IOException { // test case for jackson-datatypes-collections#71 ImmutableMap> property = Maps.immutable.of("foo", Lists.immutable.of(new B())); - Assert.assertEquals( + assertEquals( mapperWithModule().readValue( "{\"foo\": [{\"@c\": \".DeserializerTest$B\"}]}", new TypeReference>>() {}), @@ -594,7 +595,7 @@ public void typeInfoNestedMapMap() throws IOException { // auxiliary test case for jackson-datatypes-collections#71 - also worked before fix ImmutableMap> property = Maps.immutable.of("foo", Maps.immutable.of("bar", new B())); - Assert.assertEquals( + assertEquals( mapperWithModule().readValue( "{\"foo\": {\"bar\": {\"@c\": \".DeserializerTest$B\"}}}", new TypeReference>>() {}), @@ -656,8 +657,8 @@ public void primitivePairs() throws Exception { + ",\"two\":" + mapperWithModule().writeValueAsString(sampleTwo) + "}"; Object samplePair = factory.invoke(null, sampleOne, sampleTwo); - Assert.assertEquals(expectedJson, mapperWithModule().writeValueAsString(samplePair)); - Assert.assertEquals(samplePair, mapperWithModule().readValue(expectedJson, pairType)); + assertEquals(expectedJson, mapperWithModule().writeValueAsString(samplePair)); + assertEquals(samplePair, mapperWithModule().readValue(expectedJson, pairType)); } } } @@ -670,8 +671,8 @@ public void twin() throws Exception { String expectedJson = "{\"one\":" + mapper.writeValueAsString(sampleOne) + ",\"two\":" + mapper.writeValueAsString(sampleTwo) + "}"; Twin twin = Tuples.twin((String) sampleOne, (String) sampleTwo); - Assert.assertEquals(expectedJson, mapper.writeValueAsString(twin)); - Assert.assertEquals(twin, mapper.readValue(expectedJson, new TypeReference>() {})); + assertEquals(expectedJson, mapper.writeValueAsString(twin)); + assertEquals(twin, mapper.readValue(expectedJson, new TypeReference>() {})); } @Test @@ -681,8 +682,8 @@ public void pairTyped() throws Exception { final String actJson = mapper.writerFor(new TypeReference>() {}) .writeValueAsString(pair); String expJson = "{\"one\":{\"@c\":\".DeserializerTest$B\"},\"two\":5}"; - Assert.assertEquals(mapper.readTree(expJson), mapper.readTree(actJson)); - Assert.assertEquals(pair, + assertEquals(mapper.readTree(expJson), mapper.readTree(actJson)); + assertEquals(pair, mapper.readValue(actJson, new TypeReference>() {}) ); } @@ -693,8 +694,8 @@ public void nestedMap() throws Exception { String json = "{\"a\":{\"b\":\"c\"}}"; TypeReference>> type = new TypeReference>>() {}; - Assert.assertEquals(json, mapperWithModule().writerFor(type).writeValueAsString(pair)); - Assert.assertEquals(pair, mapperWithModule().readValue(json, type)); + assertEquals(json, mapperWithModule().writerFor(type).writeValueAsString(pair)); + assertEquals(pair, mapperWithModule().readValue(json, type)); } @Test @@ -704,8 +705,8 @@ public void triple() throws Exception { String actJson = mapper.writerFor(new TypeReference>() {}) .writeValueAsString(triple); String expJson = "{\"one\":\"a\",\"two\":2,\"three\":false}"; - Assert.assertEquals(mapper.readTree(expJson), mapper.readTree(actJson)); - Assert.assertEquals( + assertEquals(mapper.readTree(expJson), mapper.readTree(actJson)); + assertEquals( triple, mapper.readValue(actJson, new TypeReference>() {}) ); @@ -718,8 +719,8 @@ public void triplet() throws Exception { String actJson = mapper.writerFor(new TypeReference>() {}) .writeValueAsString(triple); String expJson = "{\"one\":\"a\",\"two\":\"b\",\"three\":\"c\"}"; - Assert.assertEquals(mapper.readTree(expJson), mapper.readTree(actJson)); - Assert.assertEquals( + assertEquals(mapper.readTree(expJson), mapper.readTree(actJson)); + assertEquals( triple, mapper.readValue(actJson, new TypeReference>() {}) ); diff --git a/eclipse-collections/src/test/java/com/fasterxml/jackson/datatype/eclipsecollections/Fuzz124_64629Test.java b/eclipse-collections/src/test/java/com/fasterxml/jackson/datatype/eclipsecollections/Fuzz124_64629Test.java index f9cee32d..72a2810b 100644 --- a/eclipse-collections/src/test/java/com/fasterxml/jackson/datatype/eclipsecollections/Fuzz124_64629Test.java +++ b/eclipse-collections/src/test/java/com/fasterxml/jackson/datatype/eclipsecollections/Fuzz124_64629Test.java @@ -1,15 +1,13 @@ package com.fasterxml.jackson.datatype.eclipsecollections; -import static org.junit.Assert.assertTrue; - -import org.junit.Assert; -import org.junit.Test; - import org.eclipse.collections.api.map.primitive.MutableCharCharMap; +import org.junit.jupiter.api.Test; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.exc.MismatchedInputException; +import static org.junit.jupiter.api.Assertions.*; + /** * Unit tests for verifying the fixes for OSS-Fuzz issues * work as expected @@ -25,7 +23,7 @@ public void testOSSFuzzIssue64629() throws Exception // Invalid token {"x?":[x?]: where ? is not ascii characters final char[] invalid = {123, 34, 824, 34, 58, 91, 120, 7, 93}; - MismatchedInputException e = Assert.assertThrows( + MismatchedInputException e = assertThrows( MismatchedInputException.class, () -> MAPPER.readValue(new String(invalid), MutableCharCharMap.class)); assertTrue(e.getMessage().contains("Cannot convert a JSON Null into a char element of map")); diff --git a/eclipse-collections/src/test/java/com/fasterxml/jackson/datatype/eclipsecollections/ModuleTestBase.java b/eclipse-collections/src/test/java/com/fasterxml/jackson/datatype/eclipsecollections/ModuleTestBase.java index 3acbd1e6..6082a6a2 100644 --- a/eclipse-collections/src/test/java/com/fasterxml/jackson/datatype/eclipsecollections/ModuleTestBase.java +++ b/eclipse-collections/src/test/java/com/fasterxml/jackson/datatype/eclipsecollections/ModuleTestBase.java @@ -3,7 +3,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import java.util.Arrays; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.fail; public abstract class ModuleTestBase { diff --git a/eclipse-collections/src/test/java/com/fasterxml/jackson/datatype/eclipsecollections/SerializerTest.java b/eclipse-collections/src/test/java/com/fasterxml/jackson/datatype/eclipsecollections/SerializerTest.java index 600727a6..6b6375f2 100644 --- a/eclipse-collections/src/test/java/com/fasterxml/jackson/datatype/eclipsecollections/SerializerTest.java +++ b/eclipse-collections/src/test/java/com/fasterxml/jackson/datatype/eclipsecollections/SerializerTest.java @@ -24,13 +24,15 @@ import org.eclipse.collections.impl.factory.primitive.IntObjectMaps; import org.eclipse.collections.impl.factory.primitive.LongLists; import org.eclipse.collections.impl.factory.primitive.ShortLists; -import org.junit.Assert; -import org.junit.Test; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; public final class SerializerTest extends ModuleTestBase { @Test public void ref() throws IOException { - Assert.assertEquals( + assertEquals( "[\"a\",\"b\",\"c\"]", mapperWithModule().writeValueAsString(Sets.immutable.of("a", "b", "c")) ); @@ -38,26 +40,26 @@ public void ref() throws IOException { @Test public void primitive() throws IOException { - Assert.assertEquals("[true,false,true]", mapperWithModule().writeValueAsString( + assertEquals("[true,false,true]", mapperWithModule().writeValueAsString( BooleanLists.immutable.of(true, false, true))); - Assert.assertEquals("[1,2,3]", mapperWithModule().writeValueAsString( + assertEquals("[1,2,3]", mapperWithModule().writeValueAsString( ShortLists.immutable.of((short) 1, (short) 2, (short) 3))); - Assert.assertEquals("[1,2,3]", mapperWithModule().writeValueAsString( + assertEquals("[1,2,3]", mapperWithModule().writeValueAsString( IntLists.immutable.of(1, 2, 3))); - Assert.assertEquals("[1.1,2.3,3.5]", mapperWithModule().writeValueAsString( + assertEquals("[1.1,2.3,3.5]", mapperWithModule().writeValueAsString( FloatLists.immutable.of(1.1F, 2.3F, 3.5F))); - Assert.assertEquals("[1,2,3]", mapperWithModule().writeValueAsString( + assertEquals("[1,2,3]", mapperWithModule().writeValueAsString( LongLists.immutable.of(1, 2, 3))); - Assert.assertEquals("[1.1,2.3,3.5]", mapperWithModule().writeValueAsString( + assertEquals("[1.1,2.3,3.5]", mapperWithModule().writeValueAsString( DoubleLists.immutable.of(1.1, 2.3, 3.5))); - Assert.assertEquals( + assertEquals( mapperWithModule().writeValueAsString(new byte[]{ 1, 2, 3 }), mapperWithModule().writeValueAsString(ByteLists.immutable.of((byte) 1, (byte) 2, (byte) 3))); - Assert.assertEquals( + assertEquals( mapperWithModule().writeValueAsString(new char[]{ '1', '2', '3' }), mapperWithModule().writeValueAsString(CharLists.immutable.of('1', '2', '3'))); - Assert.assertEquals( + assertEquals( mapperWithModule().configure(SerializationFeature.WRITE_CHAR_ARRAYS_AS_JSON_ARRAYS, true) .writeValueAsString(new char[]{ '1', '2', '3' }), mapperWithModule().configure(SerializationFeature.WRITE_CHAR_ARRAYS_AS_JSON_ARRAYS, true) @@ -82,7 +84,7 @@ class Wrapper { Wrapper wrapper = new Wrapper(); wrapper.object = iterable; - Assert.assertEquals("{\"object\":[\"" + iterable.getClass().getName() + "\"," + data + "]}", + assertEquals("{\"object\":[\"" + iterable.getClass().getName() + "\"," + data + "]}", objectMapper.writeValueAsString(wrapper)); } @@ -117,27 +119,27 @@ public void primitiveMaps() throws Exception @Test public void objectObjectMaps() throws IOException { - Assert.assertEquals( + assertEquals( "{\"abc\":\"def\"}", mapperWithModule().writerFor(MutableMap.class).writeValueAsString(Maps.mutable.of("abc", "def")) ); - Assert.assertEquals( + assertEquals( "{\"abc\":\"def\"}", mapperWithModule().writerFor(ImmutableMap.class).writeValueAsString(Maps.immutable.of("abc", "def")) ); - Assert.assertEquals( + assertEquals( "{\"abc\":\"def\"}", mapperWithModule().writerFor(MapIterable.class).writeValueAsString(Maps.immutable.of("abc", "def")) ); - Assert.assertEquals( + assertEquals( "{\"abc\":\"def\"}", mapperWithModule().writerFor(MutableMapIterable.class).writeValueAsString(Maps.mutable.of("abc", "def")) ); - Assert.assertEquals( + assertEquals( "{\"abc\":\"def\"}", mapperWithModule().writeValueAsString(Maps.immutable.of("abc", "def")) ); - Assert.assertEquals( + assertEquals( "{\"abc\":\"def\"}", mapperWithModule().writerFor(new TypeReference>() {}) .writeValueAsString(Maps.immutable.of("abc", "def")) @@ -146,7 +148,7 @@ public void objectObjectMaps() throws IOException { @Test public void typeInfoObjectMap() throws IOException { - Assert.assertEquals( + assertEquals( "{\"map\":{\"0\":{\"@c\":\".SerializerTest$B\"}}}", mapperWithModule().writeValueAsString(new Container()) ); diff --git a/guava/pom.xml b/guava/pom.xml index e949f2ca..f02d0119 100644 --- a/guava/pom.xml +++ b/guava/pom.xml @@ -8,7 +8,7 @@ com.fasterxml.jackson.datatype jackson-datatypes-collections - 2.18.5-SNAPSHOT + 2.19.0-SNAPSHOT jackson-datatype-guava Jackson datatype: Guava @@ -66,6 +66,13 @@ com.google.common.*;version="${version.guava.osgi}", guava ${version.guava} + + + + junit + junit + test + diff --git a/guava/src/main/java/com/fasterxml/jackson/datatype/guava/GuavaDeserializers.java b/guava/src/main/java/com/fasterxml/jackson/datatype/guava/GuavaDeserializers.java index 7f9c135a..d01a595d 100644 --- a/guava/src/main/java/com/fasterxml/jackson/datatype/guava/GuavaDeserializers.java +++ b/guava/src/main/java/com/fasterxml/jackson/datatype/guava/GuavaDeserializers.java @@ -1,7 +1,12 @@ package com.fasterxml.jackson.datatype.guava; +import com.fasterxml.jackson.datatype.guava.deser.table.HashBasedTableDeserializer; +import com.fasterxml.jackson.datatype.guava.deser.table.ImmutableTableDeserializer; +import com.fasterxml.jackson.datatype.guava.deser.table.TreeBasedTableDeserializer; import java.io.Serializable; +import com.fasterxml.jackson.databind.type.CollectionLikeType; +import com.fasterxml.jackson.datatype.guava.ser.ImmutableDoubleArraySerializer; import com.google.common.base.Optional; import com.google.common.cache.Cache; import com.google.common.collect.*; @@ -21,6 +26,8 @@ import com.fasterxml.jackson.datatype.guava.deser.multimap.list.LinkedListMultimapDeserializer; import com.fasterxml.jackson.datatype.guava.deser.multimap.set.HashMultimapDeserializer; import com.fasterxml.jackson.datatype.guava.deser.multimap.set.LinkedHashMultimapDeserializer; +import com.google.common.primitives.ImmutableDoubleArray; +import com.google.common.primitives.ImmutableIntArray; /** * Custom deserializers module offers. @@ -129,7 +136,6 @@ public JsonDeserializer findCollectionDeserializer(CollectionType type, elementDeserializer, elementTypeDeserializer, null, null); } - return null; } @@ -259,11 +265,18 @@ public JsonDeserializer findMapLikeDeserializer(MapLikeType type, } if (Table.class.isAssignableFrom(raw)) { - // !!! TODO + if (HashBasedTable.class.isAssignableFrom(raw)) { + return new HashBasedTableDeserializer(type); + } + if (TreeBasedTable.class.isAssignableFrom(raw)) { + return new TreeBasedTableDeserializer(type); + } + return new ImmutableTableDeserializer(type); } + // @since 2.16 : support Cache deserialization - java.util.Optional> cacheDeserializer = findCacheDeserializer(raw, type, config, - beanDesc, keyDeserializer, elementTypeDeserializer, elementDeserializer); + java.util.Optional> cacheDeserializer = findCacheDeserializer(raw, type, config, + beanDesc, keyDeserializer, elementTypeDeserializer, elementDeserializer); if (cacheDeserializer.isPresent()) { return cacheDeserializer.get(); } @@ -281,9 +294,9 @@ public JsonDeserializer findMapLikeDeserializer(MapLikeType type, * @return An optional {@link JsonDeserializer} for the cache type, if found. * @since 2.16 */ - private java.util.Optional> findCacheDeserializer(Class raw, MapLikeType type, - DeserializationConfig config, BeanDescription beanDesc, KeyDeserializer keyDeserializer, - TypeDeserializer elementTypeDeserializer, JsonDeserializer elementDeserializer) + private java.util.Optional> findCacheDeserializer(Class raw, MapLikeType type, + DeserializationConfig config, BeanDescription beanDesc, KeyDeserializer keyDeserializer, + TypeDeserializer elementTypeDeserializer, JsonDeserializer elementDeserializer) { /* // Example implementations if (LoadingCache.class.isAssignableFrom(raw)) { @@ -315,7 +328,7 @@ public JsonDeserializer findReferenceDeserializer(ReferenceType refType, public JsonDeserializer findBeanDeserializer(final JavaType type, DeserializationConfig config, BeanDescription beanDesc) { - if (RangeSet.class.isAssignableFrom(type.getRawClass())) { + if (type.isTypeOrSubTypeOf(RangeSet.class)) { return new RangeSetDeserializer(); } if (type.hasRawClass(Range.class)) { @@ -330,6 +343,12 @@ public JsonDeserializer findBeanDeserializer(final JavaType type, Deserializa if (type.hasRawClass(HashCode.class)) { return HashCodeDeserializer.std; } + if (type.hasRawClass(ImmutableIntArray.class)) { + return new ImmutableIntArrayDeserializer(); + } + if (type.hasRawClass(ImmutableDoubleArray.class)) { + return new ImmutableDoubleArrayDeserializer(); + } return null; } @@ -348,6 +367,8 @@ public boolean hasDeserializerFor(DeserializationConfig config, Class valueTy || ImmutableMap.class.isAssignableFrom(valueType) || BiMap.class.isAssignableFrom(valueType) || ImmutableRangeSet.class.isAssignableFrom(valueType) + || (valueType == ImmutableIntArray.class) + || (valueType == ImmutableDoubleArray.class) ; } return false; diff --git a/guava/src/main/java/com/fasterxml/jackson/datatype/guava/GuavaSerializers.java b/guava/src/main/java/com/fasterxml/jackson/datatype/guava/GuavaSerializers.java index 6b795227..302449e7 100644 --- a/guava/src/main/java/com/fasterxml/jackson/datatype/guava/GuavaSerializers.java +++ b/guava/src/main/java/com/fasterxml/jackson/datatype/guava/GuavaSerializers.java @@ -13,7 +13,6 @@ import com.fasterxml.jackson.databind.type.ReferenceType; import com.fasterxml.jackson.databind.ser.std.StdDelegatingSerializer; import com.fasterxml.jackson.databind.util.StdConverter; -import com.fasterxml.jackson.datatype.guava.ser.RangeSetSerializer; import com.google.common.base.Optional; import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; @@ -26,10 +25,15 @@ import com.google.common.hash.HashCode; import com.google.common.net.HostAndPort; import com.google.common.net.InternetDomainName; +import com.google.common.primitives.ImmutableDoubleArray; +import com.google.common.primitives.ImmutableIntArray; import com.fasterxml.jackson.datatype.guava.ser.CacheSerializer; import com.fasterxml.jackson.datatype.guava.ser.GuavaOptionalSerializer; +import com.fasterxml.jackson.datatype.guava.ser.ImmutableDoubleArraySerializer; +import com.fasterxml.jackson.datatype.guava.ser.ImmutableIntArraySerializer; import com.fasterxml.jackson.datatype.guava.ser.MultimapSerializer; import com.fasterxml.jackson.datatype.guava.ser.RangeSerializer; +import com.fasterxml.jackson.datatype.guava.ser.RangeSetSerializer; import com.fasterxml.jackson.datatype.guava.ser.TableSerializer; public class GuavaSerializers extends Serializers.Base @@ -47,7 +51,7 @@ public Iterable convert(Object value) { } @Override - public JsonSerializer findReferenceSerializer(SerializationConfig config, + public JsonSerializer findReferenceSerializer(SerializationConfig config, ReferenceType refType, BeanDescription beanDesc, TypeSerializer contentTypeSerializer, JsonSerializer contentValueSerializer) { @@ -64,35 +68,37 @@ public JsonSerializer findReferenceSerializer(SerializationConfig config, @Override public JsonSerializer findSerializer(SerializationConfig config, JavaType type, BeanDescription beanDesc) { - Class raw = type.getRawClass(); - if (RangeSet.class.isAssignableFrom(raw)) { + if (type.isTypeOrSubTypeOf(RangeSet.class)) { return new RangeSetSerializer(); } - if (Range.class.isAssignableFrom(raw)) { + if (type.isTypeOrSubTypeOf(Range.class)) { return new RangeSerializer(_findDeclared(type, Range.class)); } - if (Table.class.isAssignableFrom(raw)) { - return new TableSerializer(_findDeclared(type, Table.class)); - } // since 2.4 - if (HostAndPort.class.isAssignableFrom(raw)) { + if (type.isTypeOrSubTypeOf(HostAndPort.class)) { return ToStringSerializer.instance; } - if (InternetDomainName.class.isAssignableFrom(raw)) { + if (type.isTypeOrSubTypeOf(InternetDomainName.class)) { return ToStringSerializer.instance; } // not sure how useful, but why not? - if (CacheBuilderSpec.class.isAssignableFrom(raw) || CacheBuilder.class.isAssignableFrom(raw)) { + if (type.isTypeOrSubTypeOf(CacheBuilderSpec.class) || type.isTypeOrSubTypeOf(CacheBuilder.class)) { return ToStringSerializer.instance; } - if (HashCode.class.isAssignableFrom(raw)) { + if (type.isTypeOrSubTypeOf(HashCode.class)) { return ToStringSerializer.instance; } - if (FluentIterable.class.isAssignableFrom(raw)) { + if (type.isTypeOrSubTypeOf(FluentIterable.class)) { JavaType iterableType = _findDeclared(type, Iterable.class); return new StdDelegatingSerializer(FluentConverter.instance, iterableType, null); } + if (ImmutableIntArray.class.isAssignableFrom(raw)) { + return new ImmutableIntArraySerializer(); + } + if (ImmutableDoubleArray.class.isAssignableFrom(raw)) { + return new ImmutableDoubleArraySerializer(); + } return super.findSerializer(config, type, beanDesc); } @@ -101,7 +107,7 @@ public JsonSerializer findMapLikeSerializer(SerializationConfig config, MapLikeType type, BeanDescription beanDesc, JsonSerializer keySerializer, TypeSerializer elementTypeSerializer, JsonSerializer elementValueSerializer) { - if (Multimap.class.isAssignableFrom(type.getRawClass())) { + if (type.isTypeOrSubTypeOf(Multimap.class)) { final AnnotationIntrospector intr = config.getAnnotationIntrospector(); Object filterId = intr.findFilterId((Annotated)beanDesc.getClassInfo()); JsonIgnoreProperties.Value ignorals = config.getDefaultPropertyIgnorals(Multimap.class, @@ -110,7 +116,7 @@ public JsonSerializer findMapLikeSerializer(SerializationConfig config, return new MultimapSerializer(type, beanDesc, keySerializer, elementTypeSerializer, elementValueSerializer, ignored, filterId); } - if (Cache.class.isAssignableFrom(type.getRawClass())) { + if (type.isTypeOrSubTypeOf(Cache.class)) { final AnnotationIntrospector intr = config.getAnnotationIntrospector(); Object filterId = intr.findFilterId((Annotated)beanDesc.getClassInfo()); JsonIgnoreProperties.Value ignorals = config.getDefaultPropertyIgnorals(Cache.class, @@ -119,6 +125,9 @@ public JsonSerializer findMapLikeSerializer(SerializationConfig config, return new CacheSerializer(type, beanDesc, keySerializer, elementTypeSerializer, elementValueSerializer, ignored, filterId); } + if (type.isTypeOrSubTypeOf(Table.class)) { + return new TableSerializer(type); + } return null; } diff --git a/guava/src/main/java/com/fasterxml/jackson/datatype/guava/GuavaTypeModifier.java b/guava/src/main/java/com/fasterxml/jackson/datatype/guava/GuavaTypeModifier.java index 4f50106d..64439aee 100644 --- a/guava/src/main/java/com/fasterxml/jackson/datatype/guava/GuavaTypeModifier.java +++ b/guava/src/main/java/com/fasterxml/jackson/datatype/guava/GuavaTypeModifier.java @@ -53,6 +53,19 @@ public JavaType modifyType(JavaType type, Type jdkType, TypeBindings bindings, T if (raw == Optional.class) { return ReferenceType.upgradeFrom(type, type.containedTypeOrUnknown(0)); } + if (raw == Table.class) { + MapLikeType columnValueType = + MapLikeType.upgradeFrom( + type, + type.containedTypeOrUnknown(1), + type.containedTypeOrUnknown(2) + ); + return MapLikeType.upgradeFrom( + type, + type.containedTypeOrUnknown(0), + columnValueType + ); + } return type; } } diff --git a/guava/src/main/java/com/fasterxml/jackson/datatype/guava/deser/GuavaCollectionDeserializer.java b/guava/src/main/java/com/fasterxml/jackson/datatype/guava/deser/GuavaCollectionDeserializer.java index f8db28d5..d0cf6f43 100644 --- a/guava/src/main/java/com/fasterxml/jackson/datatype/guava/deser/GuavaCollectionDeserializer.java +++ b/guava/src/main/java/com/fasterxml/jackson/datatype/guava/deser/GuavaCollectionDeserializer.java @@ -175,7 +175,7 @@ protected T _deserializeFromSingleValue(JsonParser p, DeserializationContext ctx { final JsonDeserializer valueDes = _valueDeserializer; final TypeDeserializer typeDeser = _valueTypeDeserializer; - final JsonToken t = p.getCurrentToken(); + final JsonToken t = p.currentToken(); final Object value; diff --git a/guava/src/main/java/com/fasterxml/jackson/datatype/guava/deser/GuavaImmutableMapDeserializer.java b/guava/src/main/java/com/fasterxml/jackson/datatype/guava/deser/GuavaImmutableMapDeserializer.java index 716c9bac..4dd6cfff 100644 --- a/guava/src/main/java/com/fasterxml/jackson/datatype/guava/deser/GuavaImmutableMapDeserializer.java +++ b/guava/src/main/java/com/fasterxml/jackson/datatype/guava/deser/GuavaImmutableMapDeserializer.java @@ -43,7 +43,7 @@ protected T _deserializeEntries(JsonParser p, DeserializationContext ctxt) final TypeDeserializer typeDeser = _valueTypeDeserializer; ImmutableMap.Builder builder = createBuilder(); - for (; p.getCurrentToken() == JsonToken.FIELD_NAME; p.nextToken()) { + for (; p.currentToken() == JsonToken.FIELD_NAME; p.nextToken()) { // Must point to field name now String fieldName = p.currentName(); Object key = (keyDes == null) ? fieldName : keyDes.deserializeKey(fieldName, ctxt); diff --git a/guava/src/main/java/com/fasterxml/jackson/datatype/guava/deser/GuavaMapDeserializer.java b/guava/src/main/java/com/fasterxml/jackson/datatype/guava/deser/GuavaMapDeserializer.java index 6ff4d357..3fa66e3a 100644 --- a/guava/src/main/java/com/fasterxml/jackson/datatype/guava/deser/GuavaMapDeserializer.java +++ b/guava/src/main/java/com/fasterxml/jackson/datatype/guava/deser/GuavaMapDeserializer.java @@ -158,7 +158,7 @@ public T deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { // Ok: must point to START_OBJECT or FIELD_NAME - JsonToken t = p.getCurrentToken(); + JsonToken t = p.currentToken(); if (t == JsonToken.START_OBJECT) { // If START_OBJECT, move to next; may also be END_OBJECT t = p.nextToken(); } diff --git a/guava/src/main/java/com/fasterxml/jackson/datatype/guava/deser/ImmutableDoubleArrayDeserializer.java b/guava/src/main/java/com/fasterxml/jackson/datatype/guava/deser/ImmutableDoubleArrayDeserializer.java new file mode 100644 index 00000000..514475f5 --- /dev/null +++ b/guava/src/main/java/com/fasterxml/jackson/datatype/guava/deser/ImmutableDoubleArrayDeserializer.java @@ -0,0 +1,50 @@ +package com.fasterxml.jackson.datatype.guava.deser; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.DeserializationConfig; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.deser.std.PrimitiveArrayDeserializers; +import com.fasterxml.jackson.databind.deser.std.StdDeserializer; +import com.fasterxml.jackson.databind.util.AccessPattern; +import com.google.common.primitives.ImmutableDoubleArray; + +import java.io.IOException; + +public final class ImmutableDoubleArrayDeserializer extends StdDeserializer { + + private final JsonDeserializer doubleArrayDeserializer; + + public ImmutableDoubleArrayDeserializer() { + super(ImmutableDoubleArray.class); + @SuppressWarnings("unchecked") + JsonDeserializer doubleArrayDeserializer = (JsonDeserializer) PrimitiveArrayDeserializers.forType(double.class); + this.doubleArrayDeserializer = doubleArrayDeserializer; + } + + @Override + public Boolean supportsUpdate(DeserializationConfig config) { + return Boolean.FALSE; + } + + @Override + public boolean isCachable() { + return true; + } + + @Override + public AccessPattern getEmptyAccessPattern() { + return AccessPattern.CONSTANT; + } + + @Override + public ImmutableDoubleArray getEmptyValue(DeserializationContext ctxt) throws JsonMappingException { + return ImmutableDoubleArray.of(); + } + + @Override + public ImmutableDoubleArray deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException { + return ImmutableDoubleArray.copyOf(doubleArrayDeserializer.deserialize(jsonParser, deserializationContext)); + } +} diff --git a/guava/src/main/java/com/fasterxml/jackson/datatype/guava/deser/ImmutableIntArrayDeserializer.java b/guava/src/main/java/com/fasterxml/jackson/datatype/guava/deser/ImmutableIntArrayDeserializer.java new file mode 100644 index 00000000..77c1260f --- /dev/null +++ b/guava/src/main/java/com/fasterxml/jackson/datatype/guava/deser/ImmutableIntArrayDeserializer.java @@ -0,0 +1,50 @@ +package com.fasterxml.jackson.datatype.guava.deser; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.DeserializationConfig; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.deser.std.PrimitiveArrayDeserializers; +import com.fasterxml.jackson.databind.deser.std.StdDeserializer; +import com.fasterxml.jackson.databind.util.AccessPattern; +import com.google.common.primitives.ImmutableIntArray; + +import java.io.IOException; + +public final class ImmutableIntArrayDeserializer extends StdDeserializer { + + private final JsonDeserializer intArrayDeserializer; + + public ImmutableIntArrayDeserializer() { + super(ImmutableIntArray.class); + @SuppressWarnings("unchecked") + JsonDeserializer intArrayDeserializer = (JsonDeserializer) PrimitiveArrayDeserializers.forType(int.class); + this.intArrayDeserializer = intArrayDeserializer; + } + + @Override + public Boolean supportsUpdate(DeserializationConfig config) { + return Boolean.FALSE; + } + + @Override + public boolean isCachable() { + return true; + } + + @Override + public AccessPattern getEmptyAccessPattern() { + return AccessPattern.CONSTANT; + } + + @Override + public ImmutableIntArray getEmptyValue(DeserializationContext ctxt) throws JsonMappingException { + return ImmutableIntArray.of(); + } + + @Override + public ImmutableIntArray deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException { + return ImmutableIntArray.copyOf(intArrayDeserializer.deserialize(jsonParser, deserializationContext)); + } +} diff --git a/guava/src/main/java/com/fasterxml/jackson/datatype/guava/deser/cache/GuavaCacheDeserializer.java b/guava/src/main/java/com/fasterxml/jackson/datatype/guava/deser/cache/GuavaCacheDeserializer.java index a54c5dff..1977e742 100644 --- a/guava/src/main/java/com/fasterxml/jackson/datatype/guava/deser/cache/GuavaCacheDeserializer.java +++ b/guava/src/main/java/com/fasterxml/jackson/datatype/guava/deser/cache/GuavaCacheDeserializer.java @@ -160,7 +160,7 @@ private T deserializeContents(JsonParser p, DeserializationContext ctxt) } private void expect(JsonParser p, JsonToken token) throws IOException { - if (p.getCurrentToken() != token) { + if (p.currentToken() != token) { throw new JsonMappingException(p, "Expecting " + token + " to start `Cache` value, found " + p.currentToken(), p.currentLocation()); } diff --git a/guava/src/main/java/com/fasterxml/jackson/datatype/guava/deser/multimap/GuavaMultimapDeserializer.java b/guava/src/main/java/com/fasterxml/jackson/datatype/guava/deser/multimap/GuavaMultimapDeserializer.java index 77cd8c55..ae131df5 100644 --- a/guava/src/main/java/com/fasterxml/jackson/datatype/guava/deser/multimap/GuavaMultimapDeserializer.java +++ b/guava/src/main/java/com/fasterxml/jackson/datatype/guava/deser/multimap/GuavaMultimapDeserializer.java @@ -272,7 +272,7 @@ private Object getCurrentTokenValue(JsonParser p, DeserializationContext ctxt) } private void expect(JsonParser p, JsonToken token) throws IOException { - if (p.getCurrentToken() != token) { + if (p.currentToken() != token) { throw new JsonMappingException(p, "Expecting " + token + " to start `MultiMap` value, found " + p.currentToken(), p.currentLocation()); } diff --git a/guava/src/main/java/com/fasterxml/jackson/datatype/guava/deser/table/HashBasedTableDeserializer.java b/guava/src/main/java/com/fasterxml/jackson/datatype/guava/deser/table/HashBasedTableDeserializer.java new file mode 100644 index 00000000..b9fb8185 --- /dev/null +++ b/guava/src/main/java/com/fasterxml/jackson/datatype/guava/deser/table/HashBasedTableDeserializer.java @@ -0,0 +1,44 @@ +package com.fasterxml.jackson.datatype.guava.deser.table; + +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.KeyDeserializer; +import com.fasterxml.jackson.databind.deser.NullValueProvider; +import com.fasterxml.jackson.databind.jsontype.TypeDeserializer; +import com.fasterxml.jackson.databind.type.MapLikeType; +import com.google.common.collect.HashBasedTable; + +/** + * Provides deserialization for the Guava HashBasedTable class. + * + * @author Abhishekkr3003 + */ +public class HashBasedTableDeserializer + extends MutableTableDeserializer> { + private static final long serialVersionUID = 1L; + + public HashBasedTableDeserializer(MapLikeType type) { + super(type); + } + + public HashBasedTableDeserializer(MapLikeType type, KeyDeserializer rowDeserializer, + KeyDeserializer columnDeserializer, TypeDeserializer elementTypeDeserializer, + JsonDeserializer elementDeserializer, NullValueProvider nvp) { + super(type, rowDeserializer, columnDeserializer, elementTypeDeserializer, + elementDeserializer, nvp + ); + } + + @Override + protected HashBasedTable createTable() { + return HashBasedTable.create(); + } + + @Override + protected JsonDeserializer _createContextual(MapLikeType type, + KeyDeserializer rowDeserializer, + KeyDeserializer columnDeserializer, TypeDeserializer typeDeserializer, + JsonDeserializer elementDeserializer, NullValueProvider nvp) { + return new HashBasedTableDeserializer(type, + rowDeserializer, columnDeserializer, typeDeserializer, elementDeserializer, nvp); + } +} diff --git a/guava/src/main/java/com/fasterxml/jackson/datatype/guava/deser/table/ImmutableTableDeserializer.java b/guava/src/main/java/com/fasterxml/jackson/datatype/guava/deser/table/ImmutableTableDeserializer.java new file mode 100644 index 00000000..dedd7c54 --- /dev/null +++ b/guava/src/main/java/com/fasterxml/jackson/datatype/guava/deser/table/ImmutableTableDeserializer.java @@ -0,0 +1,115 @@ +package com.fasterxml.jackson.datatype.guava.deser.table; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonToken; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.KeyDeserializer; +import com.fasterxml.jackson.databind.deser.NullValueProvider; +import com.fasterxml.jackson.databind.jsontype.TypeDeserializer; +import com.fasterxml.jackson.databind.type.MapLikeType; +import com.fasterxml.jackson.databind.util.AccessPattern; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableTable; +import java.io.IOException; + +/** + * Provides deserialization for the Guava ImmutableTable class. + * + * @author Abhishekkr3003 + */ +public class ImmutableTableDeserializer + extends TableDeserializer> { + private static final long serialVersionUID = 2L; + + public ImmutableTableDeserializer(MapLikeType type) { + super(type); + } + + protected ImmutableTableDeserializer(MapLikeType type, KeyDeserializer rowDeserializer, + KeyDeserializer colDeserializer, JsonDeserializer valueDeserializer, + TypeDeserializer valueTypeDeserializer, NullValueProvider nuller) { + super(type, rowDeserializer, colDeserializer, valueTypeDeserializer, valueDeserializer, + nuller + ); + } + + @Override + public AccessPattern getEmptyAccessPattern() { + // immutable, hence: + return AccessPattern.CONSTANT; + } + + + @Override + public Object getEmptyValue(DeserializationContext ctxt) throws JsonMappingException { + return ImmutableMap.of(); + } + + protected ImmutableTable.Builder createBuilder() { + return ImmutableTable.builder(); + } + + @Override + public ImmutableTable deserialize(JsonParser p, + DeserializationContext ctxt) throws IOException { + ImmutableTable.Builder table = createBuilder(); + + JsonToken currToken = p.currentToken(); + if (currToken != JsonToken.FIELD_NAME && currToken != JsonToken.END_OBJECT) { + expect(p, JsonToken.START_OBJECT); + currToken = p.nextToken(); + } + + for (; currToken == JsonToken.FIELD_NAME; currToken = p.nextToken()) { + final Object rowKey; + if (_rowDeserializer != null) { + rowKey = _rowDeserializer.deserializeKey(p.currentName(), ctxt); + } else { + rowKey = p.currentName(); + } + + p.nextToken(); + expect(p, JsonToken.START_OBJECT); + + for ( + currToken = p.nextToken(); currToken == JsonToken.FIELD_NAME; + currToken = p.nextToken()) { + final Object colKey; + if (_colDeserializer != null) { + colKey = _colDeserializer.deserializeKey(p.currentName(), ctxt); + } else { + colKey = p.currentName(); + } + + p.nextToken(); + + final Object value; + if (p.currentToken() == JsonToken.VALUE_NULL) { + if (_skipNullValues) { + continue; + } + value = _nullProvider.getNullValue(ctxt); + } else if (_valueTypeDeserializer != null) { + value = _valueDeserializer.deserializeWithType(p, ctxt, _valueTypeDeserializer); + } else { + value = _valueDeserializer.deserialize(p, ctxt); + } + table.put(rowKey, colKey, value); + } + expect(p, JsonToken.END_OBJECT); + } + return table.build(); + } + + @Override + protected JsonDeserializer _createContextual(MapLikeType type, + KeyDeserializer rowDeserializer, + KeyDeserializer columnDeserializer, TypeDeserializer valueTypeDeserializer, + JsonDeserializer valueDeserializer, NullValueProvider nullValueProvider) { + return new ImmutableTableDeserializer(type, rowDeserializer, columnDeserializer, + valueDeserializer, valueTypeDeserializer, nullValueProvider + ); + } +} diff --git a/guava/src/main/java/com/fasterxml/jackson/datatype/guava/deser/table/MutableTableDeserializer.java b/guava/src/main/java/com/fasterxml/jackson/datatype/guava/deser/table/MutableTableDeserializer.java new file mode 100644 index 00000000..b829c471 --- /dev/null +++ b/guava/src/main/java/com/fasterxml/jackson/datatype/guava/deser/table/MutableTableDeserializer.java @@ -0,0 +1,91 @@ +package com.fasterxml.jackson.datatype.guava.deser.table; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonToken; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.KeyDeserializer; +import com.fasterxml.jackson.databind.deser.NullValueProvider; +import com.fasterxml.jackson.databind.jsontype.TypeDeserializer; +import com.fasterxml.jackson.databind.type.MapLikeType; +import com.google.common.collect.Table; +import java.io.IOException; + +/** + * @author Abhishekkr3003 + */ +public abstract class MutableTableDeserializer> + extends TableDeserializer +{ + private static final long serialVersionUID = 1L; + + protected MutableTableDeserializer(MapLikeType type) { + super(type); + } + + protected MutableTableDeserializer(MapLikeType _type, KeyDeserializer _rowDeserializer, + KeyDeserializer _colDeserializer, TypeDeserializer _valueTypeDeserializer, + JsonDeserializer _valueDeserializer, NullValueProvider nvp) { + super( + _type, _rowDeserializer, _colDeserializer, _valueTypeDeserializer, _valueDeserializer, + nvp + ); + } + + protected abstract T createTable(); + + @Override + protected abstract JsonDeserializer _createContextual(MapLikeType t, KeyDeserializer rkd, + KeyDeserializer ckd, TypeDeserializer vtd, JsonDeserializer vd, NullValueProvider np); + + @Override + public T deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { + T table = createTable(); + + JsonToken currToken = p.currentToken(); + if (currToken != JsonToken.FIELD_NAME && currToken != JsonToken.END_OBJECT) { + expect(p, JsonToken.START_OBJECT); + currToken = p.nextToken(); + } + + for (; currToken == JsonToken.FIELD_NAME; currToken = p.nextToken()) { + final Object rowKey; + if (_rowDeserializer != null) { + rowKey = _rowDeserializer.deserializeKey(p.currentName(), ctxt); + } else { + rowKey = p.currentName(); + } + + p.nextToken(); + expect(p, JsonToken.START_OBJECT); + + for ( + currToken = p.nextToken(); currToken == JsonToken.FIELD_NAME; + currToken = p.nextToken()) { + final Object colKey; + if (_colDeserializer != null) { + colKey = _colDeserializer.deserializeKey(p.currentName(), ctxt); + } else { + colKey = p.currentName(); + } + + p.nextToken(); + + final Object value; + if (p.currentToken() == JsonToken.VALUE_NULL) { + if (_skipNullValues) { + continue; + } + value = _nullProvider.getNullValue(ctxt); + } else if (_valueTypeDeserializer != null) { + value = _valueDeserializer.deserializeWithType(p, ctxt, _valueTypeDeserializer); + } else { + value = _valueDeserializer.deserialize(p, ctxt); + } + table.put(rowKey, colKey, value); + } + expect(p, JsonToken.END_OBJECT); + } + return table; + } +} diff --git a/guava/src/main/java/com/fasterxml/jackson/datatype/guava/deser/table/TableDeserializer.java b/guava/src/main/java/com/fasterxml/jackson/datatype/guava/deser/table/TableDeserializer.java new file mode 100644 index 00000000..763960d1 --- /dev/null +++ b/guava/src/main/java/com/fasterxml/jackson/datatype/guava/deser/table/TableDeserializer.java @@ -0,0 +1,115 @@ +package com.fasterxml.jackson.datatype.guava.deser.table; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonToken; +import com.fasterxml.jackson.databind.BeanProperty; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JavaType; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.KeyDeserializer; +import com.fasterxml.jackson.databind.deser.ContextualDeserializer; +import com.fasterxml.jackson.databind.deser.NullValueProvider; +import com.fasterxml.jackson.databind.deser.impl.NullsConstantProvider; +import com.fasterxml.jackson.databind.deser.std.StdDeserializer; +import com.fasterxml.jackson.databind.jsontype.TypeDeserializer; +import com.fasterxml.jackson.databind.type.MapLikeType; +import com.google.common.collect.Table; +import java.io.IOException; + +/** + * @author Abhishekkr3003 + */ +public abstract class TableDeserializer> + extends StdDeserializer implements ContextualDeserializer { + private static final long serialVersionUID = 1L; + + protected final MapLikeType _type; + protected final KeyDeserializer _rowDeserializer; + protected final KeyDeserializer _colDeserializer; + protected final TypeDeserializer _valueTypeDeserializer; + protected final JsonDeserializer _valueDeserializer; + + // since 2.9.5: in 3.x demote to `ContainerDeserializerBase` + protected final NullValueProvider _nullProvider; + protected final boolean _skipNullValues; + + protected TableDeserializer(MapLikeType _type, KeyDeserializer _rowDeserializer, + KeyDeserializer _colDeserializer, TypeDeserializer _valueTypeDeserializer, + JsonDeserializer _valueDeserializer) { + this( + _type, _rowDeserializer, _colDeserializer, _valueTypeDeserializer, _valueDeserializer, + null + ); + } + + protected TableDeserializer(MapLikeType _type, KeyDeserializer _rowDeserializer, + KeyDeserializer _colDeserializer, TypeDeserializer _valueTypeDeserializer, + JsonDeserializer _valueDeserializer, NullValueProvider nvp) { + super(_type); + this._type = _type; + this._rowDeserializer = _rowDeserializer; + this._colDeserializer = _colDeserializer; + this._valueTypeDeserializer = _valueTypeDeserializer; + this._valueDeserializer = _valueDeserializer; + this._nullProvider = nvp; + _skipNullValues = (nvp == null) ? false : NullsConstantProvider.isSkipper(nvp); + } + + protected TableDeserializer(MapLikeType type) { + super(type); + _type = type; + _rowDeserializer = null; + _colDeserializer = null; + _valueDeserializer = null; + _valueTypeDeserializer = null; + _nullProvider = null; + _skipNullValues = false; + } + + /** + * We need to use this method to properly handle possible contextual variants of key and value + * deserializers, as well as type deserializers. + */ + @Override + public JsonDeserializer createContextual(DeserializationContext ctxt, + BeanProperty property) throws JsonMappingException { + KeyDeserializer rkd = _rowDeserializer; + if (rkd == null) { + rkd = ctxt.findKeyDeserializer(_type.getKeyType(), property); + } + MapLikeType columnValueType = (MapLikeType) _type.getContentType(); + KeyDeserializer ckd = _colDeserializer; + if (ckd == null) { + ckd = ctxt.findKeyDeserializer(columnValueType.getKeyType(), property); + } + JsonDeserializer valueDeser = _valueDeserializer; + final JavaType vt = columnValueType.getContentType(); + if (valueDeser == null) { + valueDeser = ctxt.findContextualValueDeserializer(vt, property); + } else { // if directly assigned, probably not yet contextual, so: + valueDeser = ctxt.handleSecondaryContextualization(valueDeser, property, vt); + } + // Type deserializer is slightly different; must be passed, but needs to become contextual: + TypeDeserializer vtd = _valueTypeDeserializer; + if (vtd != null) { + vtd = vtd.forProperty(property); + } + return _createContextual(_type, + rkd, ckd, vtd, valueDeser, findContentNullProvider(ctxt, property, valueDeser)); + } + + protected abstract JsonDeserializer _createContextual(MapLikeType t, KeyDeserializer rkd, + KeyDeserializer ckd, TypeDeserializer vtd, JsonDeserializer vd, NullValueProvider np); + + + protected void expect(JsonParser p, JsonToken token) throws IOException { + if (p.currentToken() != token) { + throw new JsonMappingException( + p, + "Expecting " + token + " to start `TABLE` value, found " + p.currentToken(), + p.currentLocation() + ); + } + } +} diff --git a/guava/src/main/java/com/fasterxml/jackson/datatype/guava/deser/table/TreeBasedTableDeserializer.java b/guava/src/main/java/com/fasterxml/jackson/datatype/guava/deser/table/TreeBasedTableDeserializer.java new file mode 100644 index 00000000..c102a183 --- /dev/null +++ b/guava/src/main/java/com/fasterxml/jackson/datatype/guava/deser/table/TreeBasedTableDeserializer.java @@ -0,0 +1,46 @@ +package com.fasterxml.jackson.datatype.guava.deser.table; + +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.KeyDeserializer; +import com.fasterxml.jackson.databind.deser.NullValueProvider; +import com.fasterxml.jackson.databind.jsontype.TypeDeserializer; +import com.fasterxml.jackson.databind.type.MapLikeType; +import com.google.common.collect.TreeBasedTable; + +/** + * Provides deserialization for the Guava TreeBasedTable class. + * + * @author Abhishekkr3003 + */ +public class TreeBasedTableDeserializer + extends MutableTableDeserializer> { + private static final long serialVersionUID = 1L; + + public TreeBasedTableDeserializer(MapLikeType type) { + super(type); + } + + public TreeBasedTableDeserializer(MapLikeType type, KeyDeserializer rowDeserializer, + KeyDeserializer columnDeserializer, TypeDeserializer elementTypeDeserializer, + JsonDeserializer elementDeserializer, NullValueProvider nvp) { + super(type, rowDeserializer, columnDeserializer, elementTypeDeserializer, + elementDeserializer, nvp + ); + } + + @SuppressWarnings("unchecked") + @Override + protected TreeBasedTable createTable() { + TreeBasedTable naturalOrder = TreeBasedTable.create(); + return (TreeBasedTable) naturalOrder; + } + + @Override + protected JsonDeserializer _createContextual(MapLikeType type, + KeyDeserializer rowDeserializer, + KeyDeserializer columnDeserializer, TypeDeserializer typeDeserializer, + JsonDeserializer elementDeserializer, NullValueProvider nvp) { + return new TreeBasedTableDeserializer( + type, rowDeserializer, columnDeserializer, typeDeserializer, elementDeserializer, nvp); + } +} diff --git a/guava/src/main/java/com/fasterxml/jackson/datatype/guava/ser/ImmutableDoubleArraySerializer.java b/guava/src/main/java/com/fasterxml/jackson/datatype/guava/ser/ImmutableDoubleArraySerializer.java new file mode 100644 index 00000000..7cee2b9d --- /dev/null +++ b/guava/src/main/java/com/fasterxml/jackson/datatype/guava/ser/ImmutableDoubleArraySerializer.java @@ -0,0 +1,29 @@ +package com.fasterxml.jackson.datatype.guava.ser; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.ser.std.StdSerializer; +import com.google.common.primitives.ImmutableDoubleArray; + +import java.io.IOException; + +public final class ImmutableDoubleArraySerializer extends StdSerializer { + + public ImmutableDoubleArraySerializer() { + super(ImmutableDoubleArray.class); + } + + @Override + public boolean isEmpty(SerializerProvider provider, ImmutableDoubleArray value) { + return value == null || value.isEmpty(); + } + + @Override + public void serialize(ImmutableDoubleArray value, JsonGenerator generator, SerializerProvider serializerProvider) throws IOException { + generator.writeStartArray(); + for (int i = 0; i < value.length(); i++) { + generator.writeNumber(value.get(i)); + } + generator.writeEndArray(); + } +} diff --git a/guava/src/main/java/com/fasterxml/jackson/datatype/guava/ser/ImmutableIntArraySerializer.java b/guava/src/main/java/com/fasterxml/jackson/datatype/guava/ser/ImmutableIntArraySerializer.java new file mode 100644 index 00000000..f3164a3e --- /dev/null +++ b/guava/src/main/java/com/fasterxml/jackson/datatype/guava/ser/ImmutableIntArraySerializer.java @@ -0,0 +1,29 @@ +package com.fasterxml.jackson.datatype.guava.ser; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.ser.std.StdSerializer; +import com.google.common.primitives.ImmutableIntArray; + +import java.io.IOException; + +public final class ImmutableIntArraySerializer extends StdSerializer { + + public ImmutableIntArraySerializer() { + super(ImmutableIntArray.class); + } + + @Override + public boolean isEmpty(SerializerProvider provider, ImmutableIntArray value) { + return value == null || value.isEmpty(); + } + + @Override + public void serialize(ImmutableIntArray value, JsonGenerator generator, SerializerProvider serializerProvider) throws IOException { + generator.writeStartArray(); + for (int i = 0; i < value.length(); i++) { + generator.writeNumber(value.get(i)); + } + generator.writeEndArray(); + } +} diff --git a/guava/src/main/java/com/fasterxml/jackson/datatype/guava/ser/TableSerializer.java b/guava/src/main/java/com/fasterxml/jackson/datatype/guava/ser/TableSerializer.java index b02434c3..5558d29c 100644 --- a/guava/src/main/java/com/fasterxml/jackson/datatype/guava/ser/TableSerializer.java +++ b/guava/src/main/java/com/fasterxml/jackson/datatype/guava/ser/TableSerializer.java @@ -11,8 +11,10 @@ import com.fasterxml.jackson.databind.ser.ContainerSerializer; import com.fasterxml.jackson.databind.ser.ContextualSerializer; import com.fasterxml.jackson.databind.ser.std.MapSerializer; +import com.fasterxml.jackson.databind.type.MapLikeType; import com.fasterxml.jackson.databind.type.MapType; import com.fasterxml.jackson.databind.type.TypeFactory; + import com.google.common.collect.Table; /** @@ -28,7 +30,7 @@ public class TableSerializer * Type declaration that defines parameters; may be a supertype of actual * type of property being serialized. */ - private final JavaType _type; + private final MapLikeType _type; private final BeanProperty _property; @@ -45,7 +47,7 @@ public class TableSerializer /********************************************************** */ - public TableSerializer(final JavaType type) + public TableSerializer(final MapLikeType type) { super(type); _type = type; @@ -75,10 +77,11 @@ protected TableSerializer(final TableSerializer src, _valueTypeSerializer = valueTypeSerializer; _valueSerializer = (JsonSerializer) valueSerializer; + final MapLikeType columnValueType = (MapLikeType) _type.getContentType(); final MapType columnAndValueType = typeFactory.constructMapType(Map.class, - _type.containedTypeOrUnknown(1), _type.containedTypeOrUnknown(2)); + columnValueType.getKeyType(), columnValueType.getContentType()); - JsonSerializer columnAndValueSerializer = + JsonSerializer columnAndValueSerializer = MapSerializer.construct((Set) null, columnAndValueType, false, @@ -88,7 +91,7 @@ protected TableSerializer(final TableSerializer src, null); final MapType rowMapType = typeFactory.constructMapType(Map.class, - _type.containedTypeOrUnknown(0), columnAndValueType); + columnValueType.getKeyType(), columnAndValueType); _rowMapSerializer = MapSerializer.construct((Set) null, rowMapType, @@ -134,8 +137,9 @@ protected ContainerSerializer _withValueTypeSerializer(final TypeSerializer t public JsonSerializer createContextual(final SerializerProvider provider, final BeanProperty property ) throws JsonMappingException { JsonSerializer valueSer = _valueSerializer; + MapLikeType columnValueType = (MapLikeType) _type.getContentType(); if (valueSer == null) { // if type is final, can actually resolve: - final JavaType valueType = _type.containedTypeOrUnknown(2); + final JavaType valueType = columnValueType.getContentType(); if (valueType.isFinal()) { valueSer = provider.findValueSerializer(valueType, property); } @@ -145,14 +149,14 @@ else if (valueSer instanceof ContextualSerializer) { } JsonSerializer rowKeySer = _rowSerializer; if (rowKeySer == null) { - rowKeySer = provider.findKeySerializer(_type.containedTypeOrUnknown(0), property); + rowKeySer = provider.findKeySerializer(_type.getKeyType(), property); } else if (rowKeySer instanceof ContextualSerializer) { rowKeySer = ((ContextualSerializer) rowKeySer).createContextual(provider, property); } JsonSerializer columnKeySer = _columnSerializer; if (columnKeySer == null) { - columnKeySer = provider.findKeySerializer(_type.containedTypeOrUnknown(1), property); + columnKeySer = provider.findKeySerializer(columnValueType.getKeyType(), property); } else if (columnKeySer instanceof ContextualSerializer) { columnKeySer = ((ContextualSerializer) columnKeySer).createContextual(provider, property); @@ -173,7 +177,7 @@ else if (columnKeySer instanceof ContextualSerializer) { @Override public JavaType getContentType() { - return _type.getContentType(); + return _type.getContentType().getContentType(); } @Override diff --git a/guava/src/test/java/com/fasterxml/jackson/datatype/guava/ImmutableContainersTest.java b/guava/src/test/java/com/fasterxml/jackson/datatype/guava/ImmutableContainersTest.java index d66c8749..121b2227 100644 --- a/guava/src/test/java/com/fasterxml/jackson/datatype/guava/ImmutableContainersTest.java +++ b/guava/src/test/java/com/fasterxml/jackson/datatype/guava/ImmutableContainersTest.java @@ -100,7 +100,6 @@ public void testWithoutDeserializersFail() throws Exception fail("Expected failure for missing deserializer"); } catch (InvalidDefinitionException e) { _verifyImmutableException(e, ImmutableMap.class); -// verifyException(e, "Cannot find a deserializer for non-concrete"); } } diff --git a/guava/src/test/java/com/fasterxml/jackson/datatype/guava/ImmutableDoubleArrayTest.java b/guava/src/test/java/com/fasterxml/jackson/datatype/guava/ImmutableDoubleArrayTest.java new file mode 100644 index 00000000..d20f81fb --- /dev/null +++ b/guava/src/test/java/com/fasterxml/jackson/datatype/guava/ImmutableDoubleArrayTest.java @@ -0,0 +1,23 @@ +package com.fasterxml.jackson.datatype.guava; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.primitives.ImmutableDoubleArray; + +import java.io.IOException; + +public class ImmutableDoubleArrayTest extends ModuleTestBase { + + private final ObjectMapper MAPPER = mapperWithModule(); + + public void testSerialization() throws IOException { + assertEquals("[]", MAPPER.writeValueAsString(ImmutableDoubleArray.of())); + assertEquals("[-1.0,0.0,1.0,2.0,3.1]", MAPPER.writeValueAsString(ImmutableDoubleArray.of(-1, 0, 1, 2, 3.1))); + } + + public void testDeserialization() throws IOException { + assertEquals(ImmutableDoubleArray.of(), MAPPER.readValue("[]", ImmutableDoubleArray.class)); + assertEquals(ImmutableDoubleArray.of(1, 2, 3), MAPPER.readValue("[1, 2, 3]", ImmutableDoubleArray.class)); + assertEquals(ImmutableDoubleArray.of(1.1, 2.1, 3.1), MAPPER.readValue("[1.1, 2.1, 3.1]", ImmutableDoubleArray.class)); + assertEquals(ImmutableDoubleArray.of(0.0, 1234.1, -500), MAPPER.readValue("[null, \"1234.1\", -500]", ImmutableDoubleArray.class)); + } +} \ No newline at end of file diff --git a/guava/src/test/java/com/fasterxml/jackson/datatype/guava/ImmutableIntArrayTest.java b/guava/src/test/java/com/fasterxml/jackson/datatype/guava/ImmutableIntArrayTest.java new file mode 100644 index 00000000..fe960f6d --- /dev/null +++ b/guava/src/test/java/com/fasterxml/jackson/datatype/guava/ImmutableIntArrayTest.java @@ -0,0 +1,22 @@ +package com.fasterxml.jackson.datatype.guava; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.primitives.ImmutableIntArray; + +import java.io.IOException; + +public class ImmutableIntArrayTest extends ModuleTestBase { + + private final ObjectMapper MAPPER = mapperWithModule(); + + public void testSerialization() throws IOException { + assertEquals("[]", MAPPER.writeValueAsString(ImmutableIntArray.of())); + assertEquals("[-1,0,1,2,3]", MAPPER.writeValueAsString(ImmutableIntArray.of(-1, 0, 1, 2, 3))); + } + + public void testDeserialization() throws IOException { + assertEquals(ImmutableIntArray.of(), MAPPER.readValue("[]", ImmutableIntArray.class)); + assertEquals(ImmutableIntArray.of(1, 2, 3), MAPPER.readValue("[1, 2, 3]", ImmutableIntArray.class)); + assertEquals(ImmutableIntArray.of(0, 1234, -5), MAPPER.readValue("[null, \"1234\", -5]", ImmutableIntArray.class)); + } +} diff --git a/guava/src/test/java/com/fasterxml/jackson/datatype/guava/TableSerializationTest.java b/guava/src/test/java/com/fasterxml/jackson/datatype/guava/TableSerializationTest.java deleted file mode 100644 index 48354dec..00000000 --- a/guava/src/test/java/com/fasterxml/jackson/datatype/guava/TableSerializationTest.java +++ /dev/null @@ -1,164 +0,0 @@ -package com.fasterxml.jackson.datatype.guava; - -import java.io.IOException; - -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.core.type.TypeReference; - -import com.fasterxml.jackson.databind.*; -import com.fasterxml.jackson.databind.module.SimpleModule; - -import com.google.common.collect.ImmutableTable; - -public class TableSerializationTest extends ModuleTestBase -{ - private final ObjectMapper MAPPER = mapperWithModule(false); - { - MAPPER.registerModule(new ComplexKeyModule()); - } - - static class ComplexKeyModule extends SimpleModule - { - private static final long serialVersionUID = 1L; - - public ComplexKeyModule() - { - this.addKeySerializer(ComplexKey.class, new JsonSerializer() { - @Override - public void serialize( final ComplexKey value, final JsonGenerator g, final SerializerProvider provider ) - throws IOException - { - g.writeFieldName(value.getKey1() + ":" + value.getKey2()); - } - }); - - this.addKeyDeserializer(ComplexKey.class, new KeyDeserializer() { - @Override - public Object deserializeKey( final String key, final DeserializationContext ctxt ) throws IOException - { - final String[] split = key.split(":"); - return new ComplexKey(split[0], split[1]); - } - }); - } - } - - static class ComplexKey - { - private String key1; - private String key2; - - public ComplexKey( final String key1, final String key2 ) - { - super(); - this.key1 = key1; - this.key2 = key2; - } - - public String getKey1() - { - return this.key1; - } - - public void setKey1( final String key1 ) - { - this.key1 = key1; - } - - public String getKey2() - { - return this.key2; - } - - public void setKey2( final String key2 ) - { - this.key2 = key2; - } - - @Override - public int hashCode() - { - final int prime = 31; - int result = 1; - result = prime * result + ((this.key1 == null) ? 0 : this.key1.hashCode()); - result = prime * result + ((this.key2 == null) ? 0 : this.key2.hashCode()); - return result; - } - - @Override - public boolean equals( final Object obj ) - { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if ( !(obj instanceof ComplexKey)) { - return false; - } - final ComplexKey other = (ComplexKey) obj; - if (this.key1 == null) { - if (other.key1 != null) { - return false; - } - } - else if ( !this.key1.equals(other.key1)) { - return false; - } - if (this.key2 == null) { - if (other.key2 != null) { - return false; - } - } - else if ( !this.key2.equals(other.key2)) { - return false; - } - return true; - } - - } - - public void testSimpleKeyImmutableTableSerde() throws IOException - { - final ImmutableTable.Builder builder = ImmutableTable.builder(); - builder.put(Integer.valueOf(42), "column42", "some value 42"); - builder.put(Integer.valueOf(45), "column45", "some value 45"); - final ImmutableTable simpleTable = builder.build(); - - final String simpleJson = MAPPER.writeValueAsString(simpleTable); - assertEquals("{\"42\":{\"column42\":\"some value 42\"},\"45\":{\"column45\":\"some value 45\"}}", simpleJson); - - // !!! TODO: support deser - - /* - final ImmutableTable reconstitutedTable = - this.MAPPER.readValue(simpleJson, new TypeReference>() {}); - assertEquals(simpleTable, reconstitutedTable); - */ - } - - /** - * This test illustrates one way to use objects as keys in Tables. - */ - public void testComplexKeyImmutableTableSerde() throws IOException - { - final ImmutableTable.Builder ckBuilder = ImmutableTable.builder(); - ckBuilder.put(Integer.valueOf(42), new ComplexKey("field1", "field2"), "some value 42"); - ckBuilder.put(Integer.valueOf(45), new ComplexKey("field1", "field2"), "some value 45"); - final ImmutableTable complexKeyTable = ckBuilder.build(); - - final TypeReference> tableType = new TypeReference>() - {}; - - final String ckJson = this.MAPPER.writerFor(tableType).writeValueAsString(complexKeyTable); - assertEquals("{\"42\":{\"field1:field2\":\"some value 42\"},\"45\":{\"field1:field2\":\"some value 45\"}}", ckJson); - - // !!! TODO: support deser -/* - - final ImmutableTable reconstitutedTable = this.MAPPER.readValue(ckJson, tableType); - assertEquals(complexKeyTable, reconstitutedTable); - */ - } -} diff --git a/guava/src/test/java/com/fasterxml/jackson/datatype/guava/TableTest.java b/guava/src/test/java/com/fasterxml/jackson/datatype/guava/TableTest.java new file mode 100644 index 00000000..1172f5d5 --- /dev/null +++ b/guava/src/test/java/com/fasterxml/jackson/datatype/guava/TableTest.java @@ -0,0 +1,232 @@ +package com.fasterxml.jackson.datatype.guava; + +import java.io.IOException; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.core.type.TypeReference; + +import com.fasterxml.jackson.databind.*; +import com.fasterxml.jackson.databind.module.SimpleModule; + +import com.google.common.collect.HashBasedTable; +import com.google.common.collect.ImmutableTable; +import com.google.common.collect.TreeBasedTable; + +public class TableTest extends ModuleTestBase +{ + private final ObjectMapper MAPPER = builderWithModule(false) + .addModule(new ComplexKeyModule()) + .build(); + + static class ComplexKeyModule extends SimpleModule + { + private static final long serialVersionUID = 1L; + + public ComplexKeyModule() + { + this.addKeySerializer(ComplexKey.class, new JsonSerializer() { + @Override + public void serialize( final ComplexKey value, final JsonGenerator g, final SerializerProvider provider ) + throws IOException + { + g.writeFieldName(value.getKey1() + ":" + value.getKey2()); + } + }); + + this.addKeyDeserializer(ComplexKey.class, new KeyDeserializer() { + @Override + public Object deserializeKey( final String key, final DeserializationContext ctxt ) throws IOException + { + final String[] split = key.split(":"); + return new ComplexKey(split[0], split[1]); + } + }); + } + } + + static class ComplexKey implements Comparable + { + private String key1; + private String key2; + + public ComplexKey( final String key1, final String key2 ) + { + super(); + this.key1 = key1; + this.key2 = key2; + } + + public String getKey1() + { + return this.key1; + } + + public void setKey1( final String key1 ) + { + this.key1 = key1; + } + + public String getKey2() + { + return this.key2; + } + + public void setKey2( final String key2 ) + { + this.key2 = key2; + } + + @Override + public int hashCode() + { + final int prime = 31; + int result = 1; + result = prime * result + ((this.key1 == null) ? 0 : this.key1.hashCode()); + result = prime * result + ((this.key2 == null) ? 0 : this.key2.hashCode()); + return result; + } + + @Override + public boolean equals( final Object obj ) + { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if ( !(obj instanceof ComplexKey)) { + return false; + } + final ComplexKey other = (ComplexKey) obj; + if (this.key1 == null) { + if (other.key1 != null) { + return false; + } + } + else if ( !this.key1.equals(other.key1)) { + return false; + } + if (this.key2 == null) { + if (other.key2 != null) { + return false; + } + } + else if ( !this.key2.equals(other.key2)) { + return false; + } + return true; + } + + @Override + public int compareTo(ComplexKey complexKey) { + return this.key1.compareTo(complexKey.getKey1()); + } + } + + public void testSimpleKeyImmutableTableSerde() throws IOException + { + final ImmutableTable.Builder builder = ImmutableTable.builder(); + builder.put(Integer.valueOf(42), "column42", "some value 42"); + builder.put(Integer.valueOf(45), "column45", "some value 45"); + + ImmutableTable simpleTable = builder.build(); + + final String simpleJson = MAPPER.writeValueAsString(simpleTable); + assertEquals("{\"42\":{\"column42\":\"some value 42\"},\"45\":{\"column45\":\"some value 45\"}}", simpleJson); + + final ImmutableTable reconstitutedTable = + this.MAPPER.readValue(simpleJson, + new TypeReference>() { + } + ); + assertEquals(simpleTable, reconstitutedTable); + } + + public void testSimpleKeyHashBasedTableSerde() throws IOException + { + final HashBasedTable simpleTable = HashBasedTable.create(); + simpleTable.put(Integer.valueOf(42), "column42", "some value 42"); + simpleTable.put(Integer.valueOf(45), "column45", "some value 45"); + + final String simpleJson = MAPPER.writeValueAsString(simpleTable); + assertEquals("{\"42\":{\"column42\":\"some value 42\"},\"45\":{\"column45\":\"some value 45\"}}", simpleJson); + + final HashBasedTable reconstitutedTable = + this.MAPPER.readValue(simpleJson, + new TypeReference>() { + } + ); + assertEquals(simpleTable, reconstitutedTable); + } + + public void testSimpleKeyTreeBasedTableSerde() throws IOException + { + final TreeBasedTable simpleTable = TreeBasedTable.create(); + simpleTable.put(Integer.valueOf(42), "column42", "some value 42"); + simpleTable.put(Integer.valueOf(45), "column45", "some value 45"); + + final String simpleJson = MAPPER.writeValueAsString(simpleTable); + assertEquals("{\"42\":{\"column42\":\"some value 42\"},\"45\":{\"column45\":\"some value 45\"}}", simpleJson); + + final TreeBasedTable reconstitutedTable = + this.MAPPER.readValue(simpleJson, + new TypeReference>() { + } + ); + assertEquals(simpleTable, reconstitutedTable); + } + + /** + * This test illustrates one way to use objects as keys in Tables. + */ + public void testComplexKeyImmutableTableSerde() throws IOException + { + final ImmutableTable.Builder builder = ImmutableTable.builder(); + builder.put(Integer.valueOf(42), new ComplexKey("field1", "field2"), "some value 42"); + builder.put(Integer.valueOf(45), new ComplexKey("field1", "field2"), "some value 45"); + + ImmutableTable complexKeyTable = builder.build(); + + final TypeReference> tableType = new TypeReference>() + {}; + + final String ckJson = this.MAPPER.writerFor(tableType).writeValueAsString(complexKeyTable); + assertEquals("{\"42\":{\"field1:field2\":\"some value 42\"},\"45\":{\"field1:field2\":\"some value 45\"}}", ckJson); + + final ImmutableTable reconstitutedTable = this.MAPPER.readValue(ckJson, tableType); + assertEquals(complexKeyTable, reconstitutedTable); + } + + public void testComplexKeyHashBasedTableSerde() throws IOException + { + final HashBasedTable complexKeyTable = HashBasedTable.create(); + complexKeyTable.put(Integer.valueOf(42), new ComplexKey("field1", "field2"), "some value 42"); + complexKeyTable.put(Integer.valueOf(45), new ComplexKey("field1", "field2"), "some value 45"); + + final TypeReference> tableType = new TypeReference>() + {}; + + final String ckJson = this.MAPPER.writerFor(tableType).writeValueAsString(complexKeyTable); + assertEquals("{\"42\":{\"field1:field2\":\"some value 42\"},\"45\":{\"field1:field2\":\"some value 45\"}}", ckJson); + + final HashBasedTable reconstitutedTable = this.MAPPER.readValue(ckJson, tableType); + assertEquals(complexKeyTable, reconstitutedTable); + } + + public void testComplexKeyTreeTableSerde() throws IOException + { + final TreeBasedTable complexKeyTable = TreeBasedTable.create(); + complexKeyTable.put(Integer.valueOf(42), new ComplexKey("field1", "field2"), "some value 42"); + complexKeyTable.put(Integer.valueOf(45), new ComplexKey("field1", "field2"), "some value 45"); + + final TypeReference> tableType = new TypeReference>() + {}; + + final String ckJson = this.MAPPER.writerFor(tableType).writeValueAsString(complexKeyTable); + assertEquals("{\"42\":{\"field1:field2\":\"some value 42\"},\"45\":{\"field1:field2\":\"some value 45\"}}", ckJson); + + final TreeBasedTable reconstitutedTable = this.MAPPER.readValue(ckJson, tableType); + assertEquals(complexKeyTable, reconstitutedTable); + } +} diff --git a/hppc/pom.xml b/hppc/pom.xml index 21057241..2e9c90c6 100644 --- a/hppc/pom.xml +++ b/hppc/pom.xml @@ -8,7 +8,7 @@ com.fasterxml.jackson.datatype jackson-datatypes-collections - 2.18.5-SNAPSHOT + 2.19.0-SNAPSHOT jackson-datatype-hppc Jackson datatype: HPPC diff --git a/hppc/src/test/java/com/fasterxml/jackson/datatype/hppc/HppcTestBase.java b/hppc/src/test/java/com/fasterxml/jackson/datatype/hppc/HppcTestBase.java index fd5be18f..6c010472 100644 --- a/hppc/src/test/java/com/fasterxml/jackson/datatype/hppc/HppcTestBase.java +++ b/hppc/src/test/java/com/fasterxml/jackson/datatype/hppc/HppcTestBase.java @@ -4,7 +4,9 @@ import com.fasterxml.jackson.databind.ObjectMapper; -public abstract class HppcTestBase extends junit.framework.TestCase +import static org.junit.jupiter.api.Assertions.fail; + +public abstract class HppcTestBase { protected HppcTestBase() { } diff --git a/hppc/src/test/java/com/fasterxml/jackson/datatype/hppc/TestVersions.java b/hppc/src/test/java/com/fasterxml/jackson/datatype/hppc/TestVersions.java index d9ce645e..f0f25b19 100644 --- a/hppc/src/test/java/com/fasterxml/jackson/datatype/hppc/TestVersions.java +++ b/hppc/src/test/java/com/fasterxml/jackson/datatype/hppc/TestVersions.java @@ -2,6 +2,8 @@ import java.io.*; +import static org.junit.jupiter.api.Assertions.assertEquals; + public class TestVersions extends HppcTestBase { public void testMapperVersions() throws IOException diff --git a/hppc/src/test/java/com/fasterxml/jackson/datatype/hppc/deser/TestContainerDeserializers.java b/hppc/src/test/java/com/fasterxml/jackson/datatype/hppc/deser/TestContainerDeserializers.java index bae112eb..52787efc 100644 --- a/hppc/src/test/java/com/fasterxml/jackson/datatype/hppc/deser/TestContainerDeserializers.java +++ b/hppc/src/test/java/com/fasterxml/jackson/datatype/hppc/deser/TestContainerDeserializers.java @@ -4,36 +4,40 @@ import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.Assert; - import com.carrotsearch.hppc.*; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.datatype.hppc.HppcTestBase; +import static org.junit.jupiter.api.Assertions.*; + public class TestContainerDeserializers extends HppcTestBase { + + @Test public void testIntDeserializers() throws Exception { ObjectMapper mapper = mapperWithModule(); // first, direct IntArrayList array = mapper.readValue("[1,-3]", IntArrayList.class); - Assert.assertArrayEquals(new int[] { 1, -3 }, array.toArray()); + assertArrayEquals(new int[] { 1, -3 }, array.toArray()); IntHashSet set = mapper.readValue("[-1234,0]", IntHashSet.class); // 08-Apr-2014, tatu: Order indeterminate actually, has change between 0.4 and 0.5 _assertSets(new int[] { -1234, 0 }, set.toArray()); IntArrayDeque dq = mapper.readValue("[0,13]", IntArrayDeque.class); - Assert.assertArrayEquals(new int[] { -0, 13 }, dq.toArray()); + assertArrayEquals(new int[] { -0, 13 }, dq.toArray()); // then via abstract class defaulting IntIndexedContainer array2 = mapper.readValue("[1,-3]", IntIndexedContainer.class); - Assert.assertArrayEquals(new int[] { 1, -3 }, array2.toArray()); + assertArrayEquals(new int[] { 1, -3 }, array2.toArray()); IntSet set2 = mapper.readValue("[-1234,0]", IntSet.class); _assertSets(new int[] { -1234, 0 }, set2.toArray()); IntDeque dq2 = mapper.readValue("[0,13]", IntDeque.class); - Assert.assertArrayEquals(new int[] { -0, 13 }, dq2.toArray()); + assertArrayEquals(new int[] { -0, 13 }, dq2.toArray()); } private void _assertSets(int[] exp, int[] actual) @@ -46,6 +50,6 @@ private void _assertSets(int[] exp, int[] actual) Arrays.sort(exp2); Arrays.sort(act2); - Assert.assertArrayEquals(exp2, act2); + assertArrayEquals(exp2, act2); } } diff --git a/hppc/src/test/java/com/fasterxml/jackson/datatype/hppc/ser/TestContainerSerializers.java b/hppc/src/test/java/com/fasterxml/jackson/datatype/hppc/ser/TestContainerSerializers.java index 86b9bfa5..493ce20e 100644 --- a/hppc/src/test/java/com/fasterxml/jackson/datatype/hppc/ser/TestContainerSerializers.java +++ b/hppc/src/test/java/com/fasterxml/jackson/datatype/hppc/ser/TestContainerSerializers.java @@ -3,11 +3,15 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.carrotsearch.hppc.*; +import org.junit.jupiter.api.Test; import com.fasterxml.jackson.datatype.hppc.HppcTestBase; +import static org.junit.jupiter.api.Assertions.*; + public class TestContainerSerializers extends HppcTestBase { + @Test public void testByteSerializer() throws Exception { ObjectMapper mapper = mapperWithModule(); @@ -35,6 +39,7 @@ public void testByteSerializer() throws Exception */ } + @Test public void testShortSerializer() throws Exception { ObjectMapper mapper = mapperWithModule(); @@ -51,6 +56,7 @@ public void testShortSerializer() throws Exception } } + @Test public void testIntSerializer() throws Exception { ObjectMapper mapper = mapperWithModule(); @@ -67,6 +73,7 @@ public void testIntSerializer() throws Exception } } + @Test public void testLongSerializer() throws Exception { ObjectMapper mapper = mapperWithModule(); @@ -83,6 +90,7 @@ public void testLongSerializer() throws Exception } } + @Test public void testCharSerializer() throws Exception { ObjectMapper mapper = mapperWithModule(); @@ -99,6 +107,7 @@ public void testCharSerializer() throws Exception } } + @Test public void testFloatSerializer() throws Exception { ObjectMapper mapper = mapperWithModule(); @@ -117,6 +126,7 @@ public void testFloatSerializer() throws Exception */ } + @Test public void testDoubleSerializer() throws Exception { ObjectMapper mapper = mapperWithModule(); @@ -141,6 +151,7 @@ public void testDoubleSerializer() throws Exception /********************************************************************** */ + @Test public void testObjectContainerSerializer() throws Exception { ObjectMapper mapper = mapperWithModule(); @@ -153,7 +164,8 @@ public void testObjectContainerSerializer() throws Exception // TODO: polymorphic case (@JsonTypeInfo and/or default typing) } - + + @Test public void testBitSetSerializer() throws Exception { ObjectMapper mapper = mapperWithModule(); diff --git a/pcollections/pom.xml b/pcollections/pom.xml index f21e64b1..2af22470 100644 --- a/pcollections/pom.xml +++ b/pcollections/pom.xml @@ -8,7 +8,7 @@ com.fasterxml.jackson.datatype jackson-datatypes-collections - 2.18.5-SNAPSHOT + 2.19.0-SNAPSHOT jackson-datatype-pcollections Jackson datatype: pcollections diff --git a/pcollections/src/test/java/com/fasterxml/jackson/datatype/pcollections/ModuleTestBase.java b/pcollections/src/test/java/com/fasterxml/jackson/datatype/pcollections/ModuleTestBase.java index a543e9de..fada1a53 100644 --- a/pcollections/src/test/java/com/fasterxml/jackson/datatype/pcollections/ModuleTestBase.java +++ b/pcollections/src/test/java/com/fasterxml/jackson/datatype/pcollections/ModuleTestBase.java @@ -4,7 +4,7 @@ import java.util.Arrays; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.fail; public abstract class ModuleTestBase { diff --git a/pcollections/src/test/java/com/fasterxml/jackson/datatype/pcollections/TestPCollections.java b/pcollections/src/test/java/com/fasterxml/jackson/datatype/pcollections/TestPCollections.java index 21d9ab54..3ed99126 100644 --- a/pcollections/src/test/java/com/fasterxml/jackson/datatype/pcollections/TestPCollections.java +++ b/pcollections/src/test/java/com/fasterxml/jackson/datatype/pcollections/TestPCollections.java @@ -9,10 +9,11 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.exc.InvalidDefinitionException; -import org.junit.Test; import org.pcollections.*; -import static org.junit.Assert.*; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; /** * Unit tests for verifying that various PCollection types diff --git a/pom.xml b/pom.xml index 31980805..453487ab 100644 --- a/pom.xml +++ b/pom.xml @@ -1,14 +1,14 @@ - 4.0.0 + 4.0.0 com.fasterxml.jackson jackson-base - 2.18.5-SNAPSHOT + 2.19.0-SNAPSHOT com.fasterxml.jackson.datatype jackson-datatypes-collections Jackson datatypes: collections - 2.18.5-SNAPSHOT + 2.19.0-SNAPSHOT pom Parent pom for Jackson Collection datatype modules. @@ -37,7 +37,7 @@ - 2025-05-07T01:21:27Z + 2024-09-27T04:02:27Z @@ -50,21 +50,26 @@ jackson-databind - + - junit - junit + org.junit.jupiter + junit-jupiter + test + + + org.junit.jupiter + junit-jupiter-api test - + - - central-snapshots - Sonatype Central Portal (snapshots) - https://central.sonatype.com/repository/maven-snapshots + sonatype-nexus-snapshots + Sonatype Nexus Snapshots + https://oss.sonatype.org/content/repositories/snapshots false true @@ -88,11 +93,6 @@ org.apache.maven.plugins maven-surefire-plugin - - - com/fasterxml/jackson/**/failing/*.java - - @@ -105,5 +105,4 @@ -