fixed serialization of arrays

This commit is contained in:
Tony Tam 2015-04-04 17:20:18 -07:00
parent bba91c7e92
commit 950bfff1c1
7 changed files with 51 additions and 136 deletions

View File

@ -105,12 +105,7 @@ public class {{classname}} {
return {{#returnType}}null{{/returnType}};
}
} catch (ApiException ex) {
if(ex.getCode() == 404) {
return {{#returnType}} null{{/returnType}};
}
else {
throw ex;
}
throw ex;
}
}
{{/operation}}

View File

@ -24,6 +24,7 @@ import java.net.Socket;
import java.net.UnknownHostException;
import java.net.URLEncoder;
import java.util.Collection;
import java.util.Map;
import java.util.HashMap;
import java.util.List;
@ -120,6 +121,15 @@ public class ApiInvoker {
return "";
} else if (param instanceof Date) {
return formatDateTime((Date) param);
} else if (param instanceof Collection) {
StringBuilder b = new StringBuilder();
for(Object o : (Collection)param) {
if(b.length() > 0) {
b.append(",");
}
b.append(String.valueOf(o));
}
return b.toString();
} else {
return String.valueOf(param);
}
@ -147,7 +157,7 @@ public class ApiInvoker {
public static Object deserialize(String json, String containerType, Class cls) throws ApiException {
try{
if("List".equals(containerType)) {
if("list".equalsIgnoreCase(containerType) || "array".equalsIgnoreCase(containerType)) {
JavaType typeInfo = JsonUtil.getJsonMapper().getTypeFactory().constructCollectionType(List.class, cls);
List response = (List<?>) JsonUtil.getJsonMapper().readValue(json, typeInfo);
return response;
@ -307,6 +317,7 @@ public class ApiInvoker {
HttpEntity resEntity = response.getEntity();
responseString = EntityUtils.toString(resEntity);
}
return responseString;
}
else {
if(response.getEntity() != null) {
@ -315,9 +326,8 @@ public class ApiInvoker {
}
else
responseString = "no data";
throw new ApiException(code, responseString);
}
return responseString;
throw new ApiException(code, responseString);
}
catch(IOException e) {
throw new ApiException(500, e.getMessage());

View File

@ -24,6 +24,7 @@ import java.net.Socket;
import java.net.UnknownHostException;
import java.net.URLEncoder;
import java.util.Collection;
import java.util.Map;
import java.util.HashMap;
import java.util.List;
@ -120,6 +121,15 @@ public class ApiInvoker {
return "";
} else if (param instanceof Date) {
return formatDateTime((Date) param);
} else if (param instanceof Collection) {
StringBuilder b = new StringBuilder();
for(Object o : (Collection)param) {
if(b.length() > 0) {
b.append(",");
}
b.append(String.valueOf(o));
}
return b.toString();
} else {
return String.valueOf(param);
}
@ -147,7 +157,7 @@ public class ApiInvoker {
public static Object deserialize(String json, String containerType, Class cls) throws ApiException {
try{
if("List".equals(containerType)) {
if("list".equalsIgnoreCase(containerType) || "array".equalsIgnoreCase(containerType)) {
JavaType typeInfo = JsonUtil.getJsonMapper().getTypeFactory().constructCollectionType(List.class, cls);
List response = (List<?>) JsonUtil.getJsonMapper().readValue(json, typeInfo);
return response;
@ -307,6 +317,7 @@ public class ApiInvoker {
HttpEntity resEntity = response.getEntity();
responseString = EntityUtils.toString(resEntity);
}
return responseString;
}
else {
if(response.getEntity() != null) {
@ -315,9 +326,8 @@ public class ApiInvoker {
}
else
responseString = "no data";
throw new ApiException(code, responseString);
}
return responseString;
throw new ApiException(code, responseString);
}
catch(IOException e) {
throw new ApiException(500, e.getMessage());

View File

@ -84,12 +84,7 @@ public class PetApi {
return ;
}
} catch (ApiException ex) {
if(ex.getCode() == 404) {
return ;
}
else {
throw ex;
}
throw ex;
}
}
@ -139,12 +134,7 @@ public class PetApi {
return ;
}
} catch (ApiException ex) {
if(ex.getCode() == 404) {
return ;
}
else {
throw ex;
}
throw ex;
}
}
@ -196,12 +186,7 @@ public class PetApi {
return null;
}
} catch (ApiException ex) {
if(ex.getCode() == 404) {
return null;
}
else {
throw ex;
}
throw ex;
}
}
@ -253,12 +238,7 @@ public class PetApi {
return null;
}
} catch (ApiException ex) {
if(ex.getCode() == 404) {
return null;
}
else {
throw ex;
}
throw ex;
}
}
@ -308,12 +288,7 @@ public class PetApi {
return null;
}
} catch (ApiException ex) {
if(ex.getCode() == 404) {
return null;
}
else {
throw ex;
}
throw ex;
}
}
@ -373,12 +348,7 @@ public class PetApi {
return ;
}
} catch (ApiException ex) {
if(ex.getCode() == 404) {
return ;
}
else {
throw ex;
}
throw ex;
}
}
@ -429,12 +399,7 @@ public class PetApi {
return ;
}
} catch (ApiException ex) {
if(ex.getCode() == 404) {
return ;
}
else {
throw ex;
}
throw ex;
}
}
@ -494,12 +459,7 @@ public class PetApi {
return ;
}
} catch (ApiException ex) {
if(ex.getCode() == 404) {
return ;
}
else {
throw ex;
}
throw ex;
}
}

View File

@ -84,12 +84,7 @@ public class StoreApi {
return null;
}
} catch (ApiException ex) {
if(ex.getCode() == 404) {
return null;
}
else {
throw ex;
}
throw ex;
}
}
@ -139,12 +134,7 @@ public class StoreApi {
return null;
}
} catch (ApiException ex) {
if(ex.getCode() == 404) {
return null;
}
else {
throw ex;
}
throw ex;
}
}
@ -194,12 +184,7 @@ public class StoreApi {
return null;
}
} catch (ApiException ex) {
if(ex.getCode() == 404) {
return null;
}
else {
throw ex;
}
throw ex;
}
}
@ -249,12 +234,7 @@ public class StoreApi {
return ;
}
} catch (ApiException ex) {
if(ex.getCode() == 404) {
return ;
}
else {
throw ex;
}
throw ex;
}
}

View File

@ -84,12 +84,7 @@ public class UserApi {
return ;
}
} catch (ApiException ex) {
if(ex.getCode() == 404) {
return ;
}
else {
throw ex;
}
throw ex;
}
}
@ -139,12 +134,7 @@ public class UserApi {
return ;
}
} catch (ApiException ex) {
if(ex.getCode() == 404) {
return ;
}
else {
throw ex;
}
throw ex;
}
}
@ -194,12 +184,7 @@ public class UserApi {
return ;
}
} catch (ApiException ex) {
if(ex.getCode() == 404) {
return ;
}
else {
throw ex;
}
throw ex;
}
}
@ -253,12 +238,7 @@ public class UserApi {
return null;
}
} catch (ApiException ex) {
if(ex.getCode() == 404) {
return null;
}
else {
throw ex;
}
throw ex;
}
}
@ -308,12 +288,7 @@ public class UserApi {
return ;
}
} catch (ApiException ex) {
if(ex.getCode() == 404) {
return ;
}
else {
throw ex;
}
throw ex;
}
}
@ -363,12 +338,7 @@ public class UserApi {
return null;
}
} catch (ApiException ex) {
if(ex.getCode() == 404) {
return null;
}
else {
throw ex;
}
throw ex;
}
}
@ -418,12 +388,7 @@ public class UserApi {
return ;
}
} catch (ApiException ex) {
if(ex.getCode() == 404) {
return ;
}
else {
throw ex;
}
throw ex;
}
}
@ -473,12 +438,7 @@ public class UserApi {
return ;
}
} catch (ApiException ex) {
if(ex.getCode() == 404) {
return ;
}
else {
throw ex;
}
throw ex;
}
}

View File

@ -444,11 +444,11 @@
<h3 class="field-label">Example data</h3>
<div class="example-data-content-type">Content-Type: application/json</div>
<pre class="example"><code>{\n "id" : 123456789,\n "petId" : 123456789,\n "complete" : true,\n "status" : "aeiou",\n "quantity" : 123,\n "shipDate" : "2015-04-04T23:36:32.265+0000"\n}</code></pre>
<pre class="example"><code>{\n "id" : 123456789,\n "petId" : 123456789,\n "complete" : true,\n "status" : "aeiou",\n "quantity" : 123,\n "shipDate" : "2015-04-05T00:02:39.658+0000"\n}</code></pre>
<h3 class="field-label">Example data</h3>
<div class="example-data-content-type">Content-Type: application/xml</div>
<pre class="example"><code><Order>\n <id>123456</id>\n <petId>123456</petId>\n <quantity>0</quantity>\n <shipDate>2015-04-04T16:36:32.268Z</shipDate>\n <status>string</status>\n <complete>true</complete>\n</Order></code></pre>
<pre class="example"><code><Order>\n <id>123456</id>\n <petId>123456</petId>\n <quantity>0</quantity>\n <shipDate>2015-04-04T17:02:39.662Z</shipDate>\n <status>string</status>\n <complete>true</complete>\n</Order></code></pre>
</div> <!-- method -->
<hr>
@ -472,11 +472,11 @@
<h3 class="field-label">Example data</h3>
<div class="example-data-content-type">Content-Type: application/json</div>
<pre class="example"><code>{\n "id" : 123456789,\n "petId" : 123456789,\n "complete" : true,\n "status" : "aeiou",\n "quantity" : 123,\n "shipDate" : "2015-04-04T23:36:32.269+0000"\n}</code></pre>
<pre class="example"><code>{\n "id" : 123456789,\n "petId" : 123456789,\n "complete" : true,\n "status" : "aeiou",\n "quantity" : 123,\n "shipDate" : "2015-04-05T00:02:39.664+0000"\n}</code></pre>
<h3 class="field-label">Example data</h3>
<div class="example-data-content-type">Content-Type: application/xml</div>
<pre class="example"><code><Order>\n <id>123456</id>\n <petId>123456</petId>\n <quantity>0</quantity>\n <shipDate>2015-04-04T16:36:32.270Z</shipDate>\n <status>string</status>\n <complete>true</complete>\n</Order></code></pre>
<pre class="example"><code><Order>\n <id>123456</id>\n <petId>123456</petId>\n <quantity>0</quantity>\n <shipDate>2015-04-04T17:02:39.664Z</shipDate>\n <status>string</status>\n <complete>true</complete>\n</Order></code></pre>
</div> <!-- method -->
<hr>