Skip to content

Commit

Permalink
Fix #214
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Apr 24, 2021
1 parent 39e86c0 commit 0f8ed73
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ public Optional<?> referenceValue(Object contents) {

@Override
public Object getReferenced(Optional<?> reference) {
return reference.get();
// 23-Apr-2021, tatu: [modules-java8#214] Need to support empty
// for merging too
return reference.orElse(null);
}

@Override // since 2.9
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.fasterxml.jackson.datatype.jdk8;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;

import com.fasterxml.jackson.annotation.JsonMerge;
import com.fasterxml.jackson.databind.ObjectMapper;

public class OptionalMergeTest extends ModuleTestBase
{
// [modules-java8#214]
static class OptionalListWrapper {
@JsonMerge
public Optional<List<String>> list = Optional.empty();
}

private final ObjectMapper MAPPER = mapperWithModule();

// [modules-java8#214]: ReferenceType of List, merge
public void testMergeToListViaRef() throws Exception
{
OptionalListWrapper base = MAPPER.readValue(aposToQuotes("{'list':['a']}"),
OptionalListWrapper.class);
assertNotNull(base.list);
assertEquals(Arrays.asList("a"), base.list.get());

OptionalListWrapper merged = MAPPER.readerForUpdating(base)
.readValue(aposToQuotes("{'list':['b']}"));
assertSame(base, merged);
assertEquals(Arrays.asList("a", "b"), base.list.get());
}
}
6 changes: 6 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ Modules:
=== Releases ===
------------------------------------------------------------------------

2.12.4 (not yet released)

#214: readerForUpdating(objectToUpdate).readValue(json) behaves unexpectedly
on Optional<List>
(reported by jc84-dev@github)

2.12.3 (12-Apr-2021)

#207: Fail to serialize `TemporalAdjuster` type with 2.12
Expand Down

0 comments on commit 0f8ed73

Please sign in to comment.