I'm working on upgrading the XStream version used at my company. We have a 'workflow import' feature that takes an XML file and unmarshals it to a graph of JPA entities. A snippet of the XML:
<workflowData>
<workflows>
<workflow id="1">
...
<steps>
<step reference="2"/>
<step reference="3"/>
</steps>
</workflow>
</workflows>
...
This is expected to be unmarshalled into a Workflow JPA entity. The Workflow entity has two fields of interest:
@LazyCollection(LazyCollectionOption.FALSE)
@OneToMany(mappedBy = "workflow", cascade = { CascadeType.PERSIST, CascadeType.MERGE })
@IndexColumn(name = "workflow_id")
@Fetch(FetchMode.JOIN)
private Set<TaskStep> steps = new HashSet<TaskStep>();
@LazyCollection(LazyCollectionOption.FALSE)
@OneToMany(mappedBy = "workflow", cascade = { CascadeType.PERSIST, CascadeType.MERGE })
@IndexColumn(name = "workflow_id")
@Fetch(FetchMode.JOIN)
private Set<TaskProgress> taskProgresses = new HashSet<TaskProgress>();
We configure the XStream appropriately, e.g. using xstream.alias("step", TaskStep.class); to map "step" to a TaskStep entity.
When migrating past 1.4.4 of XStream, two issues arise related to these two fields.
- The
TaskStep JPA class, which defines its parent Workflow as a @ManyToOne field (the inverse of the first field in the XML above), no longer sees the field being set. I.e. in 1.4.4, Workflow.steps is a collection of TaskStep, with the TaskStep.workflow of each item in that collection being correctly set to its parent workflow. But in 1.4.5, TaskStep.workflow is being set to null. The step being referenced in the XML (<step reference="3"/>) does not explicitly reference the workflow to which it belongs, but it's correctly inferred in 1.4.4 and not in 1.4.5.
- The XML snippet mentioned contains no XML element corresponding to the
taskProgresses collection. In 1.4.4, this is not a problem, and the value of Workflow.taskProgresses after unmarshalling is an empty hashset. In 1.4.5, the value of this field on the unmarshalled JPA entity is null, rather than an empty collection. This is causing a NullPointerException.
I'm unable to modify the XML provided to this import feature, and therefore I must retain backwards-compatibility. However, in my test, if I add <taskProgresses/> to the workflow XML, then the expected behaviour is preserved.
Can anyone advise?
I'm working on upgrading the XStream version used at my company. We have a 'workflow import' feature that takes an XML file and unmarshals it to a graph of JPA entities. A snippet of the XML:
This is expected to be unmarshalled into a Workflow JPA entity. The Workflow entity has two fields of interest:
We configure the XStream appropriately, e.g. using
xstream.alias("step", TaskStep.class);to map "step" to a TaskStep entity.When migrating past 1.4.4 of XStream, two issues arise related to these two fields.
TaskStepJPA class, which defines its parentWorkflowas a@ManyToOnefield (the inverse of the first field in the XML above), no longer sees the field being set. I.e. in 1.4.4,Workflow.stepsis a collection ofTaskStep, with theTaskStep.workflowof each item in that collection being correctly set to its parent workflow. But in 1.4.5,TaskStep.workflowis being set to null. The step being referenced in the XML (<step reference="3"/>) does not explicitly reference the workflow to which it belongs, but it's correctly inferred in 1.4.4 and not in 1.4.5.taskProgressescollection. In 1.4.4, this is not a problem, and the value ofWorkflow.taskProgressesafter unmarshalling is an empty hashset. In 1.4.5, the value of this field on the unmarshalled JPA entity is null, rather than an empty collection. This is causing a NullPointerException.I'm unable to modify the XML provided to this import feature, and therefore I must retain backwards-compatibility. However, in my test, if I add
<taskProgresses/>to the workflow XML, then the expected behaviour is preserved.Can anyone advise?