7
7
8
8
public class TestJsonSerializeAs extends BaseMapTest
9
9
{
10
- // [JACKSON-799] stuff:
11
10
public interface Fooable {
12
11
public int getFoo ();
13
12
}
@@ -20,6 +19,12 @@ public static class FooImpl implements Fooable {
20
19
public int getBar () { return 15 ; }
21
20
}
22
21
22
+ static class FooImplNoAnno implements Fooable {
23
+ @ Override
24
+ public int getFoo () { return 42 ; }
25
+ public int getBar () { return 15 ; }
26
+ }
27
+
23
28
public class Fooables {
24
29
public FooImpl [] getFoos () {
25
30
return new FooImpl [] { new FooImpl () };
@@ -32,6 +37,14 @@ public FooImpl getFoo() {
32
37
}
33
38
}
34
39
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
+
35
48
/*
36
49
/**********************************************************
37
50
/* Test methods
@@ -40,19 +53,22 @@ public FooImpl getFoo() {
40
53
41
54
private final ObjectWriter WRITER = objectWriter ();
42
55
43
- // [JACKSON-799]
44
- public void testSerializeAsInClass () throws IOException
45
- {
56
+ public void testSerializeAsInClass () throws IOException {
46
57
assertEquals ("{\" foo\" :42}" , WRITER .writeValueAsString (new FooImpl ()));
47
58
}
48
59
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 ()));
52
68
}
53
69
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 ()));
57
73
}
58
74
}
0 commit comments