Reuse JAXB metadata to populate a new JAXB Context



Lets say I'm using JAXB in a project with 3 schemas, Main(M), Custom1(C1) and Custom2(C2). Both C1 and C2 import the M schema. The M schema generates a lot of classes (like 500+), and both C1 and C2 have a couple classes each.


For reason specific to our setup I cannot have a single JAXBContext for all 3 schemas. What I need is to be able to create separate JAXBContext for M,C1 and C2. Then problem is that creating a JAXBContext for M is costly (in time and memory) since it has a lot of classes. And then again, when I create the JAXBContext for C1 and C2, they both need to load the metadata for M all over again, resulting in having the metadata from M loaded 3 times, one for each JAXBContext.


So my question ... is there a way while creating JAXBContexts C1 and C2 to reuse the metadata already loaded in a seperate JAXBContext M ?


Thanks


No comments:

Post a Comment