custom converter not called spring data mongodb [can't serialize class error]2019 Community Moderator ElectionWrong ordering in generated table in jpaHow to deserialize a list using GSON or another JSON library in Java?org.springframework.orm.hibernate3.HibernateQueryException - HibernateTemplateHow to configure handling of Map Propertieswhy spill failure happens for Custom Data Type in HadoopSpring MVC form validation does't work for nested complex typesCalling Spring Main Method from Another Class ErrorSpring boot security consider case insensitive username check for loginSpring-Security 5 always 302Why onBindViewHolder index isn't incrementing in Recycler View?

What is better: yes / no radio, or simple checkbox?

Can we carry rice to Japan?

It doesn't matter the side you see it

GPL code private and stolen

Why would the IRS ask for birth certificates or even audit a small tax return?

Correct physics behind the colors on CD (compact disc)?

How can I highlight parts in a screenshot

Deal the cards to the players

Why did the Cray-1 have 8 parity bits per word?

How to disable or uninstall iTunes under High Sierra without disabling SIP

Rationale to prefer local variables over instance variables?

What could be a means to defeat a childrens’ nightmare?

Practical reasons to have both a large police force and bounty hunting network?

Formatting a table to look nice

Sometimes a banana is just a banana

Wardrobe above a wall with fuse boxes

Caulking a corner instead of taping with joint compound?

Difference between 'stomach' and 'uterus'

Was it really inappropriate to write a pull request for the company I interviewed with?

Is there a math equivalent to the conditional ternary operator?

Why is my Contribution Detail Report (native CiviCRM Core report) not accurate?

Four buttons on a table

“I had a flat in the centre of town, but I didn’t like living there, so …”

Should we avoid writing fiction about historical events without extensive research?



custom converter not called spring data mongodb [can't serialize class error]



2019 Community Moderator ElectionWrong ordering in generated table in jpaHow to deserialize a list using GSON or another JSON library in Java?org.springframework.orm.hibernate3.HibernateQueryException - HibernateTemplateHow to configure handling of Map Propertieswhy spill failure happens for Custom Data Type in HadoopSpring MVC form validation does't work for nested complex typesCalling Spring Main Method from Another Class ErrorSpring boot security consider case insensitive username check for loginSpring-Security 5 always 302Why onBindViewHolder index isn't incrementing in Recycler View?










0















I have a User bean with a property address. I have implemented custom converter for the User and the Address class and configured the same in spring XML. The converter for User is getting called every time I save User object. But, converter for Address is not getting called while saving the User and it throwing can't serialize class com.mkyong.model.Address.



Here is my class structure and Xml config:



User Class:



package com.mkyong.model;


import java.util.Map;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;

@Document(collection = "person")
public class User

@Id
private String id;

String username;

String password;

Address address;

Map data;

public String getId()
return id;


public void setId(String id)
this.id = id;


public String getUsername()
return username;


public void setUsername(String username)
this.username = username;


public String getPassword()
return password;


public void setPassword(String password)
this.password = password;


public Address getAddress()
return address;


public void setAddress(Address address)
this.address = address;


public Map getData()
return data;


public void setData(Map data)
this.data = data;


public User(String username, String password)
super();
this.username = username;
this.password = password;


@Override
public String toString()
return "User [id=" + id + ", username=" + username + ", password=" + password + "]";





Address class :



package com.mkyong.model;

import java.io.Serializable;
import org.springframework.data.mongodb.core.mapping.Document;

@Document(collection = "address")
public class Address implements Serializable
/**
*
*/
private static final long serialVersionUID = 2310280839505243479L;
String city;
String dist;
String state;

public Address(String city, String dist, String state)
super();
this.city = city;
this.dist = dist;
this.state = state;


public String getCity()
return city;


public void setCity(String city)
this.city = city;


public String getDist()
return dist;


public void setDist(String dist)
this.dist = dist;


public String getState()
return state;


public void setState(String state)
this.state = state;


@Override
public String toString()
return "Address [city=" + city + ", dist=" + dist + ", state=" + state + "]";




spring configuration:



<mongo:mongo host="127.0.0.1" port="27017" />
<mongo:db-factory dbname="springbootdb" />

<mongo:mapping-converter id="mongoConverter">
<mongo:custom-converters base-package="com.mkyong.model">
<mongo:converter>
<bean class="com.mkyong.converter.UserConverter" />
</mongo:converter>
<mongo:converter>
<bean class="com.mkyong.converter.AddressConverter" />
</mongo:converter>
</mongo:custom-converters>
</mongo:mapping-converter>

<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
<constructor-arg name="mongoConverter" ref="mongoConverter" />
<constructor-arg name="mongoDbFactory" ref="mongoDbFactory" />
</bean>


User Converter :



package com.mkyong.converter;

import org.springframework.core.convert.converter.Converter;
import com.mkyong.model.User;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;

public class UserConverter implements Converter<User, DBObject>

@Override
public DBObject convert(User user)
DBObject dbObject = new BasicDBObject();
dbObject.put("_id", user.getId());
dbObject.put("_address", user.getAddress());
System.out.println("called !!!!!");
return dbObject;





Address Converter :



package com.mkyong.converter;

import org.springframework.core.convert.converter.Converter;
import com.mkyong.model.Address;
import com.mkyong.model.DecimalNumber;
import com.mkyong.model.User;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;

public class AddressConverter implements Converter<Address, String>

@Override
public String convert(Address user)
System.out.println("Not called!!!");
return user==null ? null : user.toString();





I am very new to spring mongodb. Any help is greatly appreciated!










share|improve this question




























    0















    I have a User bean with a property address. I have implemented custom converter for the User and the Address class and configured the same in spring XML. The converter for User is getting called every time I save User object. But, converter for Address is not getting called while saving the User and it throwing can't serialize class com.mkyong.model.Address.



    Here is my class structure and Xml config:



    User Class:



    package com.mkyong.model;


    import java.util.Map;
    import org.springframework.data.annotation.Id;
    import org.springframework.data.mongodb.core.mapping.Document;

    @Document(collection = "person")
    public class User

    @Id
    private String id;

    String username;

    String password;

    Address address;

    Map data;

    public String getId()
    return id;


    public void setId(String id)
    this.id = id;


    public String getUsername()
    return username;


    public void setUsername(String username)
    this.username = username;


    public String getPassword()
    return password;


    public void setPassword(String password)
    this.password = password;


    public Address getAddress()
    return address;


    public void setAddress(Address address)
    this.address = address;


    public Map getData()
    return data;


    public void setData(Map data)
    this.data = data;


    public User(String username, String password)
    super();
    this.username = username;
    this.password = password;


    @Override
    public String toString()
    return "User [id=" + id + ", username=" + username + ", password=" + password + "]";





    Address class :



    package com.mkyong.model;

    import java.io.Serializable;
    import org.springframework.data.mongodb.core.mapping.Document;

    @Document(collection = "address")
    public class Address implements Serializable
    /**
    *
    */
    private static final long serialVersionUID = 2310280839505243479L;
    String city;
    String dist;
    String state;

    public Address(String city, String dist, String state)
    super();
    this.city = city;
    this.dist = dist;
    this.state = state;


    public String getCity()
    return city;


    public void setCity(String city)
    this.city = city;


    public String getDist()
    return dist;


    public void setDist(String dist)
    this.dist = dist;


    public String getState()
    return state;


    public void setState(String state)
    this.state = state;


    @Override
    public String toString()
    return "Address [city=" + city + ", dist=" + dist + ", state=" + state + "]";




    spring configuration:



    <mongo:mongo host="127.0.0.1" port="27017" />
    <mongo:db-factory dbname="springbootdb" />

    <mongo:mapping-converter id="mongoConverter">
    <mongo:custom-converters base-package="com.mkyong.model">
    <mongo:converter>
    <bean class="com.mkyong.converter.UserConverter" />
    </mongo:converter>
    <mongo:converter>
    <bean class="com.mkyong.converter.AddressConverter" />
    </mongo:converter>
    </mongo:custom-converters>
    </mongo:mapping-converter>

    <bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
    <constructor-arg name="mongoConverter" ref="mongoConverter" />
    <constructor-arg name="mongoDbFactory" ref="mongoDbFactory" />
    </bean>


    User Converter :



    package com.mkyong.converter;

    import org.springframework.core.convert.converter.Converter;
    import com.mkyong.model.User;
    import com.mongodb.BasicDBObject;
    import com.mongodb.DBObject;

    public class UserConverter implements Converter<User, DBObject>

    @Override
    public DBObject convert(User user)
    DBObject dbObject = new BasicDBObject();
    dbObject.put("_id", user.getId());
    dbObject.put("_address", user.getAddress());
    System.out.println("called !!!!!");
    return dbObject;





    Address Converter :



    package com.mkyong.converter;

    import org.springframework.core.convert.converter.Converter;
    import com.mkyong.model.Address;
    import com.mkyong.model.DecimalNumber;
    import com.mkyong.model.User;
    import com.mongodb.BasicDBObject;
    import com.mongodb.DBObject;

    public class AddressConverter implements Converter<Address, String>

    @Override
    public String convert(Address user)
    System.out.println("Not called!!!");
    return user==null ? null : user.toString();





    I am very new to spring mongodb. Any help is greatly appreciated!










    share|improve this question


























      0












      0








      0








      I have a User bean with a property address. I have implemented custom converter for the User and the Address class and configured the same in spring XML. The converter for User is getting called every time I save User object. But, converter for Address is not getting called while saving the User and it throwing can't serialize class com.mkyong.model.Address.



      Here is my class structure and Xml config:



      User Class:



      package com.mkyong.model;


      import java.util.Map;
      import org.springframework.data.annotation.Id;
      import org.springframework.data.mongodb.core.mapping.Document;

      @Document(collection = "person")
      public class User

      @Id
      private String id;

      String username;

      String password;

      Address address;

      Map data;

      public String getId()
      return id;


      public void setId(String id)
      this.id = id;


      public String getUsername()
      return username;


      public void setUsername(String username)
      this.username = username;


      public String getPassword()
      return password;


      public void setPassword(String password)
      this.password = password;


      public Address getAddress()
      return address;


      public void setAddress(Address address)
      this.address = address;


      public Map getData()
      return data;


      public void setData(Map data)
      this.data = data;


      public User(String username, String password)
      super();
      this.username = username;
      this.password = password;


      @Override
      public String toString()
      return "User [id=" + id + ", username=" + username + ", password=" + password + "]";





      Address class :



      package com.mkyong.model;

      import java.io.Serializable;
      import org.springframework.data.mongodb.core.mapping.Document;

      @Document(collection = "address")
      public class Address implements Serializable
      /**
      *
      */
      private static final long serialVersionUID = 2310280839505243479L;
      String city;
      String dist;
      String state;

      public Address(String city, String dist, String state)
      super();
      this.city = city;
      this.dist = dist;
      this.state = state;


      public String getCity()
      return city;


      public void setCity(String city)
      this.city = city;


      public String getDist()
      return dist;


      public void setDist(String dist)
      this.dist = dist;


      public String getState()
      return state;


      public void setState(String state)
      this.state = state;


      @Override
      public String toString()
      return "Address [city=" + city + ", dist=" + dist + ", state=" + state + "]";




      spring configuration:



      <mongo:mongo host="127.0.0.1" port="27017" />
      <mongo:db-factory dbname="springbootdb" />

      <mongo:mapping-converter id="mongoConverter">
      <mongo:custom-converters base-package="com.mkyong.model">
      <mongo:converter>
      <bean class="com.mkyong.converter.UserConverter" />
      </mongo:converter>
      <mongo:converter>
      <bean class="com.mkyong.converter.AddressConverter" />
      </mongo:converter>
      </mongo:custom-converters>
      </mongo:mapping-converter>

      <bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
      <constructor-arg name="mongoConverter" ref="mongoConverter" />
      <constructor-arg name="mongoDbFactory" ref="mongoDbFactory" />
      </bean>


      User Converter :



      package com.mkyong.converter;

      import org.springframework.core.convert.converter.Converter;
      import com.mkyong.model.User;
      import com.mongodb.BasicDBObject;
      import com.mongodb.DBObject;

      public class UserConverter implements Converter<User, DBObject>

      @Override
      public DBObject convert(User user)
      DBObject dbObject = new BasicDBObject();
      dbObject.put("_id", user.getId());
      dbObject.put("_address", user.getAddress());
      System.out.println("called !!!!!");
      return dbObject;





      Address Converter :



      package com.mkyong.converter;

      import org.springframework.core.convert.converter.Converter;
      import com.mkyong.model.Address;
      import com.mkyong.model.DecimalNumber;
      import com.mkyong.model.User;
      import com.mongodb.BasicDBObject;
      import com.mongodb.DBObject;

      public class AddressConverter implements Converter<Address, String>

      @Override
      public String convert(Address user)
      System.out.println("Not called!!!");
      return user==null ? null : user.toString();





      I am very new to spring mongodb. Any help is greatly appreciated!










      share|improve this question
















      I have a User bean with a property address. I have implemented custom converter for the User and the Address class and configured the same in spring XML. The converter for User is getting called every time I save User object. But, converter for Address is not getting called while saving the User and it throwing can't serialize class com.mkyong.model.Address.



      Here is my class structure and Xml config:



      User Class:



      package com.mkyong.model;


      import java.util.Map;
      import org.springframework.data.annotation.Id;
      import org.springframework.data.mongodb.core.mapping.Document;

      @Document(collection = "person")
      public class User

      @Id
      private String id;

      String username;

      String password;

      Address address;

      Map data;

      public String getId()
      return id;


      public void setId(String id)
      this.id = id;


      public String getUsername()
      return username;


      public void setUsername(String username)
      this.username = username;


      public String getPassword()
      return password;


      public void setPassword(String password)
      this.password = password;


      public Address getAddress()
      return address;


      public void setAddress(Address address)
      this.address = address;


      public Map getData()
      return data;


      public void setData(Map data)
      this.data = data;


      public User(String username, String password)
      super();
      this.username = username;
      this.password = password;


      @Override
      public String toString()
      return "User [id=" + id + ", username=" + username + ", password=" + password + "]";





      Address class :



      package com.mkyong.model;

      import java.io.Serializable;
      import org.springframework.data.mongodb.core.mapping.Document;

      @Document(collection = "address")
      public class Address implements Serializable
      /**
      *
      */
      private static final long serialVersionUID = 2310280839505243479L;
      String city;
      String dist;
      String state;

      public Address(String city, String dist, String state)
      super();
      this.city = city;
      this.dist = dist;
      this.state = state;


      public String getCity()
      return city;


      public void setCity(String city)
      this.city = city;


      public String getDist()
      return dist;


      public void setDist(String dist)
      this.dist = dist;


      public String getState()
      return state;


      public void setState(String state)
      this.state = state;


      @Override
      public String toString()
      return "Address [city=" + city + ", dist=" + dist + ", state=" + state + "]";




      spring configuration:



      <mongo:mongo host="127.0.0.1" port="27017" />
      <mongo:db-factory dbname="springbootdb" />

      <mongo:mapping-converter id="mongoConverter">
      <mongo:custom-converters base-package="com.mkyong.model">
      <mongo:converter>
      <bean class="com.mkyong.converter.UserConverter" />
      </mongo:converter>
      <mongo:converter>
      <bean class="com.mkyong.converter.AddressConverter" />
      </mongo:converter>
      </mongo:custom-converters>
      </mongo:mapping-converter>

      <bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
      <constructor-arg name="mongoConverter" ref="mongoConverter" />
      <constructor-arg name="mongoDbFactory" ref="mongoDbFactory" />
      </bean>


      User Converter :



      package com.mkyong.converter;

      import org.springframework.core.convert.converter.Converter;
      import com.mkyong.model.User;
      import com.mongodb.BasicDBObject;
      import com.mongodb.DBObject;

      public class UserConverter implements Converter<User, DBObject>

      @Override
      public DBObject convert(User user)
      DBObject dbObject = new BasicDBObject();
      dbObject.put("_id", user.getId());
      dbObject.put("_address", user.getAddress());
      System.out.println("called !!!!!");
      return dbObject;





      Address Converter :



      package com.mkyong.converter;

      import org.springframework.core.convert.converter.Converter;
      import com.mkyong.model.Address;
      import com.mkyong.model.DecimalNumber;
      import com.mkyong.model.User;
      import com.mongodb.BasicDBObject;
      import com.mongodb.DBObject;

      public class AddressConverter implements Converter<Address, String>

      @Override
      public String convert(Address user)
      System.out.println("Not called!!!");
      return user==null ? null : user.toString();





      I am very new to spring mongodb. Any help is greatly appreciated!







      java spring mongodb spring-data-mongodb converters






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 6 hours ago







      Manu

















      asked 13 hours ago









      ManuManu

      104113




      104113






















          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55021186%2fcustom-converter-not-called-spring-data-mongodb-cant-serialize-class-error%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55021186%2fcustom-converter-not-called-spring-data-mongodb-cant-serialize-class-error%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

          2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived

          Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme