Skip to content

Commit

Permalink
deser test for #631
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Nov 29, 2014
1 parent 7329b4a commit ed66aeb
Showing 1 changed file with 34 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.deser.std.StdDelegatingDeserializer;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import com.fasterxml.jackson.databind.deser.std.StdNodeBasedDeserializer;
import com.fasterxml.jackson.databind.annotation.*;
import com.fasterxml.jackson.databind.deser.std.*;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.databind.util.StdConverter;

Expand Down Expand Up @@ -231,7 +228,30 @@ public JsonDeserializer<?> createContextual(DeserializationContext ctxt, BeanPro
}

}

// for [databind#631]
static class Issue631Bean
{
@JsonDeserialize(using=ParentClassDeserializer.class)
public Object prop;
}

static class ParentClassDeserializer
extends StdScalarDeserializer<Object>
{
protected ParentClassDeserializer() {
super(Object.class);
}

@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt)
throws IOException {
Object parent = p.getCurrentValue();
String desc = (parent == null) ? "NULL" : parent.getClass().getSimpleName();
return "prop/"+ desc;
}
}

/*
/**********************************************************
/* Unit tests
Expand Down Expand Up @@ -353,4 +373,13 @@ public void testContextReadValue() throws Exception
assertNotNull(w.value.inner);
assertEquals(-13, w.value.inner.x);
}

// [#631]: "current value" access
public void testCurrentValueAccess() throws Exception
{
Issue631Bean bean = MAPPER.readValue(aposToQuotes("{'prop':'stuff'}"),
Issue631Bean.class);
assertNotNull(bean);
assertEquals("prop/Issue631Bean", bean.prop);
}
}

0 comments on commit ed66aeb

Please sign in to comment.