Embedded abstract class not working with 2.0.0?
See original GitHub issueHow can I use abstract classes properly with 2.0.0 I used to have something similar to the below which used to work on the previous version:
@Entity
public class Root {
private List<AbstractPlugin> plugins = new ArrayList<>();
public Root() {
}
...
}
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = As.EXISTING_PROPERTY, property = "pluginType")
@JsonSubTypes({
@JsonSubTypes.Type(value = APlugin.class, name = "A_PLUGIN"),
@JsonSubTypes.Type(value = BPlugin.class, name = "B_PLUGIN")
})
@Embedded
public abstract class AbstractPlugin{
...
}
With 2.0.0 I’m getting the following error:
dev.morphia.mapping.MappingException: AbstractPlugin does not have a 0 argument constructor.
Obviously adding an empty constructor doesn’t work either with an error similar to:
dev.morphia.mapping.MappingException: Can't instantiate the type AbstractPlugin: null
The db also has the className
field with the correct concrete class so after upgrading tbh I’m not sure if previously it was using the pluginType
or the className
to resolve which class the data represent.
What am I doing wrong and how can I make this work as before?
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (5 by maintainers)
Top Results From Across the Web
JPA 2.0 : Embedded inherited abstract Class - Stack Overflow
In your example you can take advantage of the inheritance only if you use one of your subtypes in the OrderSlip class (not...
Read more >UML Class Diagram Tutorial: Abstract Class with Examples
This tutorial covers UML Class Diagram Basics, Benefits of Class Diagram, Elements of a Class Diagram, Abstract Classes, Best Practices, ...
Read more >SLF4J Error Codes
This warning, i.e. not an error, message is reported when no SLF4J providers could be found on the class path. Placing one (and...
Read more >Documentation - Apache Kafka
This allows building applications that do non-trivial processing that compute aggregations off of streams or join streams together. This facility helps solve ...
Read more >[DEPRECATED] Embedding Debezium Connectors
Not every application needs this level of fault tolerance and reliability, ... EmbeddedEngine class serves as an easy-to-use wrapper around any standard ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
OK. That makes sense. It’s “weird” in some ways but not particularly “wrong.” Morphia isn’t currently set up to make that work, I don’t think. Just thinking through the deserialization code, I’m pretty sure that key/value gets processed and discarded since it’s typically a meta-field. I don’t think it’ll be hard to correct that but I’m reasonably sure it won’t work with what’s out there to day. I’ll file a separate issue to track that.
Morphia has never used the jackson annotations so you probably just got lucky.
Thanks for the reply, I think I’ve found why my specific implementation isn’t working… I will update tomorrow if I manage to fix it…