Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ElementOutlineImpl omits serialVersionUID and proposed fix #1750

Closed
patrodyne opened this issue Oct 3, 2023 · 0 comments · Fixed by #1753
Closed

ElementOutlineImpl omits serialVersionUID and proposed fix #1750

patrodyne opened this issue Oct 3, 2023 · 0 comments · Fixed by #1753

Comments

@patrodyne
Copy link
Contributor

ISSUE

The ElementOutlineImpl class omits the serialVersionUID field when specified by

<jaxb:globalBindings>
    <jaxb:serializable uid="20231001" />
</jaxb:globalBindings>

PROPOSAL

Add a method to ElementOutlineImpl to implement the serializable option and call the method at the start of the if(ei.hasClass()) {...} block.

Method: serializableOption(...)

/**
 * Serializable option to implement the {@link Serializable} interface
 * and <code>serialVersionUID</code> field.
 *
 * @param bg The XJC bean generator.
 * @param implClass The implementation class.
 */
private void serializableOption(BeanGenerator bg, JDefinedClass implClass)
{
    if (bg.getModel().serializable)
    {
        JClass serRef = bg.getCodeModel().ref(Serializable.class);
        if ( !serRef.isAssignableFrom(implClass) )
            implClass._implements(Serializable.class);

        if ( !implClass.fields().containsKey("serialVersionUID") )
        {
            if (bg.getModel().serialVersionUID != null)
            {
                implClass.field(
                    JMod.PRIVATE | JMod.STATIC | JMod.FINAL,
                    bg.getCodeModel().LONG,
                    "serialVersionUID",
                    JExpr.lit(bg.getModel().serialVersionUID));
            }
        }
    }
}
patrodyne added a commit to patrodyne/jaxb-ri that referenced this issue Oct 3, 2023
lukasj pushed a commit to lukasj/jaxb-ri that referenced this issue Oct 6, 2023
lukasj pushed a commit that referenced this issue Oct 6, 2023
lukasj pushed a commit to lukasj/jaxb-ri that referenced this issue Oct 9, 2023
lukasj pushed a commit that referenced this issue Oct 13, 2023
(cherry picked from commit d1c27f9)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant