4 Commits

Author SHA1 Message Date
93f2f822d4 update(BsonJson): add date and boolean support 2026-09-11 15:43:48 +08:00
74f7ca2db2 release -> v0.1.2 2026-09-10 18:13:40 +08:00
bbf351f169 update(BsonJson): add date and boolean support 2026-09-10 18:04:22 +08:00
f907f89ca2 change package name 2025-08-15 16:39:32 +08:00
4 changed files with 12 additions and 3 deletions

2
.idea/vcs.xml generated
View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
<mapping directory="" vcs="Git" />
</component>
</project>

View File

@@ -3,4 +3,4 @@ plugins {
}
group = "ai.neuon.utility"
version = "0.1.0"
version = "0.1.2"

View File

@@ -33,7 +33,7 @@ publishing {
publications {
create<MavenPublication>("maven") {
groupId = rootProject.group.toString()
artifactId = "bson-core"
artifactId = "bson"
version = rootProject.version.toString()
from(components["java"])
artifact(javadocJar)

View File

@@ -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 -> {}
}
}
}