/** * Serializes provided {@link JSONAPIDocument} into JSON API Spec compatible byte representation. * @param document {@link JSONAPIDocument} document to serialize * @return serialized content in bytes * @throws DocumentSerializationException thrown in case serialization fails */ public byte [] writeDocument(JSONAPIDocument<?> document) throws DocumentSerializationException { return writeDocument(document, null); }
@Override public RequestBody convert(T t) throws IOException { try { MediaType mediaType = MediaType.parse("application/vnd.api+json"); JSONAPIDocument<?> document; boolean isCollection; if (t instanceof JSONAPIDocument) { document = (JSONAPIDocument<?>) t; isCollection = Iterable.class.isAssignableFrom(document.get().getClass()); } else { document = new JSONAPIDocument<>(t); isCollection = Iterable.class.isAssignableFrom(t.getClass()); } if (isCollection) { return RequestBody.create(mediaType, converter.writeDocumentCollection((JSONAPIDocument<? extends Iterable<?>>) document)); } else { return RequestBody.create(mediaType, converter.writeDocument(document)); } } catch (Exception e) { throw new RuntimeException(e); } } }
@Override public RequestBody convert(T t) throws IOException { try { MediaType mediaType = MediaType.parse("application/vnd.api+json"); JSONAPIDocument<?> document; boolean isCollection; if (t instanceof JSONAPIDocument) { document = (JSONAPIDocument<?>) t; isCollection = Iterable.class.isAssignableFrom(document.get().getClass()); } else { document = new JSONAPIDocument<>(t); isCollection = Iterable.class.isAssignableFrom(t.getClass()); } if (isCollection) { return RequestBody.create(mediaType, converter.writeDocumentCollection((JSONAPIDocument<? extends Iterable<?>>) document)); } else { return RequestBody.create(mediaType, converter.writeDocument(document)); } } catch (Exception e) { throw new RuntimeException(e); } } }
/** * Serializes provided {@link JSONAPIDocument} into JSON API Spec compatible byte representation. * @param document {@link JSONAPIDocument} document to serialize * @return serialized content in bytes * @throws DocumentSerializationException thrown in case serialization fails */ public byte [] writeDocument(JSONAPIDocument<?> document) throws DocumentSerializationException { return writeDocument(document, null); }
/** * Converts input object to byte array. * @param object input object * @return raw bytes * @throws JsonProcessingException * @throws IllegalAccessException */ @Deprecated public byte [] writeObject(Object object) throws JsonProcessingException, IllegalAccessException { try { return writeDocument(new JSONAPIDocument<>(object)); } catch (DocumentSerializationException e) { throw new RuntimeException(e); } }
/** * Converts input object to byte array. * @param object input object * @return raw bytes * @throws JsonProcessingException * @throws IllegalAccessException */ @Deprecated public byte [] writeObject(Object object) throws JsonProcessingException, IllegalAccessException { try { return writeDocument(new JSONAPIDocument<>(object)); } catch (DocumentSerializationException e) { throw new RuntimeException(e); } }