public static Document documentFromObject(Object document) { return Document.FromObject(document); }
static Document FromObject(Object document) { return FromObject(document, new ObjectMapper()); }
/** * Replaces a document using a POJO object. * * @param documentLink the document link. * @param document the document represented as a POJO or Document object. * @param options the request options. * @return the resource response with the replaced document. * @throws DocumentClientException the document client exception. */ public ResourceResponse<Document> replaceDocument(String documentLink, Object document, RequestOptions options) throws DocumentClientException { if (StringUtils.isEmpty(documentLink)) { throw new IllegalArgumentException("documentLink"); } if (document == null) { throw new IllegalArgumentException("document"); } Document typedDocument = Document.FromObject(document, objectMapper); return this.replaceDocumentInternal(documentLink, typedDocument, options); }
private DocumentServiceRequest getCreateDocumentRequest(String documentCollectionLink, Object document, RequestOptions options, boolean disableAutomaticIdGeneration, OperationType operationType) { if (StringUtils.isEmpty(documentCollectionLink)) { throw new IllegalArgumentException("documentCollectionLink"); } if (document == null) { throw new IllegalArgumentException("document"); } Document typedDocument = Document.FromObject(document, objectMapper); DocumentClient.validateResource(typedDocument); if (typedDocument.getId() == null && !disableAutomaticIdGeneration) { // We are supposed to use GUID. Basically UUID is the same as GUID // when represented as a string. typedDocument.setId(Utils.getSecureRandomUUID().toString()); } String path = Utils.joinPath(documentCollectionLink, Paths.DOCUMENTS_PATH_SEGMENT); Map<String, String> requestHeaders = getRequestHeaders(options); DocumentServiceRequest request = DocumentServiceRequest.create(operationType, ResourceType.Document, path, typedDocument, requestHeaders); this.addPartitionKeyInformation(request, typedDocument, options); return request; }