I understand that the ObjectFactory
is often automatically generated when working with JAXB as one might define schema and XML first. However, this is not the way I can approach the project.
I have existing code which needs to be annotated and extended to use JAXB to then use it in conjunction with a REST service. I have only a handful of classes and annotated them already. As far as I understood the documentation (I am new to JAXB), I need an implementation of ObjectFactory
either by package for automatic invocation on package level, or a multitude of implementations when they are referred to directly rather than referred to by package context.
I am a bit unsure what the best approach would be. If I were to use one implementation per package then the manager would be rather abstract, instantiating many classes. However, I am not sure this is the "right" way to do it. I would personally opt to separate the concerns for instantiation into separate instances of the ObjectFactory
, i.e., have one factory per class. Hence, I would implement something similar to the Data Access Object pattern.
My engineering background tells me that separation of concerns and opting for extension over modification would be a better choice. Hence, my intuition tells me that the monolithic ObjectFactory
is only used when produced as a result of the approach starting from XML rather than code. Yet I don't have enough experience to make an informed choice.
I would like to ask you not only for your experience with the technology and recommendation (which would be to opinion based) but also whether this approach will introduce any risks that I am missing as well as technical limitations regarding JAXB that I might run into if I pursue my course of action. Thank you!