Class BsonUtils
- java.lang.Object
-
- java.lang.Throwable
-
- java.lang.Exception
-
- java.lang.RuntimeException
-
- com.mongodb.stitch.core.internal.common.BsonUtils
-
- All Implemented Interfaces:
Serializable
public final class BsonUtils extends RuntimeException
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static CodecRegistry
DEFAULT_CODEC_REGISTRY
A basic codec registry which provides codecs for all BSON types, BSON documents, iterable types, and maps.
-
Constructor Summary
Constructors Constructor Description BsonUtils()
-
Method Summary
Modifier and Type Method Description static BsonDocument
copyOfDocument(BsonDocument document)
Returns a copy of the given document.static <T> BsonDocument
documentToBsonDocument(T document, Codec<T> codec)
static <T> BsonDocument
documentToBsonDocument(T document, CodecRegistry codecRegistry)
static <T> Codec<T>
getCodec(CodecRegistry codecRegistry, Class<T> documentClass)
static BsonValue
getDocumentId(BsonDocument document)
static <T> T
parseValue(String json, Class<T> valueClass)
Parses the provided extended JSON string and decodes it into a T value as specified by the provided class type.static <T> T
parseValue(String json, Class<T> valueClass, CodecRegistry codecRegistry)
Parses the provided extended JSON string and decodes it into a T value as specified by the provided class type.static <T> T
parseValue(String json, Decoder<T> valueDecoder)
Parses the provided extended JSON string and decodes it into a T value as specified by the providedDecoder
.static <T> BsonDocument
toBsonDocument(Bson bson, Class<T> documentClass, CodecRegistry codecRegistry)
static <T> BsonDocument
toBsonDocumentOrNull(Bson document, Class<T> documentClass, CodecRegistry codecRegistry)
-
Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
-
-
-
Field Detail
-
DEFAULT_CODEC_REGISTRY
public static final CodecRegistry DEFAULT_CODEC_REGISTRY
A basic codec registry which provides codecs for all BSON types, BSON documents, iterable types, and maps.
-
-
Method Detail
-
parseValue
public static <T> T parseValue(String json, Decoder<T> valueDecoder)
Parses the provided extended JSON string and decodes it into a T value as specified by the providedDecoder
.- Type Parameters:
T
- the type into which the JSON string is decoded.- Parameters:
json
- the JSON string to parse.valueDecoder
- theDecoder
to use to convert the BSON value into the type T.- Returns:
- the decoded value.
-
parseValue
public static <T> T parseValue(String json, Class<T> valueClass)
Parses the provided extended JSON string and decodes it into a T value as specified by the provided class type. The type will decoded using the codec found for the type in the default codec registry. If the provided type is not supported by the default codec registry, the method will throw aCodecConfigurationException
.- Type Parameters:
T
- the type into which the JSON string is decoded.- Parameters:
json
- the JSON string to parse.valueClass
- the class that the JSON string should be decoded into.- Returns:
- the decoded value.
-
parseValue
public static <T> T parseValue(String json, Class<T> valueClass, CodecRegistry codecRegistry)
Parses the provided extended JSON string and decodes it into a T value as specified by the provided class type. The type will decoded using the codec found for the type in the provided codec registry. If the provided type is not supported by the provided codec registry, the method will throw aCodecConfigurationException
.- Type Parameters:
T
- the type into which the JSON string is decoded.- Parameters:
json
- the JSON string to parse.valueClass
- the class that the JSON string should be decoded into.codecRegistry
- the codec registry to use to find the codec for the provided class.- Returns:
- the decoded value.
-
getCodec
public static <T> Codec<T> getCodec(CodecRegistry codecRegistry, Class<T> documentClass)
-
documentToBsonDocument
public static <T> BsonDocument documentToBsonDocument(T document, CodecRegistry codecRegistry)
-
documentToBsonDocument
public static <T> BsonDocument documentToBsonDocument(T document, Codec<T> codec)
-
toBsonDocument
public static <T> BsonDocument toBsonDocument(Bson bson, Class<T> documentClass, CodecRegistry codecRegistry)
-
getDocumentId
public static BsonValue getDocumentId(BsonDocument document)
-
copyOfDocument
public static BsonDocument copyOfDocument(BsonDocument document)
Returns a copy of the given document.- Parameters:
document
- the document to copy.- Returns:
- a copy of the given document.
-
toBsonDocumentOrNull
public static <T> BsonDocument toBsonDocumentOrNull(Bson document, Class<T> documentClass, CodecRegistry codecRegistry)
-
-