30
30
31
31
import org .apache .dto .BaseType ;
32
32
import org .apache .dto .FirstDomainObject ;
33
+ import org .apache .dto .FirstNestedType ;
34
+ import org .apache .dto .NestedType ;
33
35
import org .apache .dto .SecondDomainObject ;
36
+ import org .apache .dto .SecondNestedType ;
34
37
import org .apache .dto .TestModules ;
35
38
import org .apache .james .json .DTO ;
36
39
import org .apache .james .json .JsonGenericSerializer ;
40
43
import org .junit .jupiter .params .provider .MethodSource ;
41
44
42
45
class JsonGenericSerializerTest {
43
- private static final FirstDomainObject FIRST = new FirstDomainObject (Optional .of (1L ), ZonedDateTime .parse ("2016-04-03T02:01+07:00[Asia/Vientiane]" ), "first payload" );
44
- private static final SecondDomainObject SECOND = new SecondDomainObject (UUID .fromString ("4a2c853f-7ffc-4ce3-9410-a47e85b3b741" ), "second payload" );
46
+ private static final Optional <NestedType > NO_CHILD = Optional .empty ();
47
+ private static final FirstDomainObject FIRST = new FirstDomainObject (Optional .of (1L ), ZonedDateTime .parse ("2016-04-03T02:01+07:00[Asia/Vientiane]" ), "first payload" , NO_CHILD );
48
+ private static final SecondDomainObject SECOND = new SecondDomainObject (UUID .fromString ("4a2c853f-7ffc-4ce3-9410-a47e85b3b741" ), "second payload" , NO_CHILD );
49
+ private static final SecondDomainObject SECOND_WITH_NESTED = new SecondDomainObject (UUID .fromString ("4a2c853f-7ffc-4ce3-9410-a47e85b3b741" ), "second payload" , Optional .of (new FirstNestedType (12 )));
50
+ private static final FirstDomainObject FIRST_WITH_NESTED = new FirstDomainObject (Optional .of (1L ), ZonedDateTime .parse ("2016-04-03T02:01+07:00[Asia/Vientiane]" ), "payload" , Optional .of (new SecondNestedType ("bar" )));
45
51
46
52
private static final String MISSING_TYPE_JSON = "{\" id\" :1,\" time\" :\" 2016-04-03T02:01+07:00[Asia/Vientiane]\" ,\" payload\" :\" first payload\" }" ;
47
53
private static final String DUPLICATE_TYPE_JSON = "{\" type\" :\" first\" , \" type\" :\" second\" , \" id\" :1,\" time\" :\" 2016-04-03T02:01+07:00[Asia/Vientiane]\" ,\" payload\" :\" first payload\" }" ;
48
54
private static final String FIRST_JSON = "{\" type\" :\" first\" ,\" id\" :1,\" time\" :\" 2016-04-03T02:01+07:00[Asia/Vientiane]\" ,\" payload\" :\" first payload\" }" ;
55
+ private static final String FIRST_JSON_WITH_NESTED = "{\" type\" :\" first\" ,\" id\" :1,\" time\" :\" 2016-04-03T02:01+07:00[Asia/Vientiane]\" ,\" payload\" :\" payload\" , \" child\" : {\" bar\" : \" bar\" , \" type\" : \" second-nested\" }}" ;
49
56
private static final String SECOND_JSON = "{\" type\" :\" second\" ,\" id\" :\" 4a2c853f-7ffc-4ce3-9410-a47e85b3b741\" ,\" payload\" :\" second payload\" }" ;
57
+ private static final String SECOND_WITH_NESTED_JSON = "{\" type\" :\" second\" ,\" id\" :\" 4a2c853f-7ffc-4ce3-9410-a47e85b3b741\" ,\" payload\" :\" second payload\" , \" child\" : {\" foo\" : 12, \" type\" : \" first-nested\" }}" ;
50
58
51
59
@ SuppressWarnings ("unchecked" )
52
60
@ Test
@@ -56,6 +64,22 @@ void shouldDeserializeKnownType() throws Exception {
56
64
.isEqualTo (FIRST );
57
65
}
58
66
67
+ @ SuppressWarnings ("unchecked" )
68
+ @ Test
69
+ void shouldDeserializeNestedTypeWithSecond () throws Exception {
70
+ assertThat (JsonGenericSerializer .of (TestModules .FIRST_TYPE , TestModules .SECOND_TYPE , TestModules .FIRST_NESTED , TestModules .SECOND_NESTED )
71
+ .deserialize (SECOND_WITH_NESTED_JSON ))
72
+ .isEqualTo (SECOND_WITH_NESTED );
73
+ }
74
+
75
+ @ SuppressWarnings ("unchecked" )
76
+ @ Test
77
+ void shouldDeserializeNestedTypeWithFirst () throws Exception {
78
+ assertThat (JsonGenericSerializer .of (TestModules .FIRST_TYPE , TestModules .SECOND_TYPE , TestModules .FIRST_NESTED , TestModules .SECOND_NESTED )
79
+ .deserialize (FIRST_JSON_WITH_NESTED ))
80
+ .isEqualTo (FIRST_WITH_NESTED );
81
+ }
82
+
59
83
@ SuppressWarnings ("unchecked" )
60
84
@ Test
61
85
void shouldThrowWhenDeserializeEventWithMissingType () {
0 commit comments