0

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

sidgate
  • 14,650
  • 11
  • 68
  • 119
adwardwo1f
  • 817
  • 6
  • 18

1 Answers1

0

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.

nurisezgin
  • 1,530
  • 12
  • 19
  • thanks but in this case i use ktor so i couldn't even use this model class to handle a response. I can't deserialized since i didn't recieve a response. – adwardwo1f Jul 13 '21 at 04:44