Enums in MongoDB cannot be serialized
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
| Querydsl |
Fix Released
|
Undecided
|
Unassigned |
Bug Description
Enums cannot be serialized without transforming them.
I propose, that all java enums are serialized (and deserialized) using the name() method (or valueOf() method).
Example:
@Entity
public enum Type {
TYPE1, TYPE2
}
public class MyObject {
protected Type type;
public Type getType() {
}
public void setType(Type type) {
this.type = type;
}
}
Usage:
QMyObject.
java.lang.
at org.bson.
at org.bson.
at org.bson.
at org.bson.
at org.bson.
at com.mongodb.
at com.mongodb.
at com.mongodb.
at com.mongodb.
at com.mongodb.
at com.mongodb.
at com.mongodb.
at com.mongodb.
at com.mysema.
at org.springframe
at sun.reflect.
at sun.reflect.
at java.lang.
at org.springframe
at org.springframe
at org.springframe
at org.springframe
at $Proxy18.
Robert Stiller (robert-stiller) wrote : | #2 |
I've used them as simple properties of an entity.
But when it cam to a request using Predicates the exception was thrown ...
I only added the @Entity Annotation to the enum because of Morphia itself. I thought it would be needed.
But nevertheless the Exception was caused by the request using the Morphia API (Predicates) and has nothing to do with spring-data itself.
I know that spring-data supports the translation from and to enum, because I wrote the feature-request :D
I also wrote a ticket to the mongo-java-
Timo Westkämper (timo-westkamper) wrote : | #3 |
Fixed in SVN trunk. This was indeed a Querydsl bug.
Changed in querydsl: | |
status: | In Progress → Fix Committed |
Robert Stiller (robert-stiller) wrote : | #4 |
Cool, Thank you!
Timo Westkämper (timo-westkamper) wrote : | #5 |
Released in 2.2.0.beta5
Changed in querydsl: | |
status: | Fix Committed → Fix Released |
Are you using an enum as an entity? Could you explain why?
I believe enums work when used as simple properties, at least there are conversions for them available in Morphia, I am not sure about Spring Data.