Question

I have a class hierarchy with a base class called EntityModel, and two classes InvestorModel and AgentModel that each inherit directly from it and add a few properties. I am then creating Mule Data Maps to map JSON to each child class individually.

The InvestorModel map works fine, but the AgentModel map fails (in the IDE preview) with an IOException stating that it can't instantiate EntityModel. This seems strange as it can instantiate it in the InvestorModel map. I'm posting the error, but I don't really have any source to post as these are just mapping files. I just don't know where to start looking.

Mule Studio is up to date and v3.5.0

java.io.IOException: org.jetel.exception.JetelException: za.co.sci.core.shared.EntityModel can not be instantiated.
    at org.jetel.component.tree.writer.TreeFormatter.write(TreeFormatter.java:72)
    at org.jetel.util.MultiFileWriter.writeRecord2CurrentTarget(MultiFileWriter.java:420)
    at org.jetel.util.MultiFileWriter.write(MultiFileWriter.java:297)
    at org.jetel.component.TreeWriter.execute(TreeWriter.java:464)
    at org.jetel.graph.Node.run(Node.java:465)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:744)
Caused by: org.jetel.exception.JetelException: za.co.sci.core.shared.EntityModel can not be instantiated.
    at com.opensys.cloveretl.component.tree.writer.bean.BeanWriter.a(Unknown Source)
    at com.opensys.cloveretl.component.tree.writer.bean.BeanWriter.a(Unknown Source)
    at com.opensys.cloveretl.component.tree.writer.bean.BeanWriter.a(Unknown Source)
    at com.opensys.cloveretl.component.tree.writer.bean.BeanWriter.writeStartNode(Unknown Source)
    at org.jetel.component.tree.writer.model.runtime.WritableObject.writeContent(WritableObject.java:67)
    at org.jetel.component.tree.writer.model.runtime.WritableContainer.write(WritableContainer.java:67)
    at org.jetel.component.tree.writer.model.runtime.WritableObject.writeContent(WritableObject.java:77)
    at org.jetel.component.tree.writer.model.runtime.WritableContainer.write(WritableContainer.java:67)
    at org.jetel.component.tree.writer.model.runtime.WritableObject.writeContent(WritableObject.java:77)
    at org.jetel.component.tree.writer.model.runtime.WritableContainer.write(WritableContainer.java:67)
    at org.jetel.component.tree.writer.model.runtime.WritableObject.writeContent(WritableObject.java:77)
    at org.jetel.component.tree.writer.model.runtime.WritableContainer.write(WritableContainer.java:67)
    at org.jetel.component.tree.writer.model.runtime.WritableObject.writeContent(WritableObject.java:77)
    at org.jetel.component.tree.writer.TreeFormatter.write(TreeFormatter.java:69)
    ... 7 more

Class snippets:

public abstract class EntityModel implements Serializable {
    protected Long id;
    private long entityNumber;
    private EntityStatus status;
    private String entityName;
...

public class AgentModel extends EntityModel implements Serializable{
    private int agentCode;
    private AgentType agentType;
    private AgentClass agentClass;
...

public class InvestorModel extends EntityModel implements Serializable {
    private boolean blockedRand;
    private String utAUTType;
...
Was it helpful?

Solution

Turns out the error was due to the base class being abstract. Kind of obvious really.

The reason the one map worked, but not the other was because of the order of the fields. The first field to be mapped on the InvestorModel was a field defined in InvestorModel so the mapper knew which class to instantiate. On the AgentModel map the first field was defined on the abstract class EntityModel so the mapper tried to instantiate that class, but failed, it didn't matter that I have chosen AgentModel as the destination.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top