@@ -34,7 +34,7 @@ public final class XmlUtility {
3434 */
3535 private XmlUtility () {
3636 }
37-
37+
3838 /**
3939 * Helper method to serialize an object to XML. Requires object to be Serializable
4040 * @param entity Object to serialize
@@ -49,7 +49,6 @@ public static synchronized <T extends Serializable> String getXml(T entity) thro
4949
5050 if ( null != entity )
5151 {
52-
5352 if (!jaxbContext .containsKey (entity .getClass ().toString ()))
5453 {
5554 request_ctx = JAXBContext .newInstance (entity .getClass ());
@@ -59,11 +58,14 @@ public static synchronized <T extends Serializable> String getXml(T entity) thro
5958 {
6059 request_ctx = jaxbContext .get (entity .getClass ().toString ());
6160 }
62-
63- Marshaller m = request_ctx .createMarshaller ();
64- m .setProperty (Marshaller .JAXB_FORMATTED_OUTPUT , true );
6561
66- m .marshal (entity , sw );
62+ if (request_ctx != null )
63+ {
64+ Marshaller m = request_ctx .createMarshaller ();
65+ m .setProperty (Marshaller .JAXB_FORMATTED_OUTPUT , true );
66+
67+ m .marshal (entity , sw );
68+ }
6769 }
6870 sw .flush ();
6971 sw .close ();
@@ -95,29 +97,32 @@ public static synchronized <T extends Serializable> T create(String xml, Class<T
9597 {
9698 response_ctx = jaxbContext .get (classType .toString ());
9799 }
98-
99- Unmarshaller um = response_ctx .createUnmarshaller ();
100- try {
101- Object unmarshaled = um .unmarshal (new StringReader (xml ));
102- if ( null != unmarshaled )
103- {
104- try {
105- entity = classType .cast (unmarshaled );
106- } catch (ClassCastException cce ) {
107- if (unmarshaled instanceof JAXBElement ) {
108- @ SuppressWarnings ("rawtypes" )
109- JAXBElement element = (JAXBElement ) unmarshaled ;
110- if ( null != element .getValue () && element .getValue ().getClass ()==classType ) {
111- entity = (T ) element .getValue ();
112- }
113- }
114- }
115- }
116- } catch (JAXBException jaxbe ) {
117- LogHelper .info (logger , "Exception - while deserializing text:'%s' " , xml );
118- LogHelper .warn (logger , "Exception Details-> Code:'%s', Message:'%s'" , jaxbe .getErrorCode (), jaxbe .getMessage ());
119- throw jaxbe ;
120- }
100+
101+ if (response_ctx != null )
102+ {
103+ Unmarshaller um = response_ctx .createUnmarshaller ();
104+ try {
105+ Object unmarshaled = um .unmarshal (new StringReader (xml ));
106+ if ( null != unmarshaled )
107+ {
108+ try {
109+ entity = classType .cast (unmarshaled );
110+ } catch (ClassCastException cce ) {
111+ if (unmarshaled instanceof JAXBElement ) {
112+ @ SuppressWarnings ("rawtypes" )
113+ JAXBElement element = (JAXBElement ) unmarshaled ;
114+ if ( null != element .getValue () && element .getValue ().getClass ()==classType ) {
115+ entity = (T ) element .getValue ();
116+ }
117+ }
118+ }
119+ }
120+ } catch (JAXBException jaxbe ) {
121+ LogHelper .info (logger , "Exception - while deserializing text:'%s' " , xml );
122+ LogHelper .warn (logger , "Exception Details-> Code:'%s', Message:'%s'" , jaxbe .getErrorCode (), jaxbe .getMessage ());
123+ throw jaxbe ;
124+ }
125+ }
121126 }
122127
123128 return entity ;
0 commit comments