Currently, I am working on a Kotlin multi-project solution. One project defines data classes and an API to access a MongoDB where the ObjectId is automatically created. This particular project uses Morphia version 1.3.2. Entries are stored using the following function:
fun store(myClass: MyClass) = db.save(myClass).let { myClass.id?.toHexString() ?: "0" }
Now, I am integrating this project into a Spring Boot Kotlin project. I have developed a small webpage with filters that should be applied to my query successfully.
The results of my query are returned via my Rest-controller without any conversions. However, when attempting to print the ObjectId for each result on my webpage, it appears as an object instead of a String:
id:
counter:15304909
date:"2018-08-27T23:45:35.000+0000"
machineIdentifier:123456
processIdentifier:1234
time:1535413535000
timeSecond:1535413535
timestamp:1535413535
I am wondering if there is a way to force Morphia to return the ObjectId in its String representation or enable correct mapping options. Alternatively, do I need to manually convert each object id to hexadecimal string representation? I am hopeful for a more efficient solution to this issue.
Additionally, I encountered difficulties when trying to remap the object to a valid ID due to a
java.lang.IllegalArgumentException: Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986
exception. The request appears as follows:
myClass?id={"timestamp":1535413631,"machineIdentifier":123456,"processIdentifier":1234,"counter":16576969,"time":1535413631000,"date":"2018-08-27T23:47:11.000+0000","timeSecond":1535413631}
At present, I am exploring various solutions to resolve this issue.