1515 */
1616package org .labkey .remoteapi ;
1717
18- import org .json .simple .JSONObject ;
19- import org .json .simple .JSONValue ;
18+ import org .json .JSONObject ;
2019
2120import java .util .List ;
2221import java .util .Map ;
4342 */
4443public class CommandResponse
4544{
46- private String _text ;
47- private int _statusCode ;
48- private String _contentType ;
49- private JSONObject _data = null ;
50- private Command _sourceCommand ;
45+ private final String _text ;
46+ private final int _statusCode ;
47+ private final String _contentType ;
48+ private final Command _sourceCommand ;
49+
50+ private Map <String , Object > _data ;
5151
5252 /**
5353 * Constructs a new CommandResponse, initialized with the provided
@@ -63,7 +63,7 @@ public CommandResponse(String text, int statusCode, String contentType, JSONObje
6363 _text = text ;
6464 _statusCode = statusCode ;
6565 _contentType = contentType ;
66- _data = json ;
66+ _data = null != json ? json . toMap () : null ;
6767 _sourceCommand = sourceCommand ;
6868 }
6969
@@ -134,9 +134,9 @@ public Command getSourceCommand()
134134 @ SuppressWarnings ("unchecked" )
135135 public Map <String , Object > getParsedData ()
136136 {
137- if (null == _data && null != getText ()
137+ if (null == _data && null != getText ()
138138 && null != _contentType && _contentType .contains (Command .CONTENT_TYPE_JSON ))
139- _data = ( JSONObject ) JSONValue . parse (getText ());
139+ _data = new JSONObject (getText ()). toMap ( );
140140 return _data ;
141141 }
142142
@@ -158,9 +158,9 @@ public <T> T getProperty(String path)
158158 {
159159 assert null != path ;
160160 String [] pathParts = path .split ("\\ ." );
161- if ( null == pathParts || pathParts .length == 0 )
161+ if ( pathParts .length == 0 )
162162 return null ;
163- return ( T ) getProperty (pathParts , 0 , getParsedData ());
163+ return getProperty (pathParts , 0 , getParsedData ());
164164 }
165165
166166 /**
@@ -176,7 +176,7 @@ public <T> T getProperty(String path)
176176 @ SuppressWarnings ("unchecked" )
177177 protected <T > T getProperty (String [] path , int pathIndex , Map <String , Object > parent )
178178 {
179- if (null == parent )
179+ if (null == parent )
180180 return null ;
181181
182182 String key = path [pathIndex ];
@@ -192,20 +192,20 @@ protected <T> T getProperty(String[] path, int pathIndex, Map<String, Object> pa
192192 Object prop = parent .get (key );
193193 if (arrayIndex != null )
194194 {
195- if (prop != null && prop instanceof List && ((List )prop ).size () > arrayIndex )
195+ if (prop instanceof List && ((List ) prop ).size () > arrayIndex )
196196 prop = ((List )prop ).get (arrayIndex );
197197 else
198198 return null ;
199199 }
200200
201201 //if this was the last path part, return the prop
202202 //will return null if final path part not found
203- if (pathIndex == (path .length -1 ))
203+ if (pathIndex == (path .length -1 ))
204204 return (T )prop ;
205205 else
206206 {
207207 //recurse if prop is non-null and instance of map
208- return (null != prop && prop instanceof Map )
208+ return (prop instanceof Map )
209209 ? (T )getProperty (path , pathIndex + 1 , (Map <String , Object >)prop )
210210 : null ;
211211 }
0 commit comments