简体   繁体   中英

Seem like i can't handle response from mongodb when using hyphen in field name

I didn't see any recommendation about using hyphen in field name at all

Even with @serialName it still didn't work

@SerialName("created-date")
val created_date: String,

but It worked fine with underscore (now i'm using it)

The reason i used it in the first place is because I have used a few api and most of them used hyphen and i just want to follow the common name.

If anyone know why please kindly tell me. I might be missing any docs or sth

There is a page in MongoDB documentation, I'm putting a shortcut for restrictions based on field names https://docs.mongodb.com/manual/reference/limits/#mongodb-limit-Restrictions-on-Field-Names .

MongoDB can store various different field names even you can have "space" in field name. It is not a problem for MongoDB, but once your application receives MongoDB output, it should be deserialized. I have never used kotlinx.serialization before; hence I'm just guessing. What if the problem might be coming from serialization/deserialization process. You better check kotlinx.serialization, maybe something is there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM