Skip to content
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

Improve JavaDoc and Test for config ACCEPT_EMPTY_STRING_AS_NULL_OBJECT wrt special cases #4012

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,9 @@ public enum DeserializationFeature implements ConfigFeature
* whether they can be coerced depends on
* {@link MapperFeature#ALLOW_COERCION_OF_SCALARS}.
*<p>
* IMPORTANT: This feature might work even when an empty string {@code ""}
* may be a valid value for some types.
*<p>
* Feature is disabled by default.
*/
ACCEPT_EMPTY_STRING_AS_NULL_OBJECT(false),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.fasterxml.jackson.databind.deser.jdk;

import static org.junit.jupiter.api.Assertions.assertThrows;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.BaseMapTest;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectReader;
import java.util.Locale;

// [databind#4009] Locale "" is deserialised as NULL if ACCEPT_EMPTY_STRING_AS_NULL_OBJECT is true
public class LocaleDeser4009Test extends BaseMapTest
{

static class MyPojo {
public String field;
}
final ObjectMapper mapper = newJsonMapper();

final ObjectReader DISABLED_READER = mapper.reader()
.without(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT);

final ObjectReader ENABLED_READER = mapper.reader()
.with(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT);

public void testPOJOWithFeatureDisabled()
{
assertThrows(JsonProcessingException.class, () -> {
DISABLED_READER.readValue("\"\"", MyPojo.class);
});
}

public void testPOJOWithFeatureEnabled() throws Exception
{
assertNull(ENABLED_READER.readValue("\"\"", MyPojo.class));
}

public void testLocaleWithFeatureDisabled() throws Exception
{
assertEquals(Locale.ROOT, DISABLED_READER.readValue("\"\"", Locale.class));
}

public void testLocaleWithFeatureEnabled() throws Exception
{
assertNull(ENABLED_READER.readValue("\"\"", Locale.class));
}
}