question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Embedded abstract class not working with 2.0.0?

See original GitHub issue

How 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:closed
  • Created 3 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
evanchoolycommented, Sep 27, 2020

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.

1reaction
stzanakiscommented, Sep 22, 2020

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…

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found