MorphiaOrg / MorphiaOrg/morphia

How do I register a custom codec

Open
#2,990 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

question
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.