@@ -70,22 +70,26 @@ public <T> T deserializeObject(final String inputString, final Class<T> clazz) {
7070 return deserializeObject (inputString , clazz , null );
7171 }
7272
73+ @ SuppressWarnings ("unchecked" )
7374 @ Override
7475 public <T > T deserializeObject (final String inputString , final Class <T > clazz , Map <String , java .util .List <String >> responseHeaders ) {
75- T jsonObject = gson .fromJson (inputString , clazz );
76+ final T jsonObject = gson .fromJson (inputString , clazz );
7677
7778 // Populate the JSON-backed fields for any annotations that are not in the object model
7879 if (jsonObject instanceof IJsonBackedObject ) {
7980 logger .logDebug ("Deserializing type " + clazz .getSimpleName ());
80- final IJsonBackedObject jsonBackedObject = (IJsonBackedObject ) jsonObject ;
8181 final JsonObject rawObject = gson .fromJson (inputString , JsonObject .class );
82-
83- // If there is a derived class, try to get it and deserialize to it
84- Class derivedClass = this .getDerivedClass (rawObject , clazz );
85- if (derivedClass != null ) {
86- jsonObject = (T ) gson .fromJson (inputString , derivedClass );
87- }
88-
82+
83+ // If there is a derived class, try to get it and deserialize to it
84+ Class <?> derivedClass = this .getDerivedClass (rawObject , clazz );
85+ final T jo ;
86+ if (derivedClass != null ) {
87+ jo = (T ) gson .fromJson (inputString , derivedClass );
88+ } else {
89+ jo = jsonObject ;
90+ }
91+
92+ final IJsonBackedObject jsonBackedObject = (IJsonBackedObject ) jo ;
8993 jsonBackedObject .setRawObject (this , rawObject );
9094
9195 if (responseHeaders != null ) {
@@ -94,11 +98,11 @@ public <T> T deserializeObject(final String inputString, final Class<T> clazz, M
9498 }
9599
96100 jsonBackedObject .additionalDataManager ().setAdditionalData (rawObject );
101+ return jo ;
97102 } else {
98103 logger .logDebug ("Deserializing a non-IJsonBackedObject type " + clazz .getSimpleName ());
104+ return jsonObject ;
99105 }
100-
101- return jsonObject ;
102106 }
103107
104108 /**
0 commit comments