cancel
Showing results for 
Search instead for 
Did you mean: 

DelegateExecution.setVariable loses inherited attributes

rufini
Champ in-the-making
Champ in-the-making
Hi,

I've an issue Using Activiti 5.6.
If I set in the DelegateExecution an object wich extends of a superclass, I lost the inherited attributes


public class Animal{
  private String color;
  (getters&setters)
}

public class Cat extends Animal{
   private String name;
  (getters&setters)
}

public class AnimalTask
    implements JavaDelegate {

   public void execute(DelegateExecution execution) {
      Cat cat = new Cat();
      cat.setColor = "cyan";
      cat.setName = "Tom";
      execution.setVariable("ANIMAL", cat);
   }
}

(My flow ends with a UserTask):

// The inherited attribute
execution.getVariable("ANIMAL").getColor() is null
// The other attribute
execution.getVariable("ANIMAL").getName() is "Tom"

I tryied both; making Animal abstract and concrete.

Any suggestions?

Thanks in advance!
rufini.
2 REPLIES 2

frederikherema1
Star Contributor
Star Contributor
The variables are serialized. Serialized objects are created differently than regular ones, not really an activiti-issue, more of an Java-general thing.

Check this out: http://www.javapractices.com/topic/TopicAction.do?Id=70

rufini
Champ in-the-making
Champ in-the-making
It's true, Frederik!

Implementing Serializable on the superclass "Animal" fixed the issue (the subclass "Cat" was already implementing it)

Thanks!
rufini