-
Notifications
You must be signed in to change notification settings - Fork 47
Features/fix for issue 291 #292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jkstrauss
wants to merge
4
commits into
vavr-io:main
Choose a base branch
from
jkstrauss:features/fix-for-issue-291
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -19,37 +19,35 @@ | |
| */ | ||
| package io.vavr.jackson.datatype.deserialize; | ||
|
|
||
| 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.deser.ContextualDeserializer; | ||
| import com.fasterxml.jackson.databind.jsontype.TypeDeserializer; | ||
| import tools.jackson.core.JsonToken; | ||
| import tools.jackson.databind.BeanProperty; | ||
| import tools.jackson.databind.DatabindException; | ||
| import tools.jackson.databind.DeserializationContext; | ||
| import tools.jackson.databind.JavaType; | ||
| import tools.jackson.databind.ValueDeserializer; | ||
| import tools.jackson.databind.jsontype.TypeDeserializer; | ||
| import io.vavr.collection.Traversable; | ||
| import tools.jackson.core.JsonParser; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.ArrayList; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
|
|
||
| import static com.fasterxml.jackson.core.JsonToken.END_ARRAY; | ||
| import static com.fasterxml.jackson.core.JsonToken.VALUE_NULL; | ||
| import static tools.jackson.core.JsonToken.END_ARRAY; | ||
| import static tools.jackson.core.JsonToken.VALUE_NULL; | ||
|
|
||
| abstract class ArrayDeserializer<T> extends ValueDeserializer<T> implements ContextualDeserializer { | ||
| abstract class ArrayDeserializer<T> extends VavrValueDeserializer<T> { | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The local ValueDeserializer/ValueSerializer was renamed due to a naming conflict with Jackson 3's classes of the same names. |
||
|
|
||
| private static final long serialVersionUID = 1L; | ||
|
|
||
| protected final JavaType collectionType; | ||
| protected final JavaType elementType; | ||
| protected final TypeDeserializer elementTypeDeserializer; | ||
| protected final JsonDeserializer<?> elementDeserializer; | ||
| protected final ValueDeserializer<?> elementDeserializer; | ||
| protected final boolean deserializeNullAsEmptyCollection; | ||
|
|
||
| ArrayDeserializer(JavaType collectionType, int typeCount, JavaType elementType, | ||
| TypeDeserializer elementTypeDeserializer, JsonDeserializer<?> elementDeserializer, | ||
| TypeDeserializer elementTypeDeserializer, ValueDeserializer<?> elementDeserializer, | ||
| boolean deserializeNullAsEmptyCollection) { | ||
| super(collectionType, typeCount); | ||
| this.collectionType = collectionType; | ||
|
|
@@ -59,7 +57,7 @@ abstract class ArrayDeserializer<T> extends ValueDeserializer<T> implements Cont | |
| this.deserializeNullAsEmptyCollection = deserializeNullAsEmptyCollection; | ||
| } | ||
|
|
||
| abstract T create(List<Object> list, DeserializationContext ctxt) throws JsonMappingException; | ||
| abstract T create(List<Object> list, DeserializationContext ctxt) throws DatabindException; | ||
|
|
||
| /** | ||
| * Creates a new deserializer from the original one (this). | ||
|
|
@@ -70,11 +68,11 @@ abstract class ArrayDeserializer<T> extends ValueDeserializer<T> implements Cont | |
| * @return a new deserializer | ||
| */ | ||
| abstract ArrayDeserializer<T> createDeserializer(TypeDeserializer elementTypeDeserializer, | ||
| JsonDeserializer<?> elementDeserializer); | ||
| ValueDeserializer<?> elementDeserializer); | ||
|
|
||
| @Override | ||
| public JsonDeserializer<?> createContextual(DeserializationContext ctxt, BeanProperty property) throws JsonMappingException { | ||
| JsonDeserializer<?> elementDeser = elementDeserializer; | ||
| public ValueDeserializer<?> createContextual(DeserializationContext ctxt, BeanProperty property) throws DatabindException { | ||
| ValueDeserializer<?> elementDeser = elementDeserializer; | ||
| TypeDeserializer elementTypeDeser = elementTypeDeserializer; | ||
|
|
||
| if (elementDeser == null) { | ||
|
|
@@ -89,9 +87,9 @@ public JsonDeserializer<?> createContextual(DeserializationContext ctxt, BeanPro | |
| } | ||
|
|
||
| @Override | ||
| public T deserialize(JsonParser parser, DeserializationContext context, T intoValue) throws IOException { | ||
| public T deserialize(JsonParser parser, DeserializationContext context, T intoValue) { | ||
| if (!parser.isExpectedStartArrayToken()) { | ||
| throw mappingException(context, collectionType.getRawClass(), parser.getCurrentToken()); | ||
| throw mappingException(context, collectionType.getRawClass(), parser.currentToken()); | ||
| } | ||
|
|
||
| List<Object> elements = new ArrayList<>(); | ||
|
|
@@ -117,19 +115,19 @@ public T deserialize(JsonParser parser, DeserializationContext context, T intoVa | |
| } | ||
|
|
||
| @Override | ||
| public T deserialize(JsonParser parser, DeserializationContext context) throws IOException { | ||
| public T deserialize(JsonParser parser, DeserializationContext context) { | ||
| return deserialize(parser, context, null); | ||
| } | ||
|
|
||
| @Override | ||
| public T getNullValue(DeserializationContext ctxt) throws JsonMappingException { | ||
| public T getNullValue(DeserializationContext ctxt) throws DatabindException { | ||
| if (deserializeNullAsEmptyCollection) { | ||
| return create(Collections.emptyList(), ctxt); | ||
| } | ||
| return super.getNullValue(ctxt); | ||
| return (T) super.getNullValue(ctxt); | ||
| } | ||
|
|
||
| static void checkContainedTypeIsComparable(DeserializationContext ctxt, JavaType type) throws JsonMappingException { | ||
| static void checkContainedTypeIsComparable(DeserializationContext ctxt, JavaType type) throws DatabindException { | ||
| Class<?> clz = type.getRawClass(); | ||
| if (clz == Object.class || !Comparable.class.isAssignableFrom(clz)) { | ||
| throw mappingException(ctxt, clz, null); | ||
|
|
||
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There might be a better way than using rebuild, but this was the quickest way without changing the code significantly. This strategy was employed throughout the PR.