MorphiaOrg / MorphiaOrg/morphia
How do I register a custom codec
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 1.7k
- Forks
- 449
- Avg merge
- 7m
- Merged PRs (30d)
- 10
Description
** Please ask your question and provide whatever background or supporting information you think might be relevant: **
I am currently trying to register a codec that I have created for the Bukkit ItemStack class but I cannot figure out how to register it. I have already looked at both MongoDB's and Morphia's documentation but was unable to find anything. Here is my Mongo Registration class
object MongoDatabase {
lateinit var datastore: Datastore
var connect by Delegates.notNull<Boolean>()
fun init() {
connect = false
try {
val mongoUri = ClickerServer.getInstance().config.getString("mongo.uri")
if (mongoUri == null) {
ClickerServer.getInstance().logger.severe("MongoDB URI not found in config.yml")
ClickerServer.getInstance().server.pluginManager.disablePlugin(ClickerServer.getInstance())
throw IllegalStateException("MongoDB URI not found in config.yml")
}
datastore = Morphia.createDatastore(MongoClients.create(mongoUri), ClickerServer.getInstance().config.getString("mongo.db")!!)
datastore.mapper.config.packages(listOf("dev.reassembly.clickerserver.models"))
// TODO: Register Codec here
connect = true
} catch (e: Exception) {
connect = false
e.printStackTrace()
}
}
}
** Please complete the following information: **
Server Version: Unsure, I'm using mongo atlas if that's the question
Driver Version: Whichever one comes bundled in morphia
Morphia Version: 2.4.11
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the MongoDatabase.init entry point and its TODO for codec registration, then check the Morphia 2.4.11 and MongoDB driver documentation referenced by the report. Confirm the supported registration path for a Bukkit ItemStack codec and document a complete example or identify the missing API behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kotlin, mongodb
- Domain
- backend, databases
- Issue type
- Documentation
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100