Java SOAP API refactor - To manually marshall/unmarshall or to not?



I'm working on overhauling an existing API. Normally, with a SOAP API in Java, JAXB or a similar framework might be used. However, this one's a bit different.


The current API will request certain objects/data from the server, which is sent and parsed. However, each object can have a multitude of properties (technically, over a thousand, although that's an extreme case) and either a default set of properties is requested or a specific, prebuilt set is requested. The current API handles this by defining properties as objects and using them as keys in a HashMap to store properties for these objects when they're pulled from the XML response. A number of convenience methods serve as getters/setters for common properties, or you can specifically pass it a property key and retrieve the value. The developer also has the ability to define their own additional properties.


As such, this API currently parses the XML manually using an XMLEventReader. There's a fair amount of mapping involved, of course. I'm looking at a number of improvements and enhancements on this API, but I'm a bit torn on whether or not I should overhaul the XML nitty-gritty. I could implement generated classes from a schema, but getting everything constructed and written properly in that sense could be difficult, especially with the devs being able to create custom properties. There are also some rules about what can be read/written and when that could be difficult to implement. Generated classes would have a massive number of fields (especially since there's a fair amount of inheritance in most objects), most of which would rarely see any use. It may be necessary to separate the generated objects from the rest of the API, which means additional mapping anyway. Manually doing this may technically be faster, although that's not a large concern.


In addition, there's also the subject of time. Some enhancement to the existing framework would probably be simpler as opposed to reworking a much larger chunk of this thing. I suppose the broader question is when it would be considered viable to use the XMLEventReader/Writer to manually handle the XML as opposed to the usual pattern of generated classes and automated martialling/unmartialling.


No comments:

Post a Comment