Skip to content

Commit e59a1ae

Browse files
committed
add a unit test for serialization type overrides
1 parent c966a03 commit e59a1ae

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

src/test/java/com/fasterxml/jackson/databind/ser/TestJsonSerializeAs.java

+26-10
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
public class TestJsonSerializeAs extends BaseMapTest
99
{
10-
// [JACKSON-799] stuff:
1110
public interface Fooable {
1211
public int getFoo();
1312
}
@@ -20,6 +19,12 @@ public static class FooImpl implements Fooable {
2019
public int getBar() { return 15; }
2120
}
2221

22+
static class FooImplNoAnno implements Fooable {
23+
@Override
24+
public int getFoo() { return 42; }
25+
public int getBar() { return 15; }
26+
}
27+
2328
public class Fooables {
2429
public FooImpl[] getFoos() {
2530
return new FooImpl[] { new FooImpl() };
@@ -32,6 +37,14 @@ public FooImpl getFoo() {
3237
}
3338
}
3439

40+
// Also test via Field
41+
static class FooableWithFieldWrapper {
42+
@JsonSerialize(as=Fooable.class)
43+
public Fooable getFoo() {
44+
return new FooImplNoAnno();
45+
}
46+
}
47+
3548
/*
3649
/**********************************************************
3750
/* Test methods
@@ -40,19 +53,22 @@ public FooImpl getFoo() {
4053

4154
private final ObjectWriter WRITER = objectWriter();
4255

43-
// [JACKSON-799]
44-
public void testSerializeAsInClass() throws IOException
45-
{
56+
public void testSerializeAsInClass() throws IOException {
4657
assertEquals("{\"foo\":42}", WRITER.writeValueAsString(new FooImpl()));
4758
}
4859

49-
public void testSerializeAsForArrayProp() throws IOException
50-
{
51-
assertEquals("{\"foos\":[{\"foo\":42}]}", WRITER.writeValueAsString(new Fooables()));
60+
public void testSerializeAsForArrayProp() throws IOException {
61+
assertEquals("{\"foos\":[{\"foo\":42}]}",
62+
WRITER.writeValueAsString(new Fooables()));
63+
}
64+
65+
public void testSerializeAsForSimpleProp() throws IOException {
66+
assertEquals("{\"foo\":{\"foo\":42}}",
67+
WRITER.writeValueAsString(new FooableWrapper()));
5268
}
5369

54-
public void testSerializeAsForSimpleProp() throws IOException
55-
{
56-
assertEquals("{\"foo\":{\"foo\":42}}", WRITER.writeValueAsString(new FooableWrapper()));
70+
public void testSerializeWithFieldAnno() throws IOException {
71+
assertEquals("{\"foo\":{\"foo\":42}}",
72+
WRITER.writeValueAsString(new FooableWithFieldWrapper()));
5773
}
5874
}

0 commit comments

Comments
 (0)