-
Notifications
You must be signed in to change notification settings - Fork 41
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
fix: null handling with Structure, Value #663
Conversation
Codecov Report
@@ Coverage Diff @@
## main #663 +/- ##
============================================
+ Coverage 94.47% 94.97% +0.49%
- Complexity 362 365 +3
============================================
Files 32 33 +1
Lines 851 856 +5
Branches 51 52 +1
============================================
+ Hits 804 813 +9
+ Misses 24 22 -2
+ Partials 23 21 -2
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 1 file with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
Co-authored-by: Michael Beemer <[email protected]> Signed-off-by: Todd Baert <[email protected]>
Co-authored-by: Michael Beemer <[email protected]> Signed-off-by: Todd Baert <[email protected]>
Co-authored-by: Michael Beemer <[email protected]> Signed-off-by: Todd Baert <[email protected]>
Co-authored-by: Michael Beemer <[email protected]> Signed-off-by: Todd Baert <[email protected]>
Co-authored-by: Giovanni Liva <[email protected]> Signed-off-by: Todd Baert <[email protected]>
274aba2
to
2091fb4
Compare
Signed-off-by: Todd Baert <[email protected]>
@@ -134,7 +138,9 @@ default <T extends Structure> Map<String, Value> merge(Function<Map<String, Valu | |||
*/ | |||
static Structure mapToStructure(Map<String, Object> map) { | |||
return new MutableStructure(map.entrySet().stream() | |||
.filter(e -> e.getValue() != null) |
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.
We were FILTERING null values before. This resulted in maps with null entries not having converted (empty) Values
. I think that's wrong. With this change, all nulls in maps are converted to null-containing Values
and vice-versa.
public Map<String, Object> asObjectMap() { | ||
return attributes | ||
.entrySet() | ||
.stream() | ||
// custom collector, workaround for Collectors.toMap in JDK8 | ||
// https://bugs.openjdk.org/browse/JDK-8148463 | ||
.collect(HashMap::new, | ||
(accumulated, entry) -> accumulated.put(entry.getKey(), convertValue(entry.getValue())), | ||
HashMap::putAll); |
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.
This was common to both the MutableContext
and ImmutableContext
, so I've extracted it to an abstract.
Signed-off-by: Todd Baert <[email protected]>
@@ -98,6 +98,20 @@ void mapToStructureTest() { | |||
assertEquals(new Value(Instant.ofEpochSecond(0)), res.getValue("Instant")); | |||
assertEquals(new HashMap<>(), res.getValue("Map").asStructure().asMap()); | |||
assertEquals(new Value(immutableContext), res.getValue("ImmutableContext")); | |||
assertNull(res.getValue("nullKey")); | |||
assertEquals(new Value(), res.getValue("nullKey")); |
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.
Modified assertion associated with this change.
Signed-off-by: Todd Baert <[email protected]>
Kudos, SonarCloud Quality Gate passed!
|
Value
->null
and vice versa)