-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for jakarta-validation (#42)
* remove dependency on el-interpreter for tests * add support for jakarta-validation * add support for jakarta-validation * make ValidatorFactory local again * remove some unnecessary boxing of primitive integers
- Loading branch information
1 parent
4485fd1
commit f70a463
Showing
6 changed files
with
64 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/main/java/org/openapitools/jackson/nullable/JsonNullableJakartaValueExtractor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.openapitools.jackson.nullable; | ||
|
||
import jakarta.validation.valueextraction.ExtractedValue; | ||
import jakarta.validation.valueextraction.UnwrapByDefault; | ||
import jakarta.validation.valueextraction.ValueExtractor; | ||
|
||
/** | ||
* Extractor for JsonNullable (modern jakarta-validation version) | ||
*/ | ||
@UnwrapByDefault | ||
public class JsonNullableJakartaValueExtractor implements ValueExtractor<JsonNullable<@ExtractedValue ?>> { | ||
@Override | ||
public void extractValues(JsonNullable<?> originalValue, ValueReceiver receiver) { | ||
JsonNullableValueExtractorHelper.extractValues(originalValue, receiver::indexedValue, receiver::value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/main/java/org/openapitools/jackson/nullable/JsonNullableValueExtractorHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package org.openapitools.jackson.nullable; | ||
|
||
import java.util.Collection; | ||
|
||
abstract class JsonNullableValueExtractorHelper { | ||
public static void extractValues(JsonNullable<?> originalValue, IndexedValueSetter indexedValueSetter, ValueSetter valueSetter) { | ||
if (originalValue.isPresent()) { | ||
Object unwrapped = originalValue.get(); | ||
if (unwrapped instanceof Collection<?>) { | ||
Collection<?> unwrappedList = (Collection<?>) unwrapped; | ||
Object[] objects = unwrappedList.toArray(); | ||
for (int i = 0; i < objects.length; i++) { | ||
indexedValueSetter.apply("<list element>", i, objects[i]); | ||
} | ||
} else { | ||
valueSetter.apply(null, originalValue.get()); | ||
} | ||
} | ||
} | ||
|
||
@FunctionalInterface | ||
interface IndexedValueSetter { | ||
void apply(String var1, int var2, Object var3); | ||
} | ||
|
||
@FunctionalInterface | ||
interface ValueSetter { | ||
void apply(String var1, Object var2); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
src/main/resources/META-INF/services/jakarta.validation.valueextraction.ValueExtractor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
org.openapitools.jackson.nullable.JsonNullableJakartaValueExtractor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters