4
我想代碼不拋出異常時從該不存在枚舉代碼蒙戈java代碼負載枚舉值彈簧數據mongodb的枚舉映射變換器
例:
java.lang.IllegalArgumentException: No enum constant fr.myapp.type.OrderOptionEnum.TELEPHONE
at java.lang.Enum.valueOf(Enum.java:238)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.getPotentiallyConvertedSimpleRead(MappingMongoConverter.java:819)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.readCollectionOrArray(MappingMongoConverter.java:909)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.readValue(MappingMongoConverter.java:1184)
因爲電話並不在OrderOptionEnum
existe我想要代碼返回空值
任何想法?
問候
我認爲你需要創建一個自定義的ConverterFactory:http://stackoverflow.com/a/30024621/641627 – alexbt
這是舊的,但可能對你有幫助(他包裝他的枚舉):https:// ghads .wordpress.com/2011/04/12/mongodb的和 - java的枚舉 – alexbt