highsource / highsource/jaxb2-basics
Using -XhashCode and ID/IDREF causes StackOverflowException
- Dominant language
- Java
- Stars
- 119
- Forks
- 49
- PR merge metrics
- No merged PRs in 30d
Description
Marshaling an object graph that contains cycle can be broken using ID and IDREF.
The technique works perfectly with Jaxb and the maven-jaxb2-plugin. Adding bindings such that the IDREF elements return a properly typed instance makes this technique completely transparent at the Java class level. The Structure is serialized to XML without cycles as an XML tree and is returned with the proper cycles in place in Java objects.
Sadly, if enabling hashCode plugin from jaxb2-basics will create an infinite call loop where hashcode will call member hashcodes.
Take for example the following object structure:
AGraph object that contains a single Node
Nodes contain a list of Edges
Edges contain a start Node and an end Node
Hashcode for a Node would call Edge which in return would call Node again so on and so forth.
Workaround are possible but imply disabling one part of the chain.
1 - Disable the hashCode plugin, this implies we will have to re-code all the hashcode functions manually for all generated objects.
2 - Not declare the baseType bindings in the xjb file. Implies we will have to manually cast the reference into the proper object. This in turn can be worked around with the code injection plugin by creating another accessor that performs the cast for us.
3 - not use ID/IDREF and perform this logic manually in a proxy class of some sort.
Option 2 here provides biggest bang for the buck.
I suspect other parts would suffer the same fate (equals, toString etc)
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.