Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Fix/union #43

Merged
merged 5 commits into from
Dec 13, 2019
Merged

Fix/union #43

merged 5 commits into from
Dec 13, 2019

Conversation

Kaiser1989
Copy link

@Kaiser1989 Kaiser1989 commented Dec 9, 2019

Ok what we got so far:

We need to differ two deserialization strategies:

The manuel one:

NilUnionType b = mapper.readValue(new StringReader(out.toString()), NilUnionType.class);

here we need the getNullValue implementation of StdDeserializer

and the one used in Jackson Deserialization with JsonNode:

NilUnionType b = mapper.treeToValue(node, NilUnionType.class);

here we need the if (node.isNull()) check

I left both in there so we can't get something wrong then (one does not work without the other).

The other thing really was a bug when calling the constructor with null value, as constructor thought we put in a Integer or Boolean or String...

Which leads us to the next point: ambiguity!
I removed all constructors and only left one private empty constructor, indicating that the object was not correctly initialized (all null, also enum null)
And i added one constructor with Object as argument, checking the given value against all possibilities to build the correct Union type. This also handles the null value correctly and someone can use following code to create a StringNilUnion:

String test = ("sometext" or null);
new StringNilUnionImpl(test);

One does not need to care to call the empty constructor for null values anymore. If the type does not fit, an IllegalArgumentException is thrown.

Some other changes:

  • Code cleanup
  • Added helper function for Amibiguous testing
  • Added helper function for type sorting
  • One more test for a more complicated union of primitives
  • Removed Creation of ObjectMapper for every conversion (use the one of context if no changes are made to the mapper => better performance)
  • Fixed all warning by adding serialVersionUID
  • Fixed map iteration in ExcludingMap (using entrySet iteration not key iteration)

@jpbelang jpbelang changed the base branch from master to release/1.0.7 December 11, 2019 13:14
@jpbelang
Copy link
Contributor

jpbelang commented Dec 11, 2019

I've quickly read through it, and will be giving it a real checkout tonight. This should get merged.

@jpbelang jpbelang merged commit 5f60c9e into mulesoft-labs:release/1.0.7 Dec 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants