samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Client/ApiClient.cs
/// <summary>
/// Deserialize the JSON string into a proper object.
/// </summary>
/// <param name="response">The HTTP response.</param>
/// <param name="type">Object type.</param>
/// <returns>Object representation of the JSON string.</returns>
Deserialize the JSON string into a proper object.
Deserialize the JSON string into a proper object .
public object Deserialize(IRestResponse response, Type type)
        {
            byte[] data = response.RawBytes;
            string content = response.Content;
            IList<Parameter> headers = response.Headers;
            if (type == typeof(Object)) 
            {
                return content;
            }
            if (type == typeof(Stream))
            {
                if (headers != null)
                {
                    var filePath = String.IsNullOrEmpty(Configuration.TempFolderPath)
                        ? Path.GetTempPath()
                        : Configuration.TempFolderPath;
                    var regex = new Regex(@"Content-Disposition:.*filename=['""]?([^'""\s]+)['""]?$");
                    var match = regex.Match(headers.ToString());
                    if (match.Success)
                    {
                        string fileName = filePath + match.Value.Replace("\"", "").Replace("'", "");
                        File.WriteAllBytes(fileName, data);
                        return new FileStream(fileName, FileMode.Open);
                    }
                }
                var stream = new MemoryStream(data);
                return stream;
            }
            if (type.Name.StartsWith("System.Nullable`1[[System.DateTime")) 
            {
                return DateTime.Parse(content,  null, System.Globalization.DateTimeStyles.RoundtripKind);
            }
            if (type == typeof(String) || type.Name.StartsWith("System.Nullable")) 
            {
                return ConvertType(content, type); 
            }
            try
            {
                return JsonConvert.DeserializeObject(content, type);
            }
            catch (Exception e)
            {
                throw new ApiException(500, e.Message);
            }
        }
public object Deserialize ( IRestResponse response , Type type ) { byte [ ] data = response . RawBytes ; string content = response . Content ; IList < Parameter > headers = response . Headers ; if ( type == typeof ( Object ) ) { return content ; } if ( type == typeof ( Stream ) ) { if ( headers != null ) { var filePath = String . IsNullOrEmpty ( Configuration . TempFolderPath ) ? Path . GetTempPath ( ) : Configuration . TempFolderPath ; var regex = new Regex ( @"Content-Disposition:.*filename=['""]?([^'""\s]+)['""]?$" ) ; var match = regex . Match ( headers . ToString ( ) ) ; if ( match . Success ) { string fileName = filePath + match . Value . Replace ( " \" " , " " ) . Replace ( " " , " " ) ; File . WriteAllBytes ( fileName , data ) ; return new FileStream ( fileName , FileMode . Open ) ; } } var stream = new MemoryStream ( data ) ; return stream ; } if ( type . Name . StartsWith ( " " ) ) { return DateTime . Parse ( content , null , System . Globalization . DateTimeStyles . RoundtripKind ) ; } if ( type == typeof ( String ) || type . Name . StartsWith ( " " ) ) { return ConvertType ( content , type ) ; } try { return JsonConvert . DeserializeObject ( content , type ) ; } catch ( Exception e ) { throw new ApiException ( 500 , e . Message ) ; } }
Deserialize the JSON string into a proper object.
Deserialize the JSON string into a proper object .
// return an object // return a datetime object // return primitive type // at this point, it must be a model (json)
Object representation of the JSON string.
Object representation of the JSON string .
response
IRestResponse
The HTTP response.
The HTTP response .
type
Type
None