Skip to content

Commit

Permalink
unit test improvement (wrt #312)
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Feb 26, 2015
1 parent 540213f commit 9a233d9
Showing 1 changed file with 26 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;

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

public class TestOverlappingTypeIdNames312 extends BaseMapTest
Expand All @@ -17,22 +17,43 @@ static abstract class Base312 { }
static class Impl312 extends Base312 {
public int x;
}


@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
@JsonSubTypes({
@JsonSubTypes.Type(name = "a", value = Impl312B1.class),
@JsonSubTypes.Type(name = "a", value = Impl312B2.class)
})
static class Base312B {
public int value = 1;
}

static class Impl312B1 extends Base312B { }
static class Impl312B2 extends Base312B { }

final ObjectMapper MAPPER = objectMapper();

public void testOverlappingNameDeser() throws Exception
{
final ObjectMapper mapper = objectMapper();
Base312 value;

// Ensure both type ids are acceptable

value = mapper.readValue(aposToQuotes("{'type':'a','x':7}"), Base312.class);
value = MAPPER.readValue(aposToQuotes("{'type':'a','x':7}"), Base312.class);
assertNotNull(value);
assertEquals(Impl312.class, value.getClass());
assertEquals(7, ((Impl312) value).x);

value = mapper.readValue(aposToQuotes("{'type':'b','x':3}"), Base312.class);
value = MAPPER.readValue(aposToQuotes("{'type':'b','x':3}"), Base312.class);
assertNotNull(value);
assertEquals(Impl312.class, value.getClass());
assertEquals(3, ((Impl312) value).x);
}

public void testOverlappingNameSer() throws Exception
{
assertEquals(aposToQuotes("{'type':'a','value':1}"),
MAPPER.writeValueAsString(new Impl312B1()));
assertEquals(aposToQuotes("{'type':'a','value':1}"),
MAPPER.writeValueAsString(new Impl312B2()));
}
}

0 comments on commit 9a233d9

Please sign in to comment.