spring data - Save LocaTime via SpringData to MongoDB -
i try save localtime (joda) field mongodb springdata using spring-boot-starter-parent (org.springframework.boot 1.2.3.release) , stackoverflowerror.
the stackoverflowerror in beanwrapper in method
public <s> s getproperty(persistentproperty<?> property, class<? extends s> type)
stacktrace:
http-nio-8080-exec-2@5509 daemon, prio=5, in group 'main', status: 'running' @ org.springframework.data.mapping.model.beanwrapper.getproperty(beanwrapper.java:120) @ org.springframework.data.mapping.model.beanwrapper.getproperty(beanwrapper.java:100) @ org.springframework.data.mongodb.core.convert.mappingmongoconverter$3.dowithpersistentproperty(mappingmongoconverter.java:419) @ org.springframework.data.mongodb.core.convert.mappingmongoconverter$3.dowithpersistentproperty(mappingmongoconverter.java:412) @ org.springframework.data.mapping.model.basicpersistententity.dowithproperties(basicpersistententity.java:307) @ org.springframework.data.mongodb.core.convert.mappingmongoconverter.writeinternal(mappingmongoconverter.java:412) @ org.springframework.data.mongodb.core.convert.mappingmongoconverter.writepropertyinternal(mappingmongoconverter.java:511) @ org.springframework.data.mongodb.core.convert.mappingmongoconverter$3.dowithpersistentproperty(mappingmongoconverter.java:424) @ org.springframework.data.mongodb.core.convert.mappingmongoconverter$3.dowithpersistentproperty(mappingmongoconverter.java:412) @ org.springframework.data.mapping.model.basicpersistententity.dowithproperties(basicpersistententity.java:307) @ org.springframework.data.mongodb.core.convert.mappingmongoconverter.writeinternal(mappingmongoconverter.java:412) @ org.springframework.data.mongodb.core.convert.mappingmongoconverter.writepropertyinternal(mappingmongoconverter.java:511) @ org.springframework.data.mongodb.core.convert.mappingmongoconverter$3.dowithpersistentproperty(mappingmongoconverter.java:424) @ org.springframework.data.mongodb.core.convert.mappingmongoconverter$3.dowithpersistentproperty(mappingmongoconverter.java:412) @ org.springframework.data.mapping.model.basicpersistententity.dowithproperties(basicpersistententity.java:307)...
adding these 2 converters customconversions fix problem.
@configuration public class mongoconfiguration extends abstractmongoconfiguration { @override protected string getdatabasename() { return "databasename"; } @override public mongo mongo() throws exception { return new mongoclient("localhost"); } @override public customconversions customconversions() { list<converter<?, ?>> converters = new arraylist<>(); converters.add(new localtimetostringconverter()); converters.add(new stringtolocaltimeconverter()); return new customconversions(converters); } } public class localtimetostringconverter implements converter<localtime, string> { @override public string convert(localtime localtime) { return localtime.tostring(); } } public class stringtolocaltimeconverter implements converter<string, localtime> { @override public localtime convert(string s) { return localtime.parse(s); } }
Comments
Post a Comment