Silin-Chen's picture
CrossSWE-Bench: current 171-instance release
0e239c6
Raw History Blame Contribute Delete
43.7 kB
diff --git a/.github/workflows/maven_release.yml b/.github/workflows/maven_release.yml
index 7efe6ca..cfb2dc3 100644
--- a/.github/workflows/maven_release.yml
+++ b/.github/workflows/maven_release.yml
@@ -15,10 +15,10 @@ jobs:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
- - name: Set up JDK 11
+ - name: Set up JDK 17
uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5.2.0
with:
- java-version: 11
+ java-version: 17
distribution: 'temurin'
- name: Cache and restore Maven packages on master
uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
@@ -59,7 +59,7 @@ jobs:
- name: Set up Maven Central Repository
uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5.2.0
with:
- java-version: 11
+ java-version: 17
distribution: 'temurin'
server-id: central
server-username: MAVEN_USERNAME
diff --git a/.github/workflows/maven_test.yml b/.github/workflows/maven_test.yml
index 15894f3..d3b05c2 100644
--- a/.github/workflows/maven_test.yml
+++ b/.github/workflows/maven_test.yml
@@ -17,10 +17,10 @@ jobs:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
- - name: Set up JDK 11
+ - name: Set up JDK 17
uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5.2.0
with:
- java-version: 11
+ java-version: 17
distribution: 'temurin'
- name: Cache and restore Maven packages on master
uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
diff --git a/pom.xml b/pom.xml
index 58ff5f8..9ac7ef4 100644
--- a/pom.xml
+++ b/pom.xml
@@ -36,7 +36,8 @@
<!-- region Dependency Versions -->
<!-- Validator 8+ requires Java 11, Validator 9+ requires Java 17. -->
<hibernate-validator.version>7.0.5.Final</hibernate-validator.version>
- <jackson-bom.version>2.21.1</jackson-bom.version>
+ <jackson2-bom.version>2.21.1</jackson2-bom.version>
+ <jackson3-bom.version>3.0.4</jackson3-bom.version>
<javax-validation-api.version>2.0.1.Final</javax-validation-api.version>
<jakarta-validation-api.version>3.1.1</jakarta-validation-api.version>
<junit.version>5.14.3</junit.version>
@@ -60,10 +61,17 @@
<dependency>
<groupId>com.fasterxml.jackson</groupId>
<artifactId>jackson-bom</artifactId>
- <version>${jackson-bom.version}</version>
+ <version>${jackson2-bom.version}</version>
<scope>import</scope>
<type>pom</type>
</dependency>
+ <dependency>
+ <groupId>tools.jackson</groupId>
+ <artifactId>jackson-bom</artifactId>
+ <version>${jackson3-bom.version}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
@@ -78,6 +86,12 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>tools.jackson.core</groupId>
+ <artifactId>jackson-databind</artifactId>
+ <scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
@@ -166,6 +180,20 @@
<multiReleaseOutput>true</multiReleaseOutput>
</configuration>
</execution>
+ <execution>
+ <id>compile-java-17</id>
+ <phase>compile</phase>
+ <goals>
+ <goal>compile</goal>
+ </goals>
+ <configuration>
+ <release>17</release>
+ <compileSourceRoots>
+ <compileSourceRoot>${project.basedir}/src/main/java17</compileSourceRoot>
+ </compileSourceRoots>
+ <multiReleaseOutput>true</multiReleaseOutput>
+ </configuration>
+ </execution>
</executions>
</plugin>
<plugin>
@@ -233,7 +261,7 @@
</execution>
</executions>
<configuration>
- <source>${java.version}</source>
+ <source>17</source>
<doclint>none</doclint>
<detectJavaApiLink>false</detectJavaApiLink>
<failOnWarnings>false</failOnWarnings>
diff --git a/src/it/jakarta-jar-classpath/pom.xml b/src/it/jakarta-jar-classpath/pom.xml
index 0bf20c8..0cc50f1 100644
--- a/src/it/jakarta-jar-classpath/pom.xml
+++ b/src/it/jakarta-jar-classpath/pom.xml
@@ -25,6 +25,11 @@
<artifactId>jakarta.validation-api</artifactId>
<version>3.1.1</version>
</dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-databind</artifactId>
+ <version>2.21.1</version>
+ </dependency>
</dependencies>
<build>
diff --git a/src/it/jakarta-jar-modulepath/pom.xml b/src/it/jakarta-jar-modulepath/pom.xml
index 841640e..73e155b 100644
--- a/src/it/jakarta-jar-modulepath/pom.xml
+++ b/src/it/jakarta-jar-modulepath/pom.xml
@@ -25,6 +25,11 @@
<artifactId>jakarta.validation-api</artifactId>
<version>3.1.1</version>
</dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-databind</artifactId>
+ <version>2.21.1</version>
+ </dependency>
</dependencies>
<build>
diff --git a/src/it/jakarta-jlink/pom.xml b/src/it/jakarta-jlink/pom.xml
index 800e441..ccce134 100644
--- a/src/it/jakarta-jlink/pom.xml
+++ b/src/it/jakarta-jlink/pom.xml
@@ -25,6 +25,11 @@
<artifactId>jakarta.validation-api</artifactId>
<version>3.1.1</version>
</dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-databind</artifactId>
+ <version>2.21.1</version>
+ </dependency>
</dependencies>
<build>
diff --git a/src/main/java/org/openapitools/jackson/nullable/JsonNullableBeanPropertyWriter.java b/src/main/java/org/openapitools/jackson/nullable/JsonNullableJackson2BeanPropertyWriter.java
similarity index 69%
rename from src/main/java/org/openapitools/jackson/nullable/JsonNullableBeanPropertyWriter.java
rename to src/main/java/org/openapitools/jackson/nullable/JsonNullableJackson2BeanPropertyWriter.java
index 1f8fab6..61f8c1f 100644
--- a/src/main/java/org/openapitools/jackson/nullable/JsonNullableBeanPropertyWriter.java
+++ b/src/main/java/org/openapitools/jackson/nullable/JsonNullableJackson2BeanPropertyWriter.java
@@ -6,26 +6,26 @@ import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.BeanPropertyWriter;
import com.fasterxml.jackson.databind.util.NameTransformer;
-public class JsonNullableBeanPropertyWriter extends BeanPropertyWriter
+public class JsonNullableJackson2BeanPropertyWriter extends BeanPropertyWriter
{
private static final long serialVersionUID = 1L;
- protected JsonNullableBeanPropertyWriter(BeanPropertyWriter base) {
+ protected JsonNullableJackson2BeanPropertyWriter(BeanPropertyWriter base) {
super(base);
}
- protected JsonNullableBeanPropertyWriter(BeanPropertyWriter base, PropertyName newName) {
+ protected JsonNullableJackson2BeanPropertyWriter(BeanPropertyWriter base, PropertyName newName) {
super(base, newName);
}
@Override
protected BeanPropertyWriter _new(PropertyName newName) {
- return new JsonNullableBeanPropertyWriter(this, newName);
+ return new JsonNullableJackson2BeanPropertyWriter(this, newName);
}
@Override
public BeanPropertyWriter unwrappingWriter(NameTransformer unwrapper) {
- return new UnwrappingJsonNullableBeanPropertyWriter(this, unwrapper);
+ return new UnwrappingJsonNullableJackson2BeanPropertyWriter(this, unwrapper);
}
@Override
diff --git a/src/main/java/org/openapitools/jackson/nullable/JsonNullableBeanSerializerModifier.java b/src/main/java/org/openapitools/jackson/nullable/JsonNullableJackson2BeanSerializerModifier.java
similarity index 83%
rename from src/main/java/org/openapitools/jackson/nullable/JsonNullableBeanSerializerModifier.java
rename to src/main/java/org/openapitools/jackson/nullable/JsonNullableJackson2BeanSerializerModifier.java
index 75f4a28..6b755c8 100644
--- a/src/main/java/org/openapitools/jackson/nullable/JsonNullableBeanSerializerModifier.java
+++ b/src/main/java/org/openapitools/jackson/nullable/JsonNullableJackson2BeanSerializerModifier.java
@@ -8,7 +8,7 @@ import com.fasterxml.jackson.databind.ser.BeanSerializerModifier;
import java.util.List;
-public class JsonNullableBeanSerializerModifier extends BeanSerializerModifier
+public class JsonNullableJackson2BeanSerializerModifier extends BeanSerializerModifier
{
@Override
public List<BeanPropertyWriter> changeProperties(SerializationConfig config,
@@ -19,7 +19,7 @@ public class JsonNullableBeanSerializerModifier extends BeanSerializerModifier
final BeanPropertyWriter writer = beanProperties.get(i);
JavaType type = writer.getType();
if (type.isTypeOrSubTypeOf(JsonNullable.class)) {
- beanProperties.set(i, new JsonNullableBeanPropertyWriter(writer));
+ beanProperties.set(i, new JsonNullableJackson2BeanPropertyWriter(writer));
}
}
return beanProperties;
diff --git a/src/main/java/org/openapitools/jackson/nullable/JsonNullableDeserializer.java b/src/main/java/org/openapitools/jackson/nullable/JsonNullableJackson2Deserializer.java
similarity index 85%
rename from src/main/java/org/openapitools/jackson/nullable/JsonNullableDeserializer.java
rename to src/main/java/org/openapitools/jackson/nullable/JsonNullableJackson2Deserializer.java
index 9ebee24..01eb04a 100644
--- a/src/main/java/org/openapitools/jackson/nullable/JsonNullableDeserializer.java
+++ b/src/main/java/org/openapitools/jackson/nullable/JsonNullableJackson2Deserializer.java
@@ -14,7 +14,7 @@ import com.fasterxml.jackson.databind.type.ReferenceType;
import java.io.IOException;
-public class JsonNullableDeserializer extends ReferenceTypeDeserializer<JsonNullable<Object>> {
+public class JsonNullableJackson2Deserializer extends ReferenceTypeDeserializer<JsonNullable<Object>> {
private static final long serialVersionUID = 1L;
@@ -25,8 +25,8 @@ public class JsonNullableDeserializer extends ReferenceTypeDeserializer<JsonNull
/* Life-cycle
/**********************************************************
*/
- public JsonNullableDeserializer(JavaType fullType, ValueInstantiator inst,
- TypeDeserializer typeDeser, JsonDeserializer<?> deser) {
+ public JsonNullableJackson2Deserializer(JavaType fullType, ValueInstantiator inst,
+ TypeDeserializer typeDeser, JsonDeserializer<?> deser) {
super(fullType, inst, typeDeser, deser);
if (fullType instanceof ReferenceType && ((ReferenceType) fullType).getReferencedType() != null) {
this.isStringDeserializer = ((ReferenceType) fullType).getReferencedType().isTypeOrSubTypeOf(String.class);
@@ -52,8 +52,8 @@ public class JsonNullableDeserializer extends ReferenceTypeDeserializer<JsonNull
}
@Override
- public JsonNullableDeserializer withResolved(TypeDeserializer typeDeser, JsonDeserializer<?> valueDeser) {
- return new JsonNullableDeserializer(_fullType, _valueInstantiator,
+ public JsonNullableJackson2Deserializer withResolved(TypeDeserializer typeDeser, JsonDeserializer<?> valueDeser) {
+ return new JsonNullableJackson2Deserializer(_fullType, _valueInstantiator,
typeDeser, valueDeser);
}
diff --git a/src/main/java/org/openapitools/jackson/nullable/JsonNullableDeserializers.java b/src/main/java/org/openapitools/jackson/nullable/JsonNullableJackson2Deserializers.java
similarity index 82%
rename from src/main/java/org/openapitools/jackson/nullable/JsonNullableDeserializers.java
rename to src/main/java/org/openapitools/jackson/nullable/JsonNullableJackson2Deserializers.java
index 04764e9..54a5d3b 100644
--- a/src/main/java/org/openapitools/jackson/nullable/JsonNullableDeserializers.java
+++ b/src/main/java/org/openapitools/jackson/nullable/JsonNullableJackson2Deserializers.java
@@ -7,12 +7,12 @@ import com.fasterxml.jackson.databind.deser.Deserializers;
import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
import com.fasterxml.jackson.databind.type.ReferenceType;
-public class JsonNullableDeserializers extends Deserializers.Base {
+public class JsonNullableJackson2Deserializers extends Deserializers.Base {
@Override
public JsonDeserializer<?> findReferenceDeserializer(ReferenceType refType,
DeserializationConfig config, BeanDescription beanDesc,
TypeDeserializer contentTypeDeserializer, JsonDeserializer<?> contentDeserializer) {
- return (refType.hasRawClass(JsonNullable.class)) ? new JsonNullableDeserializer(refType, null, contentTypeDeserializer,contentDeserializer) : null;
+ return (refType.hasRawClass(JsonNullable.class)) ? new JsonNullableJackson2Deserializer(refType, null, contentTypeDeserializer,contentDeserializer) : null;
}
}
diff --git a/src/main/java/org/openapitools/jackson/nullable/JsonNullableSerializer.java b/src/main/java/org/openapitools/jackson/nullable/JsonNullableJackson2Serializer.java
similarity index 73%
rename from src/main/java/org/openapitools/jackson/nullable/JsonNullableSerializer.java
rename to src/main/java/org/openapitools/jackson/nullable/JsonNullableJackson2Serializer.java
index b2957ae..038589e 100644
--- a/src/main/java/org/openapitools/jackson/nullable/JsonNullableSerializer.java
+++ b/src/main/java/org/openapitools/jackson/nullable/JsonNullableJackson2Serializer.java
@@ -7,7 +7,7 @@ import com.fasterxml.jackson.databind.ser.std.ReferenceTypeSerializer;
import com.fasterxml.jackson.databind.type.ReferenceType;
import com.fasterxml.jackson.databind.util.NameTransformer;
-public class JsonNullableSerializer extends ReferenceTypeSerializer<JsonNullable<?>> {
+public class JsonNullableJackson2Serializer extends ReferenceTypeSerializer<JsonNullable<?>> {
private static final long serialVersionUID = 1L;
@@ -17,14 +17,14 @@ public class JsonNullableSerializer extends ReferenceTypeSerializer<JsonNullable
/**********************************************************
*/
- protected JsonNullableSerializer(ReferenceType fullType, boolean staticTyping,
- TypeSerializer vts, JsonSerializer<Object> ser) {
+ protected JsonNullableJackson2Serializer(ReferenceType fullType, boolean staticTyping,
+ TypeSerializer vts, JsonSerializer<Object> ser) {
super(fullType, staticTyping, vts, ser);
}
- protected JsonNullableSerializer(JsonNullableSerializer base, BeanProperty property,
- TypeSerializer vts, JsonSerializer<?> valueSer, NameTransformer unwrapper,
- Object suppressableValue)
+ protected JsonNullableJackson2Serializer(JsonNullableJackson2Serializer base, BeanProperty property,
+ TypeSerializer vts, JsonSerializer<?> valueSer, NameTransformer unwrapper,
+ Object suppressableValue)
{
// Keep suppressNulls to false to always serialize JsonNullable[null]
super(base, property, vts, valueSer, unwrapper,
@@ -36,7 +36,7 @@ public class JsonNullableSerializer extends ReferenceTypeSerializer<JsonNullable
TypeSerializer vts, JsonSerializer<?> valueSer,
NameTransformer unwrapper)
{
- return new JsonNullableSerializer(this, prop, vts, valueSer, unwrapper,
+ return new JsonNullableJackson2Serializer(this, prop, vts, valueSer, unwrapper,
_suppressableValue);
}
@@ -44,7 +44,7 @@ public class JsonNullableSerializer extends ReferenceTypeSerializer<JsonNullable
public ReferenceTypeSerializer<JsonNullable<?>> withContentInclusion(Object suppressableValue,
boolean suppressNulls)
{
- return new JsonNullableSerializer(this, _property, _valueTypeSerializer,
+ return new JsonNullableJackson2Serializer(this, _property, _valueTypeSerializer,
_valueSerializer, _unwrapper,
suppressableValue);
}
diff --git a/src/main/java/org/openapitools/jackson/nullable/JsonNullableSerializers.java b/src/main/java/org/openapitools/jackson/nullable/JsonNullableJackson2Serializers.java
similarity index 88%
rename from src/main/java/org/openapitools/jackson/nullable/JsonNullableSerializers.java
rename to src/main/java/org/openapitools/jackson/nullable/JsonNullableJackson2Serializers.java
index db6b1ff..cb92ed0 100644
--- a/src/main/java/org/openapitools/jackson/nullable/JsonNullableSerializers.java
+++ b/src/main/java/org/openapitools/jackson/nullable/JsonNullableJackson2Serializers.java
@@ -8,7 +8,7 @@ import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
import com.fasterxml.jackson.databind.ser.Serializers;
import com.fasterxml.jackson.databind.type.ReferenceType;
-public class JsonNullableSerializers extends Serializers.Base {
+public class JsonNullableJackson2Serializers extends Serializers.Base {
@Override
public JsonSerializer<?> findReferenceSerializer(SerializationConfig config,
@@ -17,7 +17,7 @@ public class JsonNullableSerializers extends Serializers.Base {
if (JsonNullable.class.isAssignableFrom(refType.getRawClass())) {
boolean staticTyping = (contentTypeSerializer == null)
&& config.isEnabled(MapperFeature.USE_STATIC_TYPING);
- return new JsonNullableSerializer(refType, staticTyping,
+ return new JsonNullableJackson2Serializer(refType, staticTyping,
contentTypeSerializer, contentValueSerializer);
}
return null;
diff --git a/src/main/java/org/openapitools/jackson/nullable/JsonNullableTypeModifier.java b/src/main/java/org/openapitools/jackson/nullable/JsonNullableJackson2TypeModifier.java
similarity index 92%
rename from src/main/java/org/openapitools/jackson/nullable/JsonNullableTypeModifier.java
rename to src/main/java/org/openapitools/jackson/nullable/JsonNullableJackson2TypeModifier.java
index 7e7663d..0f392b3 100644
--- a/src/main/java/org/openapitools/jackson/nullable/JsonNullableTypeModifier.java
+++ b/src/main/java/org/openapitools/jackson/nullable/JsonNullableJackson2TypeModifier.java
@@ -8,7 +8,7 @@ import com.fasterxml.jackson.databind.type.TypeModifier;
import java.lang.reflect.Type;
-public class JsonNullableTypeModifier extends TypeModifier {
+public class JsonNullableJackson2TypeModifier extends TypeModifier {
@Override
public JavaType modifyType(JavaType type, Type jdkType, TypeBindings bindings, TypeFactory typeFactory)
diff --git a/src/main/java/org/openapitools/jackson/nullable/JsonNullableJackson3BeanPropertyWriter.java b/src/main/java/org/openapitools/jackson/nullable/JsonNullableJackson3BeanPropertyWriter.java
new file mode 100644
index 0000000..4c1d88b
--- /dev/null
+++ b/src/main/java/org/openapitools/jackson/nullable/JsonNullableJackson3BeanPropertyWriter.java
@@ -0,0 +1,38 @@
+package org.openapitools.jackson.nullable;
+
+import tools.jackson.core.JsonGenerator;
+import tools.jackson.databind.PropertyName;
+import tools.jackson.databind.SerializationContext;
+import tools.jackson.databind.ser.BeanPropertyWriter;
+import tools.jackson.databind.util.NameTransformer;
+
+public class JsonNullableJackson3BeanPropertyWriter extends BeanPropertyWriter {
+
+ protected JsonNullableJackson3BeanPropertyWriter(BeanPropertyWriter base) {
+ super(base);
+ }
+
+ protected JsonNullableJackson3BeanPropertyWriter(BeanPropertyWriter base, PropertyName newName) {
+ super(base, newName);
+ }
+
+ @Override
+ protected BeanPropertyWriter _new(PropertyName newName) {
+ return new JsonNullableJackson3BeanPropertyWriter(this, newName);
+ }
+
+ @Override
+ public BeanPropertyWriter unwrappingWriter(NameTransformer unwrapper) {
+ return new UnwrappingJsonNullableJackson3BeanPropertyWriter(this, unwrapper);
+ }
+
+ @Override
+ public void serializeAsProperty(Object bean, JsonGenerator jgen, SerializationContext ctxt) throws Exception {
+ Object value = get(bean);
+ if (JsonNullable.undefined().equals(value) || (_nullSerializer == null && value == null)) {
+ return;
+ }
+ super.serializeAsProperty(bean, jgen, ctxt);
+ }
+
+}
\ No newline at end of file
diff --git a/src/main/java/org/openapitools/jackson/nullable/JsonNullableJackson3Deserializer.java b/src/main/java/org/openapitools/jackson/nullable/JsonNullableJackson3Deserializer.java
new file mode 100644
index 0000000..a01ac80
--- /dev/null
+++ b/src/main/java/org/openapitools/jackson/nullable/JsonNullableJackson3Deserializer.java
@@ -0,0 +1,93 @@
+package org.openapitools.jackson.nullable;
+
+
+import tools.jackson.core.JacksonException;
+import tools.jackson.core.JsonParser;
+import tools.jackson.core.JsonToken;
+import tools.jackson.databind.DeserializationConfig;
+import tools.jackson.databind.DeserializationContext;
+import tools.jackson.databind.JavaType;
+import tools.jackson.databind.ValueDeserializer;
+import tools.jackson.databind.deser.ValueInstantiator;
+import tools.jackson.databind.deser.std.ReferenceTypeDeserializer;
+import tools.jackson.databind.jsontype.TypeDeserializer;
+import tools.jackson.databind.type.ReferenceType;
+
+public class JsonNullableJackson3Deserializer extends ReferenceTypeDeserializer<JsonNullable<Object>> {
+
+
+ private boolean isStringDeserializer = false;
+
+ /*
+ /**********************************************************
+ /* Life-cycle
+ /**********************************************************
+ */
+ public JsonNullableJackson3Deserializer(JavaType fullType, ValueInstantiator inst,
+ TypeDeserializer typeDeser, ValueDeserializer<?> deser) {
+ super(fullType, inst, typeDeser, deser);
+ if (fullType instanceof ReferenceType && ((ReferenceType) fullType).getReferencedType() != null) {
+ this.isStringDeserializer = ((ReferenceType) fullType).getReferencedType().isTypeOrSubTypeOf(String.class);
+ }
+ }
+
+ /*
+ /**********************************************************
+ /* Abstract method implementations
+ /**********************************************************
+ */
+
+ @Override
+ public JsonNullable<Object> deserialize(JsonParser p, DeserializationContext ctxt) throws JacksonException {
+ JsonToken t = p.currentToken();
+ if (t == JsonToken.VALUE_STRING && !isStringDeserializer) {
+ String str = p.getString().trim();
+ if (str.isEmpty()) {
+ return JsonNullable.undefined();
+ }
+ }
+ return super.deserialize(p, ctxt);
+ }
+
+ @Override
+ protected ReferenceTypeDeserializer<JsonNullable<Object>> withResolved(TypeDeserializer typeDeser, ValueDeserializer<?> valueDeser) {
+ return new JsonNullableJackson3Deserializer(_fullType, _valueInstantiator,
+ typeDeser, valueDeser);
+ }
+
+ @Override
+ public Object getAbsentValue(DeserializationContext ctxt) {
+ return JsonNullable.undefined();
+ }
+
+ @Override
+ public JsonNullable<Object> getNullValue(DeserializationContext ctxt) {
+ return JsonNullable.of(null);
+ }
+
+ @Override
+ public Object getEmptyValue(DeserializationContext ctxt) {
+ return JsonNullable.undefined();
+ }
+
+ @Override
+ public JsonNullable<Object> referenceValue(Object contents) {
+ return JsonNullable.of(contents);
+ }
+
+ @Override
+ public Object getReferenced(JsonNullable<Object> reference) {
+ return reference.get();
+ }
+
+ @Override
+ public JsonNullable<Object> updateReference(JsonNullable<Object> reference, Object contents) {
+ return JsonNullable.of(contents);
+ }
+
+ @Override
+ public Boolean supportsUpdate(DeserializationConfig config) {
+ // yes; regardless of value deserializer reference itself may be updated
+ return Boolean.TRUE;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/org/openapitools/jackson/nullable/JsonNullableJackson3Deserializers.java b/src/main/java/org/openapitools/jackson/nullable/JsonNullableJackson3Deserializers.java
new file mode 100644
index 0000000..7ef853c
--- /dev/null
+++ b/src/main/java/org/openapitools/jackson/nullable/JsonNullableJackson3Deserializers.java
@@ -0,0 +1,23 @@
+package org.openapitools.jackson.nullable;
+
+import tools.jackson.databind.DeserializationConfig;
+import tools.jackson.databind.ValueDeserializer;
+import tools.jackson.databind.BeanDescription.Supplier;
+import tools.jackson.databind.deser.Deserializers;
+import tools.jackson.databind.jsontype.TypeDeserializer;
+import tools.jackson.databind.type.ReferenceType;
+
+public class JsonNullableJackson3Deserializers extends Deserializers.Base {
+
+ @Override
+ public ValueDeserializer<?> findReferenceDeserializer(ReferenceType refType,
+ DeserializationConfig config, Supplier beanDescRef,
+ TypeDeserializer contentTypeDeserializer, ValueDeserializer<?> contentDeserializer) {
+ return (refType.hasRawClass(JsonNullable.class)) ? new JsonNullableJackson3Deserializer(refType, null, contentTypeDeserializer,contentDeserializer) : null;
+ }
+
+ @Override
+ public boolean hasDeserializerFor(DeserializationConfig config, Class<?> valueType) {
+ return JsonNullable.class.equals(valueType);
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/org/openapitools/jackson/nullable/JsonNullableJackson3Module.java b/src/main/java/org/openapitools/jackson/nullable/JsonNullableJackson3Module.java
new file mode 100644
index 0000000..e9abf49
--- /dev/null
+++ b/src/main/java/org/openapitools/jackson/nullable/JsonNullableJackson3Module.java
@@ -0,0 +1,39 @@
+package org.openapitools.jackson.nullable;
+
+import tools.jackson.core.Version;
+import tools.jackson.core.json.PackageVersion;
+import tools.jackson.databind.JacksonModule;
+
+public class JsonNullableJackson3Module extends JacksonModule {
+
+ private final String NAME = "JsonNullableModule";
+
+ @Override
+ public void setupModule(SetupContext context) {
+ context.addSerializers(new JsonNullableJackson3Serializers());
+ context.addDeserializers(new JsonNullableJackson3Deserializers());
+ // Modify type info for JsonNullable
+ context.addTypeModifier(new JsonNullableJackson3TypeModifier());
+ context.addSerializerModifier(new JsonNullableJackson3ValueSerializerModifier());
+ }
+
+ @Override
+ public Version version() {
+ return PackageVersion.VERSION;
+ }
+
+ @Override
+ public int hashCode() {
+ return NAME.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ return this == o;
+ }
+
+ @Override
+ public String getModuleName() {
+ return NAME;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/org/openapitools/jackson/nullable/JsonNullableJackson3Serializer.java b/src/main/java/org/openapitools/jackson/nullable/JsonNullableJackson3Serializer.java
new file mode 100644
index 0000000..5c91ac2
--- /dev/null
+++ b/src/main/java/org/openapitools/jackson/nullable/JsonNullableJackson3Serializer.java
@@ -0,0 +1,72 @@
+package org.openapitools.jackson.nullable;
+
+import tools.jackson.databind.BeanProperty;
+import tools.jackson.databind.ValueSerializer;
+import tools.jackson.databind.jsontype.TypeSerializer;
+import tools.jackson.databind.ser.std.ReferenceTypeSerializer;
+import tools.jackson.databind.type.ReferenceType;
+import tools.jackson.databind.util.NameTransformer;
+
+public class JsonNullableJackson3Serializer extends ReferenceTypeSerializer<JsonNullable<?>> {
+
+ private static final long serialVersionUID = 1L;
+
+ /*
+ /**********************************************************
+ /* Constructors, factory methods
+ /**********************************************************
+ */
+
+ protected JsonNullableJackson3Serializer(ReferenceType fullType, boolean staticTyping,
+ TypeSerializer vts, ValueSerializer<Object> ser) {
+ super(fullType, staticTyping, vts, ser);
+ }
+
+ protected JsonNullableJackson3Serializer(JsonNullableJackson3Serializer base, BeanProperty property,
+ TypeSerializer vts, ValueSerializer<?> valueSer, NameTransformer unwrapper,
+ Object suppressableValue)
+ {
+ // Keep suppressNulls to false to always serialize JsonNullable[null]
+ super(base, property, vts, valueSer, unwrapper,
+ suppressableValue, false);
+ }
+
+ @Override
+ protected ReferenceTypeSerializer<JsonNullable<?>> withResolved(BeanProperty prop,
+ TypeSerializer vts, ValueSerializer<?> valueSer,
+ NameTransformer unwrapper)
+ {
+ return new JsonNullableJackson3Serializer(this, prop, vts, valueSer, unwrapper,
+ _suppressableValue);
+ }
+
+ @Override
+ public ReferenceTypeSerializer<JsonNullable<?>> withContentInclusion(Object suppressableValue,
+ boolean suppressNulls)
+ {
+ return new JsonNullableJackson3Serializer(this, _property, _valueTypeSerializer,
+ _valueSerializer, _unwrapper,
+ suppressableValue);
+ }
+
+ /*
+ /**********************************************************
+ /* Abstract method impls
+ /**********************************************************
+ */
+
+ @Override
+ protected boolean _isValuePresent(JsonNullable<?> value) {
+ return value.isPresent();
+ }
+
+ @Override
+ protected Object _getReferenced(JsonNullable<?> value) {
+ return value.get();
+ }
+
+ @Override
+ protected Object _getReferencedIfPresent(JsonNullable<?> value) {
+ return value.isPresent() ? value.get() : null;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/org/openapitools/jackson/nullable/JsonNullableJackson3Serializers.java b/src/main/java/org/openapitools/jackson/nullable/JsonNullableJackson3Serializers.java
new file mode 100644
index 0000000..fdf826c
--- /dev/null
+++ b/src/main/java/org/openapitools/jackson/nullable/JsonNullableJackson3Serializers.java
@@ -0,0 +1,27 @@
+package org.openapitools.jackson.nullable;
+
+
+import com.fasterxml.jackson.annotation.JsonFormat.Value;
+
+import tools.jackson.databind.MapperFeature;
+import tools.jackson.databind.SerializationConfig;
+import tools.jackson.databind.ValueSerializer;
+import tools.jackson.databind.BeanDescription.Supplier;
+import tools.jackson.databind.jsontype.TypeSerializer;
+import tools.jackson.databind.ser.Serializers;
+import tools.jackson.databind.type.ReferenceType;
+
+public class JsonNullableJackson3Serializers extends Serializers.Base {
+ @Override
+ public ValueSerializer<?> findReferenceSerializer(SerializationConfig config,
+ ReferenceType refType, Supplier beanDescRef, Value formatOverrides,
+ TypeSerializer contentTypeSerializer, ValueSerializer<Object> contentValueSerializer) {
+ if (JsonNullable.class.isAssignableFrom(refType.getRawClass())) {
+ boolean staticTyping = (contentTypeSerializer == null)
+ && config.isEnabled(MapperFeature.USE_STATIC_TYPING);
+ return new JsonNullableJackson3Serializer(refType, staticTyping,
+ contentTypeSerializer, contentValueSerializer);
+ }
+ return null;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/org/openapitools/jackson/nullable/JsonNullableJackson3TypeModifier.java b/src/main/java/org/openapitools/jackson/nullable/JsonNullableJackson3TypeModifier.java
new file mode 100644
index 0000000..8a4a63c
--- /dev/null
+++ b/src/main/java/org/openapitools/jackson/nullable/JsonNullableJackson3TypeModifier.java
@@ -0,0 +1,30 @@
+package org.openapitools.jackson.nullable;
+
+import tools.jackson.databind.JavaType;
+import tools.jackson.databind.type.ReferenceType;
+import tools.jackson.databind.type.TypeBindings;
+import tools.jackson.databind.type.TypeFactory;
+import tools.jackson.databind.type.TypeModifier;
+
+import java.lang.reflect.Type;
+
+public class JsonNullableJackson3TypeModifier extends TypeModifier {
+
+ @Override
+ public JavaType modifyType(JavaType type, Type jdkType, TypeBindings bindings, TypeFactory typeFactory)
+ {
+ if (type.isReferenceType() || type.isContainerType()) {
+ return type;
+ }
+ final Class<?> raw = type.getRawClass();
+
+ JavaType refType;
+
+ if (raw == JsonNullable.class) {
+ refType = type.containedTypeOrUnknown(0);
+ } else {
+ return type;
+ }
+ return ReferenceType.upgradeFrom(type, refType);
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/org/openapitools/jackson/nullable/JsonNullableJackson3ValueSerializerModifier.java b/src/main/java/org/openapitools/jackson/nullable/JsonNullableJackson3ValueSerializerModifier.java
new file mode 100644
index 0000000..c20b1fb
--- /dev/null
+++ b/src/main/java/org/openapitools/jackson/nullable/JsonNullableJackson3ValueSerializerModifier.java
@@ -0,0 +1,27 @@
+package org.openapitools.jackson.nullable;
+
+import tools.jackson.databind.JavaType;
+import tools.jackson.databind.SerializationConfig;
+import tools.jackson.databind.BeanDescription.Supplier;
+import tools.jackson.databind.ser.BeanPropertyWriter;
+import tools.jackson.databind.ser.ValueSerializerModifier;
+
+import java.util.List;
+
+public class JsonNullableJackson3ValueSerializerModifier extends ValueSerializerModifier
+{
+ @Override
+ public List<BeanPropertyWriter> changeProperties(SerializationConfig config,
+ Supplier beanDesc,
+ List<BeanPropertyWriter> beanProperties)
+ {
+ for (int i = 0; i < beanProperties.size(); ++i) {
+ final BeanPropertyWriter writer = beanProperties.get(i);
+ JavaType type = writer.getType();
+ if (type.isTypeOrSubTypeOf(JsonNullable.class)) {
+ beanProperties.set(i, new JsonNullableJackson3BeanPropertyWriter(writer));
+ }
+ }
+ return beanProperties;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/org/openapitools/jackson/nullable/JsonNullableModule.java b/src/main/java/org/openapitools/jackson/nullable/JsonNullableModule.java
index 2101f83..0b9fdd0 100644
--- a/src/main/java/org/openapitools/jackson/nullable/JsonNullableModule.java
+++ b/src/main/java/org/openapitools/jackson/nullable/JsonNullableModule.java
@@ -10,11 +10,11 @@ public class JsonNullableModule extends Module {
@Override
public void setupModule(SetupContext context) {
- context.addSerializers(new JsonNullableSerializers());
- context.addDeserializers(new JsonNullableDeserializers());
+ context.addSerializers(new JsonNullableJackson2Serializers());
+ context.addDeserializers(new JsonNullableJackson2Deserializers());
// Modify type info for JsonNullable
- context.addTypeModifier(new JsonNullableTypeModifier());
- context.addBeanSerializerModifier(new JsonNullableBeanSerializerModifier());
+ context.addTypeModifier(new JsonNullableJackson2TypeModifier());
+ context.addBeanSerializerModifier(new JsonNullableJackson2BeanSerializerModifier());
}
@Override
diff --git a/src/main/java/org/openapitools/jackson/nullable/UnwrappingJsonNullableBeanPropertyWriter.java b/src/main/java/org/openapitools/jackson/nullable/UnwrappingJsonNullableJackson2BeanPropertyWriter.java
similarity index 63%
rename from src/main/java/org/openapitools/jackson/nullable/UnwrappingJsonNullableBeanPropertyWriter.java
rename to src/main/java/org/openapitools/jackson/nullable/UnwrappingJsonNullableJackson2BeanPropertyWriter.java
index a9d1052..5235138 100644
--- a/src/main/java/org/openapitools/jackson/nullable/UnwrappingJsonNullableBeanPropertyWriter.java
+++ b/src/main/java/org/openapitools/jackson/nullable/UnwrappingJsonNullableJackson2BeanPropertyWriter.java
@@ -7,24 +7,24 @@ import com.fasterxml.jackson.databind.ser.BeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter;
import com.fasterxml.jackson.databind.util.NameTransformer;
-public class UnwrappingJsonNullableBeanPropertyWriter extends UnwrappingBeanPropertyWriter
+public class UnwrappingJsonNullableJackson2BeanPropertyWriter extends UnwrappingBeanPropertyWriter
{
private static final long serialVersionUID = 1L;
- public UnwrappingJsonNullableBeanPropertyWriter(BeanPropertyWriter base,
- NameTransformer transformer) {
+ public UnwrappingJsonNullableJackson2BeanPropertyWriter(BeanPropertyWriter base,
+ NameTransformer transformer) {
super(base, transformer);
}
- protected UnwrappingJsonNullableBeanPropertyWriter(UnwrappingBeanPropertyWriter base,
- NameTransformer transformer, SerializedString name) {
+ protected UnwrappingJsonNullableJackson2BeanPropertyWriter(UnwrappingBeanPropertyWriter base,
+ NameTransformer transformer, SerializedString name) {
super(base, transformer, name);
}
@Override
protected UnwrappingBeanPropertyWriter _new(NameTransformer transformer, SerializedString newName)
{
- return new UnwrappingJsonNullableBeanPropertyWriter(this, transformer, newName);
+ return new UnwrappingJsonNullableJackson2BeanPropertyWriter(this, transformer, newName);
}
@Override
diff --git a/src/main/java/org/openapitools/jackson/nullable/UnwrappingJsonNullableJackson3BeanPropertyWriter.java b/src/main/java/org/openapitools/jackson/nullable/UnwrappingJsonNullableJackson3BeanPropertyWriter.java
new file mode 100644
index 0000000..275ed02
--- /dev/null
+++ b/src/main/java/org/openapitools/jackson/nullable/UnwrappingJsonNullableJackson3BeanPropertyWriter.java
@@ -0,0 +1,36 @@
+package org.openapitools.jackson.nullable;
+
+import tools.jackson.core.JsonGenerator;
+import tools.jackson.core.io.SerializedString;
+import tools.jackson.databind.SerializationContext;
+import tools.jackson.databind.ser.BeanPropertyWriter;
+import tools.jackson.databind.ser.bean.UnwrappingBeanPropertyWriter;
+import tools.jackson.databind.util.NameTransformer;
+
+public class UnwrappingJsonNullableJackson3BeanPropertyWriter extends UnwrappingBeanPropertyWriter {
+
+
+ public UnwrappingJsonNullableJackson3BeanPropertyWriter(BeanPropertyWriter base,
+ NameTransformer transformer) {
+ super(base, transformer);
+ }
+
+ protected UnwrappingJsonNullableJackson3BeanPropertyWriter(UnwrappingBeanPropertyWriter base,
+ NameTransformer transformer, SerializedString name) {
+ super(base, transformer, name);
+ }
+
+ @Override
+ protected UnwrappingBeanPropertyWriter _new(NameTransformer transformer, SerializedString newName) {
+ return new UnwrappingJsonNullableJackson3BeanPropertyWriter(this, transformer, newName);
+ }
+
+ @Override
+ public void serializeAsProperty(Object bean, JsonGenerator gen, SerializationContext prov) throws Exception {
+ Object value = get(bean);
+ if (JsonNullable.undefined().equals(value) || (_nullSerializer == null && value == null)) {
+ return;
+ }
+ super.serializeAsProperty(bean, gen, prov);
+ }
+}
\ No newline at end of file
diff --git a/src/main/java17/module-info.java b/src/main/java17/module-info.java
new file mode 100644
index 0000000..0cb572d
--- /dev/null
+++ b/src/main/java17/module-info.java
@@ -0,0 +1,15 @@
+module org.openapitools.jackson.nullable {
+ requires static com.fasterxml.jackson.databind;
+ requires static tools.jackson.databind;
+ requires static jakarta.validation;
+ requires static java.validation;
+
+ exports org.openapitools.jackson.nullable;
+
+ // These service providers for optional dependencies can be added, if baseline is 25+ or alternative implementations can be dropped
+ // see https://github.com/OpenAPITools/jackson-databind-nullable/issues/100
+ // provides com.fasterxml.jackson.databind.Module with org.openapitools.jackson.nullable.JsonNullableModule;
+ // provides tools.jackson.databind.JacksonModule with org.openapitools.jackson.nullable.JsonNullableJackson3Module;
+ // provides javax.validation.valueextraction.ValueExtractor with org.openapitools.jackson.nullable.JsonNullableValueExtractor;
+ // provides jakarta.validation.valueextraction.ValueExtractor with org.openapitools.jackson.nullable.JsonNullableJakartaValueExtractor;
+}
diff --git a/src/main/resources/META-INF/services/tools.jackson.databind.JacksonModule b/src/main/resources/META-INF/services/tools.jackson.databind.JacksonModule
new file mode 100644
index 0000000..86f8499
--- /dev/null
+++ b/src/main/resources/META-INF/services/tools.jackson.databind.JacksonModule
@@ -0,0 +1 @@
+org.openapitools.jackson.nullable.JsonNullableJackson3Module
\ No newline at end of file