-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #145: use correct delegation for `GuavaOptionalDeserializer.get…
…Empty()` (#146)
- Loading branch information
1 parent
3456419
commit b94e67d
Showing
3 changed files
with
31 additions
and
1 deletion.
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
24 changes: 24 additions & 0 deletions
24
guava/src/test/java/com/fasterxml/jackson/datatype/guava/optional/OptionalFromEmptyTest.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 |
---|---|---|
@@ -1,18 +1,42 @@ | ||
package com.fasterxml.jackson.datatype.guava.optional; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.annotation.JsonSetter; | ||
import com.fasterxml.jackson.annotation.Nulls; | ||
|
||
import com.fasterxml.jackson.core.type.TypeReference; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.datatype.guava.ModuleTestBase; | ||
|
||
import com.google.common.base.Optional; | ||
|
||
public class OptionalFromEmptyTest extends ModuleTestBase | ||
{ | ||
static class OptionalBeanWithEmpty { | ||
protected Optional<String> _value; | ||
|
||
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES) | ||
public OptionalBeanWithEmpty(@JsonProperty("value") | ||
@JsonSetter(nulls = Nulls.AS_EMPTY) Optional<String> ref) { | ||
_value = ref; | ||
} | ||
} | ||
|
||
private final ObjectMapper MAPPER = mapperWithModule(); | ||
|
||
// [datatype-guava#48] | ||
public void testDeserNull() throws Exception { | ||
Optional<?> value = MAPPER.readValue("\"\"", new TypeReference<Optional<Integer>>() {}); | ||
assertEquals(false, value.isPresent()); | ||
} | ||
|
||
// [datatypes-collections#145] | ||
public void testDeserEmptyViaConstructor() throws Exception { | ||
OptionalBeanWithEmpty bean = MAPPER.readValue("{}", | ||
OptionalBeanWithEmpty.class); | ||
assertNotNull(bean._value); | ||
assertFalse(bean._value.isPresent()); | ||
} | ||
} |
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