Skip to content

Commit

Permalink
Add failing test for #960
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed May 5, 2016
1 parent d2c4061 commit 7a4b7af
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -330,30 +330,27 @@ public Object deserializeWithType(JsonParser p, DeserializationContext ctxt, Typ

// Method to deserialize the Enum using property based methodology
protected Object deserializeEnumUsingPropertyBased(final JsonParser p, final DeserializationContext ctxt,
final PropertyBasedCreator creator) throws IOException {
PropertyValueBuffer buffer = creator.startBuilding(p, ctxt, null);

JsonToken t = p.getCurrentToken();
for (; t == JsonToken.FIELD_NAME; t = p.nextToken()) {
String propName = p.getCurrentName();
p.nextToken(); // to point to value

SettableBeanProperty creatorProp = creator.findCreatorProperty(propName);
if (creatorProp != null) {

if (buffer.assignParameter(creatorProp, _deserializeWithErrorWrapping(p, ctxt, creatorProp))) {
p.nextToken(); // to move to next field name
}
continue;
}

if (buffer.readIdProperty(propName)) {
continue;
}
final PropertyBasedCreator creator) throws IOException
{
PropertyValueBuffer buffer = creator.startBuilding(p, ctxt, null);

}
JsonToken t = p.getCurrentToken();
for (; t == JsonToken.FIELD_NAME; t = p.nextToken()) {
String propName = p.getCurrentName();
p.nextToken(); // to point to value

return creator.build(ctxt, buffer);
SettableBeanProperty creatorProp = creator.findCreatorProperty(propName);
if (creatorProp != null) {
if (buffer.assignParameter(creatorProp, _deserializeWithErrorWrapping(p, ctxt, creatorProp))) {
p.nextToken(); // to move to next field name
}
continue;
}
if (buffer.readIdProperty(propName)) {
continue;
}
}
return creator.build(ctxt, buffer);
}

// ************ Got the below methods from BeanDeserializer ********************//
Expand All @@ -368,36 +365,35 @@ protected final Object _deserializeWithErrorWrapping(JsonParser p, Deserializati
return null;
}
}

public void wrapAndThrow(Throwable t, Object bean, String fieldName, DeserializationContext ctxt)
throws IOException
{
throw JsonMappingException.wrapWithPath(throwOrReturnThrowable(t, ctxt), bean, fieldName);
throw JsonMappingException.wrapWithPath(throwOrReturnThrowable(t, ctxt), bean, fieldName);
}

private Throwable throwOrReturnThrowable(Throwable t, DeserializationContext ctxt) throws IOException
{
while (t instanceof InvocationTargetException && t.getCause() != null) {
t = t.getCause();
}
// Errors to be passed as is
if (t instanceof Error) {
throw (Error) t;
}
boolean wrap = (ctxt == null) || ctxt.isEnabled(DeserializationFeature.WRAP_EXCEPTIONS);
// Ditto for IOExceptions; except we may want to wrap JSON
// exceptions
if (t instanceof IOException) {
if (!wrap || !(t instanceof JsonProcessingException)) {
throw (IOException) t;
}
} else if (!wrap) { // [JACKSON-407] -- allow disabling wrapping for
// unchecked exceptions
if (t instanceof RuntimeException) {
throw (RuntimeException) t;
}
}
return t;
while (t instanceof InvocationTargetException && t.getCause() != null) {
t = t.getCause();
}
// Errors to be passed as is
if (t instanceof Error) {
throw (Error) t;
}
boolean wrap = (ctxt == null) || ctxt.isEnabled(DeserializationFeature.WRAP_EXCEPTIONS);
// Ditto for IOExceptions; except we may want to wrap JSON
// exceptions
if (t instanceof IOException) {
if (!wrap || !(t instanceof JsonProcessingException)) {
throw (IOException) t;
}
} else if (!wrap) {
if (t instanceof RuntimeException) {
throw (RuntimeException) t;
}
}
return t;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.fasterxml.jackson.databind.creators;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.databind.*;

public class EnumCreatorTest extends BaseMapTest
{
static enum MyEnum960
{
VALUE, BOGUS;

@JsonCreator
public static MyEnum960 getInstance() {
return VALUE;
}
}

static class MyEnum960Wrapper {
public MyEnum960 value;
}

private final ObjectMapper MAPPER = new ObjectMapper();

// for [databind#960]
public void testNoArgEnumCreator() throws Exception
{
MyEnum960 v = MAPPER.readValue("{\"value\":\"bogus\"}", MyEnum960.class);
assertEquals(MyEnum960.VALUE, v);
}
}

0 comments on commit 7a4b7af

Please sign in to comment.