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

Update SettableAnyProperty to use ValueDeserializer's NullValue #1229

Merged
merged 1 commit into from
May 13, 2016
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 @@ -130,7 +130,7 @@ public Object deserialize(JsonParser jp, DeserializationContext ctxt) throws IOE
{
JsonToken t = jp.getCurrentToken();
if (t == JsonToken.VALUE_NULL) {
return null;
return _valueDeserializer.getNullValue(ctxt);
}
if (_valueTypeDeserializer != null) {
return _valueDeserializer.deserializeWithType(jp, ctxt, _valueTypeDeserializer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.module.SimpleModule;
Expand All @@ -23,12 +24,51 @@ public String deserialize(JsonParser jp, DeserializationContext ctxt) throws IOE
public String getNullValue(DeserializationContext ctxt) { return "funny"; }
}

static class AnySetter{

private Map<String,String> any = new HashMap<String,String>();

@JsonAnySetter
public void setAny(String name, String value){
this.any.put(name,value);
}

public Map<String,String> getAny(){
return this.any;
}
}

/*
/**********************************************************
/* Test methods
/**********************************************************
*/

public void testAnySetterNulls() throws Exception {
ObjectMapper mapper = new ObjectMapper();
SimpleModule module = new SimpleModule("test", Version.unknownVersion());
module.addDeserializer(String.class, new FunnyNullDeserializer());
mapper.registerModule(module);

String fieldName = "fieldName";
String nullValue = "{\""+fieldName+"\":null}";

// should get non-default null directly:
AnySetter result = mapper.readValue(nullValue, AnySetter.class);

assertEquals(1, result.getAny().size());
assertNotNull(result.getAny().get(fieldName));
assertEquals("funny", result.getAny().get(fieldName));

// as well as via ObjectReader
ObjectReader reader = mapper.readerFor(AnySetter.class);
result = reader.readValue(nullValue);

assertEquals(1, result.getAny().size());
assertNotNull(result.getAny().get(fieldName));
assertEquals("funny", result.getAny().get(fieldName));
}

// Test for [JACKSON-643]
public void testCustomRootNulls() throws Exception
{
Expand Down