@@ -34,7 +34,7 @@ public final class XmlUtility {
34
34
*/
35
35
private XmlUtility () {
36
36
}
37
-
37
+
38
38
/**
39
39
* Helper method to serialize an object to XML. Requires object to be Serializable
40
40
* @param entity Object to serialize
@@ -49,7 +49,6 @@ public static synchronized <T extends Serializable> String getXml(T entity) thro
49
49
50
50
if ( null != entity )
51
51
{
52
-
53
52
if (!jaxbContext .containsKey (entity .getClass ().toString ()))
54
53
{
55
54
request_ctx = JAXBContext .newInstance (entity .getClass ());
@@ -59,11 +58,14 @@ public static synchronized <T extends Serializable> String getXml(T entity) thro
59
58
{
60
59
request_ctx = jaxbContext .get (entity .getClass ().toString ());
61
60
}
62
-
63
- Marshaller m = request_ctx .createMarshaller ();
64
- m .setProperty (Marshaller .JAXB_FORMATTED_OUTPUT , true );
65
61
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
+ }
67
69
}
68
70
sw .flush ();
69
71
sw .close ();
@@ -95,29 +97,32 @@ public static synchronized <T extends Serializable> T create(String xml, Class<T
95
97
{
96
98
response_ctx = jaxbContext .get (classType .toString ());
97
99
}
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
+ }
121
126
}
122
127
123
128
return entity ;
0 commit comments