Class BsonUtils

    • 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.
    • Constructor Detail

      • BsonUtils

        public BsonUtils()
    • 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 provided Decoder.
        Type Parameters:
        T - the type into which the JSON string is decoded.
        Parameters:
        json - the JSON string to parse.
        valueDecoder - the Decoder 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 a CodecConfigurationException.
        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 a CodecConfigurationException.
        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.
      • documentToBsonDocument

        public static <T> BsonDocument documentToBsonDocument​(T document,
                                                              CodecRegistry codecRegistry)
      • documentToBsonDocument

        public static <T> BsonDocument documentToBsonDocument​(T document,
                                                              Codec<T> codec)
      • 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.