4040 * @author Igor Stepanov
4141 * @author Artem Bilan
4242 * @author Yanming Zhou
43+ * @author Torsten Schleede
4344 */
4445public class JsonSerializationTests {
4546
4647 private StringSerializer stringWriter ;
4748
4849 private StringDeserializer stringReader ;
4950
50- private JsonSerializer <DummyEntity > jsonWriter ;
51+ private JsonSerializer <Object > jsonWriter ;
5152
5253 private JsonDeserializer <DummyEntity > jsonReader ;
5354
55+ private JsonDeserializer <DummyEntity []> jsonArrayReader ;
56+
5457 private JsonDeserializer <DummyEntity > dummyEntityJsonDeserializer ;
5558
59+ private JsonDeserializer <DummyEntity []> dummyEntityArrayJsonDeserializer ;
60+
5661 private DummyEntity entity ;
5762
63+ private DummyEntity [] entityArray ;
64+
5865 private String topic ;
5966
6067 @ Before
@@ -66,12 +73,16 @@ public void init() {
6673 List <String > list = Arrays .asList ("dummy1" , "dummy2" );
6774 entity .complexStruct = new HashMap <>();
6875 entity .complexStruct .put ((short ) 4 , list );
76+ entityArray = new DummyEntity [] { entity };
6977
7078 topic = "topic-name" ;
7179
7280 jsonReader = new JsonDeserializer <DummyEntity >() { };
7381 jsonReader .configure (new HashMap <String , Object >(), false );
7482 jsonReader .close (); // does nothing, so may be called any time, or not called at all
83+ jsonArrayReader = new JsonDeserializer <DummyEntity []>() { };
84+ jsonArrayReader .configure (new HashMap <String , Object >(), false );
85+ jsonArrayReader .close (); // does nothing, so may be called any time, or not called at all
7586 jsonWriter = new JsonSerializer <>();
7687 jsonWriter .configure (new HashMap <String , Object >(), false );
7788 jsonWriter .close (); // does nothing, so may be called any time, or not called at all
@@ -80,6 +91,7 @@ public void init() {
8091 stringWriter = new StringSerializer ();
8192 stringWriter .configure (new HashMap <String , Object >(), false );
8293 dummyEntityJsonDeserializer = new DummyEntityJsonDeserializer ();
94+ dummyEntityArrayJsonDeserializer = new DummyEntityArrayJsonDeserializer ();
8395 }
8496
8597 /*
@@ -95,6 +107,19 @@ public void testDeserializeSerializedEntityEquals() {
95107 assertThat (dummyEntityJsonDeserializer .deserialize (topic , headers , jsonWriter .serialize (topic , entity ))).isEqualTo (entity );
96108 }
97109
110+ /*
111+ * 1. Serialize test entity array to byte array.
112+ * 2. Deserialize it back from the created byte array.
113+ * 3. Check the result with the source entity array.
114+ */
115+ @ Test
116+ public void testDeserializeSerializedEntityArrayEquals () {
117+ assertThat (jsonArrayReader .deserialize (topic , jsonWriter .serialize (topic , entityArray ))).isEqualTo (entityArray );
118+ Headers headers = new RecordHeaders ();
119+ headers .add (AbstractJavaTypeMapper .DEFAULT_CLASSID_FIELD_NAME , DummyEntity [].class .getName ().getBytes ());
120+ assertThat (dummyEntityArrayJsonDeserializer .deserialize (topic , headers , jsonWriter .serialize (topic , entityArray ))).isEqualTo (entityArray );
121+ }
122+
98123 /*
99124 * 1. Serialize "dummy" String to byte array.
100125 * 2. Deserialize it back from the created byte array.
@@ -151,4 +176,8 @@ static class DummyEntityJsonDeserializer extends JsonDeserializer<DummyEntity> {
151176
152177 }
153178
179+ static class DummyEntityArrayJsonDeserializer extends JsonDeserializer <DummyEntity []> {
180+
181+ }
182+
154183}
0 commit comments