public String asJSON ( boolean pretty ) { JSONSerializer ser = new JSONSerializer ( ) ; Gson gson = new Gson ( ) ; Gson prettyJson = new GsonBuilder ( ) . setPrettyPrinting ( ) . create ( ) ; JsonArray cacheArray = new JsonArray ( ) ; String cacheAsString ; for ( ServiceWrapper s : _cache ) { String json = ser . marshalService ( s ) ; JsonObject jsonService = gson . fromJson ( json , JsonObject . class ) ; cacheArray . add ( jsonService ) ; } if ( pretty ) { cacheAsString = prettyJson . toJson ( cacheArray ) ; } else { cacheAsString = gson . toJson ( cacheArray ) ; } return cacheAsString ; }
Return the cache as JSON .