Skip to content

Commit

Permalink
Start implementing #540
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Sep 26, 2014
1 parent 750ccda commit c86fb3a
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,27 @@ public enum DeserializationFeature implements ConfigFeature
* If disabled, standard POJOs can only be bound from JSON null or
* JSON Object (standard meaning that no custom deserializers or
* constructors are defined; both of which can add support for other
* kinds of JSON values); if enable, empty JSON String can be taken
* kinds of JSON values); if enabled, empty JSON String can be taken
* to be equivalent of JSON null.
*<p>
* Feature is disabled by default.
*/
ACCEPT_EMPTY_STRING_AS_NULL_OBJECT(false),

/**
* Feature that can be enabled to allow empty JSON Array
* value (that is, <code>[ ]</code>) to be bound to POJOs as null.
* If disabled, standard POJOs can only be bound from JSON null or
* JSON Object (standard meaning that no custom deserializers or
* constructors are defined; both of which can add support for other
* kinds of JSON values); if enabled, empty JSON Array will be taken
* to be equivalent of JSON null.
*<p>
* Feature is disabled by default.
*
* @since 2.5
*/
ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT(false),

/**
* Feature that allows unknown Enum values to be parsed as null values.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public abstract class BeanDeserializerBase
implements ContextualDeserializer, ResolvableDeserializer,
java.io.Serializable // since 2.1
{
private static final long serialVersionUID = 2960120955735322578L;
private static final long serialVersionUID = 1;

protected final static PropertyName TEMP_PROPERTY_NAME = new PropertyName("#temporary-name");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ static class SimpleBuilderXY
{
public int x, y;

public SimpleBuilderXY withX(int x) {
this.x = x;
public SimpleBuilderXY withX(int x0) {
this.x = x0;
return this;
}

public SimpleBuilderXY withY(int y) {
this.y = y;
public SimpleBuilderXY withY(int y0) {
this.y = y0;
return this;
}

Expand Down Expand Up @@ -61,15 +61,15 @@ static class BuildABC
private int b, c;

@JsonProperty("b")
public BuildABC assignB(int b) {
this.b = b;
public BuildABC assignB(int b0) {
this.b = b0;
return this;
}

// Also ok NOT to return 'this'
@JsonSetter("c")
public void c(int c) {
this.c = c;
public void c(int c0) {
this.c = c0;
}

public ValueClassABC build() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ public Object deserializeKey(String key,
/********************************************************
*/

private final ObjectMapper MAPPER = new ObjectMapper();

public void testPropertyRemoval() throws Exception
{
ObjectMapper mapper = new ObjectMapper();
Expand Down Expand Up @@ -258,22 +260,43 @@ public void testIssue476() throws Exception
public void testPOJOFromEmptyString() throws Exception
{
// first, verify default settings which do not accept empty String:
ObjectMapper mapper = new ObjectMapper();
assertFalse(MAPPER.isEnabled(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT));
try {
mapper.readValue(quote(""), Bean.class);
MAPPER.readValue(quote(""), Bean.class);
fail("Should not accept Empty String for POJO");
} catch (JsonProcessingException e) {
verifyException(e, "from String value");
assertValidLocation(e.getLocation());
}
// should be ok to enable dynamically
ObjectReader r = MAPPER.reader(Bean.class)
.with(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT);
Bean result = r.readValue(quote(""));
assertNull(result);
}

// [Databind#540]
public void testPOJOFromEmptyArray() throws Exception
{
final String JSON = " [\n]";
assertFalse(MAPPER.isEnabled(DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT));
// first, verify default settings which do not accept empty Array
ObjectMapper mapper = new ObjectMapper();
try {
mapper.readValue(JSON, Bean.class);
fail("Should not accept Empty Array for POJO by default");
} catch (JsonProcessingException e) {
verifyException(e, "START_ARRAY token");
assertValidLocation(e.getLocation());
}

// should be ok to enable dynamically:
mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, true);
Bean result = mapper.readValue(quote(""), Bean.class);
ObjectReader r = MAPPER.reader(Bean.class)
.with(DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT);
Bean result = r.readValue(JSON);
assertNull(result);
}

// [Issue#120]
public void testModifyArrayDeserializer() throws Exception
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ static class SimpleBuilder
{
public int x;

public SimpleBuilder withX(int x) {
this.x = x;
public SimpleBuilder withX(int x0) {
this.x = x0;
return this;
}
}
Expand Down

0 comments on commit c86fb3a

Please sign in to comment.