Created
August 29, 2011 23:42
-
-
Save harlanji/1179718 to your computer and use it in GitHub Desktop.
Best way to add custom converters to spring-data-mongodb?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MongoTemplate mongo = ...; | |
List<Converter> converters = new ArrayList<Converter>(); | |
converters.add(new Converter<DBObject, Participant>() { | |
public Participant convert(DBObject s) { | |
throw new UnsupportedOperationException("Not supported yet 1."); | |
} | |
}); | |
converters.add(new Converter<Participant, DBObject>() { | |
public DBObject convert(Participant s) { | |
throw new UnsupportedOperationException("Not supported yet 2."); | |
} | |
}); | |
CustomConversions cc = new CustomConversions(converters); | |
((MappingMongoConverter)mongo.getConverter()).setCustomConversions(cc); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Since the link from @mpereira-dev isn't up-to-date anymore here are some new ones:
https://github.com/eugenp/tutorials/blob/master/persistence-modules/spring-data-mongodb/src/main/java/com/baeldung/config/MongoConfig.java
https://github.com/eugenp/tutorials/blob/master/persistence-modules/spring-data-mongodb/src/main/resources/mongoConfig.xml