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?
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
add a comment |
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
add a comment |
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
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
java spring mongodb spring-data-mongodb converters
edited 6 hours ago
Manu
asked 13 hours ago
ManuManu
104113
104113
add a comment |
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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