MorphiaOrg / MorphiaOrg/morphia

How to add a default codec for internal objects of an entity

Open
#3,181 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

I'm having problems reading an object that has another object defined inside. It tells me that it doesn't find a codec and therefore I would like to add a default pojoCodec as is possible in the driver.

The codecRegistry would be this:
MongoClientSettings.getDefaultCodecRegistry(), CodecRegistries.fromProviders(PojoCodecProvider.builder().automatic(true).build())

The problem is that if I add this to MapperOptions then it adds them before the Morphia Codecs and then the aggregations don't work, for example, the $match expression decodes it with the default codec.

Is there a way to do this?
Or what is the solution for internal objects of an entity?

Thanks!

** Please complete the following information: **
Morphia Version: 2.4.14

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 by reproducing the nested-object codec failure with Morphia 2.4.14, focusing on MapperOptions, the MongoClientSettings codec registry, and an aggregation using $match. Trace how adding PojoCodecProvider before Morphia codecs changes decoding; done means internal entity objects decode correctly without breaking aggregation expressions.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, mongodb
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.