diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 94a25f7..35eb1dd 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/json/src/main/kotlin/ai/neuon/utility/bson/json/BsonJson.kt b/json/src/main/kotlin/ai/neuon/utility/bson/json/BsonJson.kt index 1495211..5f71a5f 100644 --- a/json/src/main/kotlin/ai/neuon/utility/bson/json/BsonJson.kt +++ b/json/src/main/kotlin/ai/neuon/utility/bson/json/BsonJson.kt @@ -10,6 +10,8 @@ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +@file:OptIn(ExperimentalTime::class) + package ai.neuon.utility.bson.json import kotlinx.serialization.json.JsonArray @@ -18,6 +20,8 @@ import kotlinx.serialization.json.buildJsonArray import kotlinx.serialization.json.buildJsonObject import kotlinx.serialization.json.put import org.bson.BsonArray +import org.bson.BsonBoolean +import org.bson.BsonDateTime import org.bson.BsonDocument import org.bson.BsonDouble import org.bson.BsonInt32 @@ -25,6 +29,8 @@ import org.bson.BsonInt64 import org.bson.BsonNumber import org.bson.BsonObjectId import org.bson.BsonString +import kotlin.time.ExperimentalTime +import kotlin.time.Instant fun BsonArray.toJsonArray(): JsonArray = buildJsonArray { forEach { bson -> @@ -45,8 +51,11 @@ fun BsonDocument.toJsonObject(): JsonObject = buildJsonObject { is BsonDouble -> this.put(key, value.value) is BsonNumber -> this.put(key, value.doubleValue()) is BsonString -> this.put(key, value.value) + is BsonBoolean -> this.put(key, value.value) + is BsonDateTime -> this.put(key, Instant.fromEpochMilliseconds(value.value).toString()) is BsonArray -> this.put(key, value.toJsonArray()) is BsonDocument -> this.put(key, value.toJsonObject()) + else -> {} } } } \ No newline at end of file