Skip to content

Commit

Permalink
Add test for #1161
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Mar 14, 2016
1 parent 7a3b0b1 commit 9d74817
Showing 1 changed file with 35 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.BaseMapTest;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.MappingIterator;
import com.fasterxml.jackson.databind.ObjectMapper;

Expand All @@ -23,6 +24,20 @@ public boolean equals(Object o) {
@Override public int hashCode() { return a; }
}

static class Data1161 {
enum Type {
A, B, C;

@Override
public String toString() {
return name().toLowerCase();
};
};

public Type type;
public String value;
}

/*
/**********************************************************
/* Unit tests; root-level value sequences via Mapper
Expand Down Expand Up @@ -261,15 +276,15 @@ public void testNonRootMapsWithObjectReader() throws Exception
public void testNonRootArraysUsingParser() throws Exception
{
final String JSON = "[[1],[3]]";
JsonParser jp = MAPPER.getFactory().createParser(JSON);
assertToken(JsonToken.START_ARRAY, jp.nextToken());
JsonParser p = MAPPER.getFactory().createParser(JSON);
assertToken(JsonToken.START_ARRAY, p.nextToken());

// Important: as of 2.1, START_ARRAY can only be skipped if the
// target type is NOT a Collection or array Java type.
// So we have to explicitly skip it in this particular case.
assertToken(JsonToken.START_ARRAY, jp.nextToken());
assertToken(JsonToken.START_ARRAY, p.nextToken());

Iterator<int[]> it = MAPPER.readValues(jp, int[].class);
Iterator<int[]> it = MAPPER.readValues(p, int[].class);

assertTrue(it.hasNext());
int[] array = it.next();
Expand All @@ -280,6 +295,21 @@ public void testNonRootArraysUsingParser() throws Exception
assertEquals(1, array.length);
assertEquals(3, array[0]);
assertFalse(it.hasNext());
jp.close();
p.close();
}

public void testDeserProps1161() throws Exception
{
final String src = "[ { \"type\": \"a\", \"value\": \"1\" }, { \"type\": \"b\", \"value\": \"2\" }]";
MappingIterator<Data1161> iterator = MAPPER
.reader()
.with(DeserializationFeature.READ_ENUMS_USING_TO_STRING)
.forType(Data1161.class)
.readValues(src);
assertTrue(iterator.hasNext());
Data1161 item = iterator.nextValue();
assertNotNull(item);
assertSame(Data1161.Type.A, item.type);
iterator.close();
}
}

0 comments on commit 9d74817

Please sign in to comment.