|
32 | 32 | import java.lang.reflect.Type; |
33 | 33 | import java.util.ArrayList; |
34 | 34 | import java.util.Collection; |
35 | | -import java.util.List; |
36 | 35 |
|
37 | 36 | import static com.arangodb.internal.serde.SerdeUtils.constructParametricType; |
38 | 37 |
|
@@ -111,28 +110,9 @@ private InternalRequest createInsertDocumentRequest(final DocumentCreateOptions |
111 | 110 |
|
112 | 111 | protected <T> ResponseDeserializer<MultiDocumentEntity<DocumentCreateEntity<T>>> insertDocumentsResponseDeserializer(Class<T> userDataClass) { |
113 | 112 | return (response) -> { |
114 | | - final MultiDocumentEntity<DocumentCreateEntity<T>> multiDocument = new MultiDocumentEntity<>(); |
115 | | - final List<DocumentCreateEntity<T>> docs = new ArrayList<>(); |
116 | | - final List<ErrorEntity> errors = new ArrayList<>(); |
117 | | - final List<Object> documentsAndErrors = new ArrayList<>(); |
118 | | - final JsonNode body = getSerde().parse(response.getBody()); |
119 | | - for (final JsonNode next : body) { |
120 | | - JsonNode isError = next.get(ArangoResponseField.ERROR_FIELD_NAME); |
121 | | - if (isError != null && isError.booleanValue()) { |
122 | | - final ErrorEntity error = getSerde().deserialize(next, ErrorEntity.class); |
123 | | - errors.add(error); |
124 | | - documentsAndErrors.add(error); |
125 | | - } else { |
126 | | - Type type = constructParametricType(DocumentCreateEntity.class, userDataClass); |
127 | | - final DocumentCreateEntity<T> doc = getSerde().deserialize(next, type); |
128 | | - docs.add(doc); |
129 | | - documentsAndErrors.add(doc); |
130 | | - } |
131 | | - } |
132 | | - multiDocument.setDocuments(docs); |
133 | | - multiDocument.setErrors(errors); |
134 | | - multiDocument.setDocumentsAndErrors(documentsAndErrors); |
135 | | - return multiDocument; |
| 113 | + Type type = constructParametricType(MultiDocumentEntity.class, |
| 114 | + constructParametricType(DocumentCreateEntity.class, userDataClass)); |
| 115 | + return getSerde().deserialize(response.getBody(), type); |
136 | 116 | }; |
137 | 117 | } |
138 | 118 |
|
@@ -184,31 +164,12 @@ protected InternalRequest getDocumentsRequest(final Iterable<String> keys, final |
184 | 164 | return request; |
185 | 165 | } |
186 | 166 |
|
187 | | - protected <T> ResponseDeserializer<MultiDocumentEntity<T>> getDocumentsResponseDeserializer( |
188 | | - final Class<T> type) { |
| 167 | + protected <T> ResponseDeserializer<MultiDocumentEntity<T>> getDocumentsResponseDeserializer(final Class<T> type) { |
189 | 168 | return (response) -> { |
190 | | - final MultiDocumentEntity<T> multiDocument = new MultiDocumentEntity<>(); |
| 169 | + MultiDocumentEntity<T> multiDocument = getSerde().deserialize(response.getBody(), |
| 170 | + constructParametricType(MultiDocumentEntity.class, type)); |
191 | 171 | boolean potentialDirtyRead = Boolean.parseBoolean(response.getMeta("X-Arango-Potential-Dirty-Read")); |
192 | 172 | multiDocument.setPotentialDirtyRead(potentialDirtyRead); |
193 | | - final List<T> docs = new ArrayList<>(); |
194 | | - final List<ErrorEntity> errors = new ArrayList<>(); |
195 | | - final List<Object> documentsAndErrors = new ArrayList<>(); |
196 | | - final JsonNode body = getSerde().parse(response.getBody()); |
197 | | - for (final JsonNode next : body) { |
198 | | - JsonNode isError = next.get(ArangoResponseField.ERROR_FIELD_NAME); |
199 | | - if (isError != null && isError.booleanValue()) { |
200 | | - final ErrorEntity error = getSerde().deserialize(next, ErrorEntity.class); |
201 | | - errors.add(error); |
202 | | - documentsAndErrors.add(error); |
203 | | - } else { |
204 | | - final T doc = getSerde().deserializeUserData(getSerde().serialize(next), type); |
205 | | - docs.add(doc); |
206 | | - documentsAndErrors.add(doc); |
207 | | - } |
208 | | - } |
209 | | - multiDocument.setDocuments(docs); |
210 | | - multiDocument.setErrors(errors); |
211 | | - multiDocument.setDocumentsAndErrors(documentsAndErrors); |
212 | 173 | return multiDocument; |
213 | 174 | }; |
214 | 175 | } |
@@ -250,28 +211,9 @@ private InternalRequest createReplaceDocumentRequest(final DocumentReplaceOption |
250 | 211 | protected <T> ResponseDeserializer<MultiDocumentEntity<DocumentUpdateEntity<T>>> replaceDocumentsResponseDeserializer( |
251 | 212 | final Class<T> returnType) { |
252 | 213 | return (response) -> { |
253 | | - final MultiDocumentEntity<DocumentUpdateEntity<T>> multiDocument = new MultiDocumentEntity<>(); |
254 | | - final List<DocumentUpdateEntity<T>> docs = new ArrayList<>(); |
255 | | - final List<ErrorEntity> errors = new ArrayList<>(); |
256 | | - final List<Object> documentsAndErrors = new ArrayList<>(); |
257 | | - final JsonNode body = getSerde().parse(response.getBody()); |
258 | | - for (final JsonNode next : body) { |
259 | | - JsonNode isError = next.get(ArangoResponseField.ERROR_FIELD_NAME); |
260 | | - if (isError != null && isError.booleanValue()) { |
261 | | - final ErrorEntity error = getSerde().deserialize(next, ErrorEntity.class); |
262 | | - errors.add(error); |
263 | | - documentsAndErrors.add(error); |
264 | | - } else { |
265 | | - Type type = constructParametricType(DocumentUpdateEntity.class, returnType); |
266 | | - final DocumentUpdateEntity<T> doc = getSerde().deserialize(next, type); |
267 | | - docs.add(doc); |
268 | | - documentsAndErrors.add(doc); |
269 | | - } |
270 | | - } |
271 | | - multiDocument.setDocuments(docs); |
272 | | - multiDocument.setErrors(errors); |
273 | | - multiDocument.setDocumentsAndErrors(documentsAndErrors); |
274 | | - return multiDocument; |
| 214 | + Type type = constructParametricType(MultiDocumentEntity.class, |
| 215 | + constructParametricType(DocumentUpdateEntity.class, returnType)); |
| 216 | + return getSerde().deserialize(response.getBody(), type); |
275 | 217 | }; |
276 | 218 | } |
277 | 219 |
|
@@ -313,28 +255,9 @@ private InternalRequest createUpdateDocumentRequest(final DocumentUpdateOptions |
313 | 255 | protected <T> ResponseDeserializer<MultiDocumentEntity<DocumentUpdateEntity<T>>> updateDocumentsResponseDeserializer( |
314 | 256 | final Class<T> returnType) { |
315 | 257 | return (response) -> { |
316 | | - final MultiDocumentEntity<DocumentUpdateEntity<T>> multiDocument = new MultiDocumentEntity<>(); |
317 | | - final List<DocumentUpdateEntity<T>> docs = new ArrayList<>(); |
318 | | - final List<ErrorEntity> errors = new ArrayList<>(); |
319 | | - final List<Object> documentsAndErrors = new ArrayList<>(); |
320 | | - final JsonNode body = getSerde().parse(response.getBody()); |
321 | | - for (final JsonNode next : body) { |
322 | | - JsonNode isError = next.get(ArangoResponseField.ERROR_FIELD_NAME); |
323 | | - if (isError != null && isError.booleanValue()) { |
324 | | - final ErrorEntity error = getSerde().deserialize(next, ErrorEntity.class); |
325 | | - errors.add(error); |
326 | | - documentsAndErrors.add(error); |
327 | | - } else { |
328 | | - Type type = constructParametricType(DocumentUpdateEntity.class, returnType); |
329 | | - final DocumentUpdateEntity<T> doc = getSerde().deserialize(next, type); |
330 | | - docs.add(doc); |
331 | | - documentsAndErrors.add(doc); |
332 | | - } |
333 | | - } |
334 | | - multiDocument.setDocuments(docs); |
335 | | - multiDocument.setErrors(errors); |
336 | | - multiDocument.setDocumentsAndErrors(documentsAndErrors); |
337 | | - return multiDocument; |
| 258 | + Type type = constructParametricType(MultiDocumentEntity.class, |
| 259 | + constructParametricType(DocumentUpdateEntity.class, returnType)); |
| 260 | + return getSerde().deserialize(response.getBody(), type); |
338 | 261 | }; |
339 | 262 | } |
340 | 263 |
|
@@ -370,28 +293,9 @@ private InternalRequest createDeleteDocumentRequest(final DocumentDeleteOptions |
370 | 293 | protected <T> ResponseDeserializer<MultiDocumentEntity<DocumentDeleteEntity<T>>> deleteDocumentsResponseDeserializer( |
371 | 294 | final Class<T> userDataClass) { |
372 | 295 | return (response) -> { |
373 | | - final MultiDocumentEntity<DocumentDeleteEntity<T>> multiDocument = new MultiDocumentEntity<>(); |
374 | | - final List<DocumentDeleteEntity<T>> docs = new ArrayList<>(); |
375 | | - final List<ErrorEntity> errors = new ArrayList<>(); |
376 | | - final List<Object> documentsAndErrors = new ArrayList<>(); |
377 | | - final JsonNode body = getSerde().parse(response.getBody()); |
378 | | - for (final JsonNode next : body) { |
379 | | - JsonNode isError = next.get(ArangoResponseField.ERROR_FIELD_NAME); |
380 | | - if (isError != null && isError.booleanValue()) { |
381 | | - final ErrorEntity error = getSerde().deserialize(next, ErrorEntity.class); |
382 | | - errors.add(error); |
383 | | - documentsAndErrors.add(error); |
384 | | - } else { |
385 | | - Type type = constructParametricType(DocumentDeleteEntity.class, userDataClass); |
386 | | - final DocumentDeleteEntity<T> doc = getSerde().deserialize(next, type); |
387 | | - docs.add(doc); |
388 | | - documentsAndErrors.add(doc); |
389 | | - } |
390 | | - } |
391 | | - multiDocument.setDocuments(docs); |
392 | | - multiDocument.setErrors(errors); |
393 | | - multiDocument.setDocumentsAndErrors(documentsAndErrors); |
394 | | - return multiDocument; |
| 296 | + Type type = constructParametricType(MultiDocumentEntity.class, |
| 297 | + constructParametricType(DocumentDeleteEntity.class, userDataClass)); |
| 298 | + return getSerde().deserialize(response.getBody(), type); |
395 | 299 | }; |
396 | 300 | } |
397 | 301 |
|
|
0 commit comments