@@ -119,4 +119,45 @@ public void testReadJsonWithLock() throws IOException, URISyntaxException, Diges
119
119
"4945ba5011739b0b98c4a41afe224e417f47c7c99b2ce76830999c9a0861b236" ))));
120
120
// ignore testJson.list
121
121
}
122
+
123
+ @ Test
124
+ public void testReadListOfJson () throws IOException , URISyntaxException , DigestException {
125
+ Path jsonFile = Paths .get (Resources .getResource ("json/basic_list.json" ).toURI ());
126
+
127
+ String jsonString = new String (Files .readAllBytes (jsonFile ), StandardCharsets .UTF_8 );
128
+ List <TestJson > listofJsons = JsonTemplateMapper .readListOfJson (jsonString , TestJson .class );
129
+ TestJson json1 = listofJsons .get (0 );
130
+ TestJson json2 = listofJsons .get (1 );
131
+
132
+ DescriptorDigest digest1 =
133
+ DescriptorDigest .fromDigest (
134
+ "sha256:91e0cae00b86c289b33fee303a807ae72dd9f0315c16b74e6ab0cdbe9d996c10" );
135
+ DescriptorDigest digest2 =
136
+ DescriptorDigest .fromDigest (
137
+ "sha256:8c662931926fa990b41da3c9f42663a537ccd498130030f9149173a0493832ad" );
138
+
139
+ Assert .assertEquals (1 , json1 .number );
140
+ Assert .assertEquals (2 , json2 .number );
141
+ Assert .assertEquals ("text1" , json1 .text );
142
+ Assert .assertEquals ("text2" , json2 .text );
143
+ Assert .assertEquals (digest1 , json1 .digest );
144
+ Assert .assertEquals (digest2 , json2 .digest );
145
+ Assert .assertEquals (10 , json1 .innerObject .number );
146
+ Assert .assertEquals (20 , json2 .innerObject .number );
147
+ Assert .assertEquals (2 , json1 .list .size ());
148
+ Assert .assertTrue (json2 .list .isEmpty ());
149
+ }
150
+
151
+ @ Test
152
+ public void testToBlob_listOfJson () throws IOException , URISyntaxException , DigestException {
153
+ Path jsonFile = Paths .get (Resources .getResource ("json/basic_list.json" ).toURI ());
154
+
155
+ String jsonString = new String (Files .readAllBytes (jsonFile ), StandardCharsets .UTF_8 );
156
+ List <TestJson > listOfJson = JsonTemplateMapper .readListOfJson (jsonString , TestJson .class );
157
+
158
+ ByteArrayOutputStream jsonStream = new ByteArrayOutputStream ();
159
+ JsonTemplateMapper .toBlob (listOfJson ).writeTo (jsonStream );
160
+
161
+ Assert .assertEquals (jsonString , jsonStream .toString ());
162
+ }
122
163
}
0 commit comments