Class JsonDocument
- java.lang.Object
-
- com.couchbase.client.java.document.AbstractDocument<JsonObject>
-
- com.couchbase.client.java.document.JsonDocument
-
- All Implemented Interfaces:
Document<JsonObject>
,Serializable
public class JsonDocument extends AbstractDocument<JsonObject> implements Serializable
Represents aDocument
that contains aJsonObject
as the content. TheJsonDocument
is one of the most integral parts of the API. It is intended to be used as a canonical wrapper around retrieval and mutation operations, abstracting away JSON internals. Note that there is no public constructor available, but rather a multitude of factory methods that allow you to work nicely with this immutable value object. It is possible to construct empty/fresh ones, but also copies will be created from passed in documents, allowing you to override specific parts during the copy process. This document is interoperable with other SDKs. It can always be the case that some or all fields of aJsonDocument
are not set, depending on the operation performed. Here are the accessible fields and their default values: +---------------+---------+ | Field | Default | +---------------+---------+ | id | null | | content | null | | cas | 0 | | expiry | 0 | | status | null | | mutationToken | null | +---------------+---------+- Since:
- 2.0
- Author:
- Michael Nitschinger
- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static JsonDocument
create(String id)
Creates aJsonDocument
which the document id.static JsonDocument
create(String id, int expiry, JsonObject content)
Creates aJsonDocument
which the document id, JSON content and the expiration time.static JsonDocument
create(String id, int expiry, JsonObject content, long cas)
Creates aJsonDocument
which the document id, JSON content, CAS value, expiration time and status code.static JsonDocument
create(String id, int expiry, JsonObject content, long cas, MutationToken mutationToken)
Creates aJsonDocument
which the document id, JSON content, CAS value, expiration time and status code.static JsonDocument
create(String id, JsonObject content)
Creates aJsonDocument
which the document id and JSON content.static JsonDocument
create(String id, JsonObject content, long cas)
Creates aJsonDocument
which the document id, JSON content and the CAS value.static JsonDocument
from(JsonDocument doc, long cas)
Creates a copy from a differentJsonDocument
, but changes the CAS value.static JsonDocument
from(JsonDocument doc, JsonObject content)
Creates a copy from a differentJsonDocument
, but changes the content.static JsonDocument
from(JsonDocument doc, String id)
Creates a copy from a differentJsonDocument
, but changes the document ID.static JsonDocument
from(JsonDocument doc, String id, JsonObject content)
Creates a copy from a differentJsonDocument
, but changes the document ID and content.-
Methods inherited from class com.couchbase.client.java.document.AbstractDocument
cas, content, equals, expiry, hashCode, id, mutationToken, readFromSerializedStream, toString, writeToSerializedStream
-
-
-
-
Method Detail
-
create
public static JsonDocument create(String id)
Creates aJsonDocument
which the document id.- Parameters:
id
- the per-bucket unique document id.- Returns:
- a
JsonDocument
.
-
create
public static JsonDocument create(String id, JsonObject content)
Creates aJsonDocument
which the document id and JSON content.- Parameters:
id
- the per-bucket unique document id.content
- the content of the document.- Returns:
- a
JsonDocument
.
-
create
public static JsonDocument create(String id, JsonObject content, long cas)
Creates aJsonDocument
which the document id, JSON content and the CAS value.- Parameters:
id
- the per-bucket unique document id.content
- the content of the document.cas
- the CAS (compare and swap) value for optimistic concurrency.- Returns:
- a
JsonDocument
.
-
create
public static JsonDocument create(String id, int expiry, JsonObject content)
Creates aJsonDocument
which the document id, JSON content and the expiration time.- Parameters:
id
- the per-bucket unique document id.content
- the content of the document.expiry
- the expiration time of the document.- Returns:
- a
JsonDocument
.
-
create
public static JsonDocument create(String id, int expiry, JsonObject content, long cas)
Creates aJsonDocument
which the document id, JSON content, CAS value, expiration time and status code. This factory method is normally only called within the client library when a response is analyzed and a document is returned which is enriched with the status code. It does not make sense to pre populate the status field from the user level code.- Parameters:
id
- the per-bucket unique document id.content
- the content of the document.cas
- the CAS (compare and swap) value for optimistic concurrency.expiry
- the expiration time of the document.- Returns:
- a
JsonDocument
.
-
create
public static JsonDocument create(String id, int expiry, JsonObject content, long cas, MutationToken mutationToken)
Creates aJsonDocument
which the document id, JSON content, CAS value, expiration time and status code. This factory method is normally only called within the client library when a response is analyzed and a document is returned which is enriched with the status code. It does not make sense to pre populate the status field from the user level code.- Parameters:
id
- the per-bucket unique document id.content
- the content of the document.cas
- the CAS (compare and swap) value for optimistic concurrency.expiry
- the expiration time of the document.- Returns:
- a
JsonDocument
.
-
from
public static JsonDocument from(JsonDocument doc, String id)
Creates a copy from a differentJsonDocument
, but changes the document ID.- Parameters:
doc
- the originalJsonDocument
to copy.id
- the per-bucket unique document id.- Returns:
- a copied
JsonDocument
with the changed properties.
-
from
public static JsonDocument from(JsonDocument doc, JsonObject content)
Creates a copy from a differentJsonDocument
, but changes the content.- Parameters:
doc
- the originalJsonDocument
to copy.content
- the content of the document.- Returns:
- a copied
JsonDocument
with the changed properties.
-
from
public static JsonDocument from(JsonDocument doc, String id, JsonObject content)
Creates a copy from a differentJsonDocument
, but changes the document ID and content.- Parameters:
doc
- the originalJsonDocument
to copy.id
- the per-bucket unique document id.content
- the content of the document.- Returns:
- a copied
JsonDocument
with the changed properties.
-
from
public static JsonDocument from(JsonDocument doc, long cas)
Creates a copy from a differentJsonDocument
, but changes the CAS value.- Parameters:
doc
- the originalJsonDocument
to copy.cas
- the CAS (compare and swap) value for optimistic concurrency.- Returns:
- a copied
JsonDocument
with the changed properties.
-
-