users@jaxb.java.net

Lazy Init Collections in Generated Classes

From: Nick Heudecker <nheudecker_at_gmail.com>
Date: Thu, 3 Nov 2011 14:52:07 -0700

I'm sure this has been asked before but my searches haven't turned up
anything. I need a way to initialize collection objects lazily. My XSDs
(which I don't control) have the following for all objects:

<xsd:anyAttribute namespace="##any" processContents="lax"/>

Resulting in lots of the following:

public class Foo {
    private Map<QName, String> otherAttributes = new HashMap<QName,
String>();

    // ....
}

How can I tell XJC to not create the otherAttributes map until the
'getOtherAttributes()' method is called? Ordinarily this wouldn't be a
problem but I'm seeing a lot of needless object creation under load.

Thanks for your time.