forked from loafle/openapi-generator-original
fixed serialization of arrays
This commit is contained in:
parent
bba91c7e92
commit
950bfff1c1
@ -105,12 +105,7 @@ public class {{classname}} {
|
|||||||
return {{#returnType}}null{{/returnType}};
|
return {{#returnType}}null{{/returnType}};
|
||||||
}
|
}
|
||||||
} catch (ApiException ex) {
|
} catch (ApiException ex) {
|
||||||
if(ex.getCode() == 404) {
|
throw ex;
|
||||||
return {{#returnType}} null{{/returnType}};
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw ex;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{{/operation}}
|
{{/operation}}
|
||||||
|
@ -24,6 +24,7 @@ import java.net.Socket;
|
|||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -120,6 +121,15 @@ public class ApiInvoker {
|
|||||||
return "";
|
return "";
|
||||||
} else if (param instanceof Date) {
|
} else if (param instanceof Date) {
|
||||||
return formatDateTime((Date) param);
|
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 {
|
} else {
|
||||||
return String.valueOf(param);
|
return String.valueOf(param);
|
||||||
}
|
}
|
||||||
@ -147,7 +157,7 @@ public class ApiInvoker {
|
|||||||
|
|
||||||
public static Object deserialize(String json, String containerType, Class cls) throws ApiException {
|
public static Object deserialize(String json, String containerType, Class cls) throws ApiException {
|
||||||
try{
|
try{
|
||||||
if("List".equals(containerType)) {
|
if("list".equalsIgnoreCase(containerType) || "array".equalsIgnoreCase(containerType)) {
|
||||||
JavaType typeInfo = JsonUtil.getJsonMapper().getTypeFactory().constructCollectionType(List.class, cls);
|
JavaType typeInfo = JsonUtil.getJsonMapper().getTypeFactory().constructCollectionType(List.class, cls);
|
||||||
List response = (List<?>) JsonUtil.getJsonMapper().readValue(json, typeInfo);
|
List response = (List<?>) JsonUtil.getJsonMapper().readValue(json, typeInfo);
|
||||||
return response;
|
return response;
|
||||||
@ -307,6 +317,7 @@ public class ApiInvoker {
|
|||||||
HttpEntity resEntity = response.getEntity();
|
HttpEntity resEntity = response.getEntity();
|
||||||
responseString = EntityUtils.toString(resEntity);
|
responseString = EntityUtils.toString(resEntity);
|
||||||
}
|
}
|
||||||
|
return responseString;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if(response.getEntity() != null) {
|
if(response.getEntity() != null) {
|
||||||
@ -315,9 +326,8 @@ public class ApiInvoker {
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
responseString = "no data";
|
responseString = "no data";
|
||||||
throw new ApiException(code, responseString);
|
|
||||||
}
|
}
|
||||||
return responseString;
|
throw new ApiException(code, responseString);
|
||||||
}
|
}
|
||||||
catch(IOException e) {
|
catch(IOException e) {
|
||||||
throw new ApiException(500, e.getMessage());
|
throw new ApiException(500, e.getMessage());
|
||||||
|
@ -24,6 +24,7 @@ import java.net.Socket;
|
|||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -120,6 +121,15 @@ public class ApiInvoker {
|
|||||||
return "";
|
return "";
|
||||||
} else if (param instanceof Date) {
|
} else if (param instanceof Date) {
|
||||||
return formatDateTime((Date) param);
|
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 {
|
} else {
|
||||||
return String.valueOf(param);
|
return String.valueOf(param);
|
||||||
}
|
}
|
||||||
@ -147,7 +157,7 @@ public class ApiInvoker {
|
|||||||
|
|
||||||
public static Object deserialize(String json, String containerType, Class cls) throws ApiException {
|
public static Object deserialize(String json, String containerType, Class cls) throws ApiException {
|
||||||
try{
|
try{
|
||||||
if("List".equals(containerType)) {
|
if("list".equalsIgnoreCase(containerType) || "array".equalsIgnoreCase(containerType)) {
|
||||||
JavaType typeInfo = JsonUtil.getJsonMapper().getTypeFactory().constructCollectionType(List.class, cls);
|
JavaType typeInfo = JsonUtil.getJsonMapper().getTypeFactory().constructCollectionType(List.class, cls);
|
||||||
List response = (List<?>) JsonUtil.getJsonMapper().readValue(json, typeInfo);
|
List response = (List<?>) JsonUtil.getJsonMapper().readValue(json, typeInfo);
|
||||||
return response;
|
return response;
|
||||||
@ -307,6 +317,7 @@ public class ApiInvoker {
|
|||||||
HttpEntity resEntity = response.getEntity();
|
HttpEntity resEntity = response.getEntity();
|
||||||
responseString = EntityUtils.toString(resEntity);
|
responseString = EntityUtils.toString(resEntity);
|
||||||
}
|
}
|
||||||
|
return responseString;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if(response.getEntity() != null) {
|
if(response.getEntity() != null) {
|
||||||
@ -315,9 +326,8 @@ public class ApiInvoker {
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
responseString = "no data";
|
responseString = "no data";
|
||||||
throw new ApiException(code, responseString);
|
|
||||||
}
|
}
|
||||||
return responseString;
|
throw new ApiException(code, responseString);
|
||||||
}
|
}
|
||||||
catch(IOException e) {
|
catch(IOException e) {
|
||||||
throw new ApiException(500, e.getMessage());
|
throw new ApiException(500, e.getMessage());
|
||||||
|
@ -84,12 +84,7 @@ public class PetApi {
|
|||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
} catch (ApiException ex) {
|
} catch (ApiException ex) {
|
||||||
if(ex.getCode() == 404) {
|
throw ex;
|
||||||
return ;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw ex;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,12 +134,7 @@ public class PetApi {
|
|||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
} catch (ApiException ex) {
|
} catch (ApiException ex) {
|
||||||
if(ex.getCode() == 404) {
|
throw ex;
|
||||||
return ;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw ex;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -196,12 +186,7 @@ public class PetApi {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
} catch (ApiException ex) {
|
} catch (ApiException ex) {
|
||||||
if(ex.getCode() == 404) {
|
throw ex;
|
||||||
return null;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw ex;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -253,12 +238,7 @@ public class PetApi {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
} catch (ApiException ex) {
|
} catch (ApiException ex) {
|
||||||
if(ex.getCode() == 404) {
|
throw ex;
|
||||||
return null;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw ex;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -308,12 +288,7 @@ public class PetApi {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
} catch (ApiException ex) {
|
} catch (ApiException ex) {
|
||||||
if(ex.getCode() == 404) {
|
throw ex;
|
||||||
return null;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw ex;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -373,12 +348,7 @@ public class PetApi {
|
|||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
} catch (ApiException ex) {
|
} catch (ApiException ex) {
|
||||||
if(ex.getCode() == 404) {
|
throw ex;
|
||||||
return ;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw ex;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -429,12 +399,7 @@ public class PetApi {
|
|||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
} catch (ApiException ex) {
|
} catch (ApiException ex) {
|
||||||
if(ex.getCode() == 404) {
|
throw ex;
|
||||||
return ;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw ex;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -494,12 +459,7 @@ public class PetApi {
|
|||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
} catch (ApiException ex) {
|
} catch (ApiException ex) {
|
||||||
if(ex.getCode() == 404) {
|
throw ex;
|
||||||
return ;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw ex;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,12 +84,7 @@ public class StoreApi {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
} catch (ApiException ex) {
|
} catch (ApiException ex) {
|
||||||
if(ex.getCode() == 404) {
|
throw ex;
|
||||||
return null;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw ex;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,12 +134,7 @@ public class StoreApi {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
} catch (ApiException ex) {
|
} catch (ApiException ex) {
|
||||||
if(ex.getCode() == 404) {
|
throw ex;
|
||||||
return null;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw ex;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,12 +184,7 @@ public class StoreApi {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
} catch (ApiException ex) {
|
} catch (ApiException ex) {
|
||||||
if(ex.getCode() == 404) {
|
throw ex;
|
||||||
return null;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw ex;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -249,12 +234,7 @@ public class StoreApi {
|
|||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
} catch (ApiException ex) {
|
} catch (ApiException ex) {
|
||||||
if(ex.getCode() == 404) {
|
throw ex;
|
||||||
return ;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw ex;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,12 +84,7 @@ public class UserApi {
|
|||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
} catch (ApiException ex) {
|
} catch (ApiException ex) {
|
||||||
if(ex.getCode() == 404) {
|
throw ex;
|
||||||
return ;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw ex;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,12 +134,7 @@ public class UserApi {
|
|||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
} catch (ApiException ex) {
|
} catch (ApiException ex) {
|
||||||
if(ex.getCode() == 404) {
|
throw ex;
|
||||||
return ;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw ex;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,12 +184,7 @@ public class UserApi {
|
|||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
} catch (ApiException ex) {
|
} catch (ApiException ex) {
|
||||||
if(ex.getCode() == 404) {
|
throw ex;
|
||||||
return ;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw ex;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -253,12 +238,7 @@ public class UserApi {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
} catch (ApiException ex) {
|
} catch (ApiException ex) {
|
||||||
if(ex.getCode() == 404) {
|
throw ex;
|
||||||
return null;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw ex;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -308,12 +288,7 @@ public class UserApi {
|
|||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
} catch (ApiException ex) {
|
} catch (ApiException ex) {
|
||||||
if(ex.getCode() == 404) {
|
throw ex;
|
||||||
return ;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw ex;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -363,12 +338,7 @@ public class UserApi {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
} catch (ApiException ex) {
|
} catch (ApiException ex) {
|
||||||
if(ex.getCode() == 404) {
|
throw ex;
|
||||||
return null;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw ex;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -418,12 +388,7 @@ public class UserApi {
|
|||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
} catch (ApiException ex) {
|
} catch (ApiException ex) {
|
||||||
if(ex.getCode() == 404) {
|
throw ex;
|
||||||
return ;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw ex;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -473,12 +438,7 @@ public class UserApi {
|
|||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
} catch (ApiException ex) {
|
} catch (ApiException ex) {
|
||||||
if(ex.getCode() == 404) {
|
throw ex;
|
||||||
return ;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw ex;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -444,11 +444,11 @@
|
|||||||
|
|
||||||
<h3 class="field-label">Example data</h3>
|
<h3 class="field-label">Example data</h3>
|
||||||
<div class="example-data-content-type">Content-Type: application/json</div>
|
<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>
|
<h3 class="field-label">Example data</h3>
|
||||||
<div class="example-data-content-type">Content-Type: application/xml</div>
|
<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 -->
|
</div> <!-- method -->
|
||||||
<hr>
|
<hr>
|
||||||
@ -472,11 +472,11 @@
|
|||||||
|
|
||||||
<h3 class="field-label">Example data</h3>
|
<h3 class="field-label">Example data</h3>
|
||||||
<div class="example-data-content-type">Content-Type: application/json</div>
|
<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>
|
<h3 class="field-label">Example data</h3>
|
||||||
<div class="example-data-content-type">Content-Type: application/xml</div>
|
<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 -->
|
</div> <!-- method -->
|
||||||
<hr>
|
<hr>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user