Saturday, 21 November 2015

XML : marshaling Classes in Java ignore some attributes

I'm developing a java application and I'm pretending to use JAXB to save and load the project in a XML file using marshalling and unmarshalling methods. I will not post the original and entire code, because is too large, would be confused and is in spanish (in previous post some people didn't help me because the name of attributes were in spanish), so I will explain the structure of my project in a generic way. I have implemented some part of the code, and in someway only a part works. So, for I think, I need help is in the adapter class. So, I have a main class, which one is the root element that I assigned to JAXB.I think, that resolving this issue I can fix the rest of the application.I will post only the attributes:

  class main extends application{     private ObservableList<ClassA> objectA;     private ObservableList<ClassB> objectB;     private ClassC objectC;  }    

So, is worth mentioning that JAXB generate the correct XML for the objectC. The structure of this class is the next:

  public class ClassC{      private ObservableList<String> A,B,C,D;  }    

Following, the problem is the ObjectA and B, the structure of both classes are:

  public class ClassA{      private StringProperty Name;      private List<String> tasks;      private StringProperty description;      private ObservableList<ClassX> ontologies;      private ObservableList<ClassB>;  }    Public class ClassB{     private SimpleStringProperty name;      private final ObservableList<Actor> actors;      private final ObservableList<UseCase> UseCases;      private AgentModel agentM;      private JobModel jobM;  }    

so, in the output of JAXB doesn't include ObjectA neither ObjectB For the moments, I have 2 adapterClass, one for the observableList and another for the SimpleString attributes, they are defined in the next way:

  public class ObservableListAdapter<T> extends XmlAdapter<LinkedList<T>, ObservableList<T>> {            @Override          public ObservableList<T> unmarshal(LinkedList<T> v) throws Exception {              return FXCollections.observableList(v);          }            @Override          public LinkedList<T> marshal(ObservableList<T> v) throws Exception {              LinkedList<T> list = new LinkedList<T>();              list.addAll(v);              return list;          }  }    public class SimpleStringPropertyAdapter extends XmlAdapter<String, SimpleStringProperty> {          @Override          public SimpleStringProperty unmarshal(String v) throws Exception {              return new SimpleStringProperty(v);          }            @Override          public String marshal(SimpleStringProperty v) throws Exception {              if(null == v) {                  return null;              }              return v.get(); // Or whatever the correct method is          }  }    

Finally, my question is: why it works perfectly with the objectB? why the other attributes are ignored? should I define more AdapterClass? I have various objects of type ObservableList, but everyone of them save different kinds of objects so, in the adapterClass should I define differents actions for everyone depending of ClassType? Thank you very much!

No comments:

Post a Comment