Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7037435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:32:41+00:00 2026-05-28T01:32:41+00:00

Short summaries before the simple examples : Inserting new documents is OK, in the

  • 0

Short summaries before the simple examples :

  • Inserting new documents is OK, in the meaning that it uses my custom converter
  • Updating an existing document is not OK, in the meaning that it doesnt use my custom converter

My deps :

[INFO] +- org.springframework.data:spring-data-mongodb:jar:1.0.0.RC1:compile
[INFO] | +- org.springframework:spring-beans:jar:3.1.0.RELEASE:compile
[INFO] | +- org.springframework:spring-expression:jar:3.1.0.RELEASE:compile
[INFO] | +- org.springframework.data:spring-data-commons-core:jar:1.2.0.RC1:compile
[INFO] | | \- org.springframework:spring-tx:jar:3.1.0.RELEASE:compile
[INFO] | \- org.mongodb:mongo-java-driver:jar:2.7.1:compile

Here’s my class that has the it’s own converter

public class MyClass extends MyInterface<String> ..

Here are the the converters :

public class MyClassWriteConverter implements Converter<MyClass, DBObject> {
    @Override
    public DBObject convert(MyClass myClass) {
        System.out.println("MyClass WRITE CONVERTER !");
        DBObject dbo = new BasicDBObject();
        dbo.put("title", myClass.getTitle());
        dbo.put("value", myClass.getValue());
        System.out.println("value : " + myClass.getValue());
        System.out.println("class : " + myClass.getClass().getCanonicalName());
        dbo.put("_class", myClass.getClass().getCanonicalName());
        return dbo;
    }
}
public class MyClassElementReadConverter implements Converter<DBObject, MyClass> {
    @Override
    public MyClass convert(DBObject dbObject) {
        String value = (String) dbObject.get("value");
        String title = (String) dbObject.get("title");
        return new MyClass(title, value);
    }
}

<mongo:converter>
    <bean class="kam.albert.MyClassElementReadConverter" />
</mongo:converter>
<mongo:converter>
    <bean class="kam.albert.MyClassElementWriteConverter" />
</mongo:converter>

myDomain has a List<MyClass<?>> myClasses,
and this works fine, as the custom converter is being used :

this.ops.save(myDomain, "myCollection");

Which can be seen from the debugging output :

MyClass ELEMENT WRITE CONVERTER !
value : my value
class : kam.albert.MyClass

And has the result from my db.myCollection.find().pretty(); :

{
    myClasses : [
        {
             "title" : "my title",
             "value" : "my value",
             "_class" : "kam.albert.MyClass"
        }
    ]
}

All is still OK with the insert operation …

But when i make $set update to an existing document like this :

this.ops.updateFirst(
    this.idCriteria(myClass),
    new Update()
        // set the content node
        .set(dotNotation, myClass),
        "myCollection"
);

The debugging output stays the same :

MyClass ELEMENT WRITE CONVERTER !
value : my value
class : kam.albert.MyClass
(edited for clarity, the other properties omitted)
DEBUG [mongodb.core.MongoTemplate]: calling update using query: { "_id" : "81d3292e-fd75-410d-a1f9-b109b6d76194"} and update: { "$
set" : { "myClasses" : [ { "title" : "my title" , "value" : "my value"}]}] } in collection: myCollection

But the result is like without using the custom converter, without the “_class” attribute :

{
    myClasses : [
        {
             "title" : "my title",
             "value" : "my value",
        }
    ]
}

My current conclusions are :

  • For inserting a new document, the custom converter works fine
  • For updating though, although the custom converter seems to be called (the debugging output is there), but it seems to be using
    the default MappingMongoConverter to do the real update.

Am i missing something ? Please share your thoughts ..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T01:32:41+00:00Added an answer on May 28, 2026 at 1:32 am

    It seems that the current version (1.0 GA as of the time of writing) does not pipe the Update object into the QueryMapper which is responsible to massage the contained potentially complex objects into ones MongoDB can handle handle natively. In that process the MongoConverter should be invoked which should in turn trigger your custom converters.

    The issue is captured in the ticket you just filed and will be fixed with the next bugfix release (1.0.1, 1.1.M1).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Short of copying the entire .netbeans directory is there any way to transfer custom
Short Version: When I've created a Channel using ChannelFactory on a client which uses
Short of inserting a try/catch block in each worker thread method, is there a
I'm fairly new to WPF and looking for a simple solution to the problem
Short Question Is there a library that is supposed to replace mswinsoc.osx used to
I have a simple search form that looks something like: app/views/search/index.html.erb <%= form_for @search,
Short question: Is there a simple way in LINQ to objects to get a
Short question: How should product categories that appear under multiple categories be managed? Is
Short version: I want to trigger the Form_Load() event without making the form visible.
Short version: I'm wondering if it's possible, and how best, to utilise CPU specific

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.