swagger-api / swagger-api/swagger-codegen
got error as parsing json
Open
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
/**
* cloudbuy
* This is a sample server cloudbuy server.
*
* OpenAPI spec version: 1.0.1
*
*
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/
package io.swagger.client.model;
import io.swagger.client.model.Order;
import io.swagger.client.model.Product;
import io.swagger.client.model.User;
import java.util.*;
import java.util.Date;
import io.swagger.annotations.*;
import com.google.gson.annotations.SerializedName;
/**
* 抽奖活动
**/
@ApiModel(description = "抽奖活动")
public class Activity {
@SerializedName("id")
private Long id = null;
@SerializedName("activityNumber")
private String activityNumber = null;
@SerializedName("winNumber")
private String winNumber = null;
@SerializedName("winuser")
private User winuser = null;
@SerializedName("orders")
private List<Order> orders = null;
@SerializedName("product")
private Product product = null;
@SerializedName("status")
private String status = null;
@SerializedName("avaliable")
private Integer avaliable = null;
@SerializedName("begintime")
private Date begintime = null;
@SerializedName("endtime")
private Date endtime = null;
/**
* 活动编号
**/
@ApiModelProperty(value = "活动编号")
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
/**
* 活动期号
**/
@ApiModelProperty(value = "活动期号")
public String getActivityNumber() {
return activityNumber;
}
public void setActivityNumber(String activityNumber) {
this.activityNumber = activityNumber;
}
/**
**/
@ApiModelProperty(value = "")
public String getWinNumber() {
return winNumber;
}
public void setWinNumber(String winNumber) {
this.winNumber = winNumber;
}
/**
**/
@ApiModelProperty(value = "")
public User getWinuser() {
return winuser;
}
public void setWinuser(User winuser) {
this.winuser = winuser;
}
/**
**/
@ApiModelProperty(value = "")
public List<Order> getOrders() {
return orders;
}
public void setOrders(List<Order> orders) {
this.orders = orders;
}
/**
**/
@ApiModelProperty(value = "")
public Product getProduct() {
return product;
}
public void setProduct(Product product) {
this.product = product;
}
/**
* 抽奖状态(1.进行中,2.揭晓中,3.完成)
**/
@ApiModelProperty(value = "抽奖状态(1.进行中,2.揭晓中,3.完成)")
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
/**
* 剩余人次
**/
@ApiModelProperty(value = "剩余人次")
public Integer getAvaliable() {
return avaliable;
}
public void setAvaliable(Integer avaliable) {
this.avaliable = avaliable;
}
/**
* 开始时间
**/
@ApiModelProperty(value = "开始时间")
public Date getBegintime() {
return begintime;
}
public void setBegintime(Date begintime) {
this.begintime = begintime;
}
/**
* 结束时间
**/
@ApiModelProperty(value = "结束时间")
public Date getEndtime() {
return endtime;
}
public void setEndtime(Date endtime) {
this.endtime = endtime;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Activity activity = (Activity) o;
return (this.id == null ? activity.id == null : this.id.equals(activity.id)) &&
(this.activityNumber == null ? activity.activityNumber == null : this.activityNumber.equals(activity.activityNumber)) &&
(this.winNumber == null ? activity.winNumber == null : this.winNumber.equals(activity.winNumber)) &&
(this.winuser == null ? activity.winuser == null : this.winuser.equals(activity.winuser)) &&
(this.orders == null ? activity.orders == null : this.orders.equals(activity.orders)) &&
(this.product == null ? activity.product == null : this.product.equals(activity.product)) &&
(this.status == null ? activity.status == null : this.status.equals(activity.status)) &&
(this.avaliable == null ? activity.avaliable == null : this.avaliable.equals(activity.avaliable)) &&
(this.begintime == null ? activity.begintime == null : this.begintime.equals(activity.begintime)) &&
(this.endtime == null ? activity.endtime == null : this.endtime.equals(activity.endtime));
}
@Override
public int hashCode() {
int result = 17;
result = 31 * result + (this.id == null ? 0: this.id.hashCode());
result = 31 * result + (this.activityNumber == null ? 0: this.activityNumber.hashCode());
result = 31 * result + (this.winNumber == null ? 0: this.winNumber.hashCode());
result = 31 * result + (this.winuser == null ? 0: this.winuser.hashCode());
result = 31 * result + (this.orders == null ? 0: this.orders.hashCode());
result = 31 * result + (this.product == null ? 0: this.product.hashCode());
result = 31 * result + (this.status == null ? 0: this.status.hashCode());
result = 31 * result + (this.avaliable == null ? 0: this.avaliable.hashCode());
result = 31 * result + (this.begintime == null ? 0: this.begintime.hashCode());
result = 31 * result + (this.endtime == null ? 0: this.endtime.hashCode());
return result;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class Activity {\n");
sb.append(" id: ").append(id).append("\n");
sb.append(" activityNumber: ").append(activityNumber).append("\n");
sb.append(" winNumber: ").append(winNumber).append("\n");
sb.append(" winuser: ").append(winuser).append("\n");
sb.append(" orders: ").append(orders).append("\n");
sb.append(" product: ").append(product).append("\n");
sb.append(" status: ").append(status).append("\n");
sb.append(" avaliable: ").append(avaliable).append("\n");
sb.append(" begintime: ").append(begintime).append("\n");
sb.append(" endtime: ").append(endtime).append("\n");
sb.append("}\n");
return sb.toString();
}
}
package io.swagger.client;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;
import org.apache.commons.io.FileUtils;
import com.google.gson.reflect.TypeToken;
import android.app.Activity;
import io.swagger.client.api.UserApi;
import io.swagger.client.model.InlineResponse200;
import io.swagger.client.model.InlineResponse2001;
public class Main {
public static void main(String[] args) throws TimeoutException, ExecutionException, InterruptedException, ApiException, IOException {
String project=System.getProperty("user.dir");
String json = FileUtils.readFileToString(new File("D:\\bxdev\\aliyun\\cloudbuy\\doc\\gen\\android\\src\\main\\java\\data.json"),Charset.forName("GBK"));
System.out.println(json);
InlineResponse2001 object = JsonUtil.deserializeToObject(json,InlineResponse200.class);
System.out.println(object);
}
}
{"total":1,"data":[{"id":33,"activityNumber":null,"winNumber":"111122223333","winuser":{"id":33,"userName":"qingtian","nickName":null,"email":null,"password":"123456","phone":"13730666347","userStatus":null,"level":"1"},"orders":[{"id":33,"orderActivity":[],"totalPrice":null,"status":"1","complete":true,"createBy":null}],"product":{"id":65,"name":"OPPO R9s Plus","introduction":"\n6.0英寸大屏,前后1600万像素,光学防抖!这一刻,更清晰!\n(颜色随机)Android 6.0系统,骁龙653处理器,本产品按照获得顺序和填写地址顺序发货哦~!","shortIntroduction":"6GB+64GB内存版 全网通4G手机 双卡双待 金色","detailUrl":"https://item.jd.com/4143446.html","price":3499,"priceType":"1","limitFlag":0,"limitMax":100,"total":35,"largePhotoUrls":"","photoUrls":"https://m.360buyimg.com/n12/jfs/t3982/272/122877612/84922/90018ce0/583d461fNc90d345f.jpg!q70.jpg;https://m.360buyimg.com/n12/jfs/t3565/80/2111927493/59996/3c417f/583d4625N40e85f59.jpg!q70.jpg;https://m.360buyimg.com/n12/jfs/t3952/281/108638797/47113/7a02ecea/583d4629N4cf4970d.jpg!q70.jpg;https://m.360buyimg.com/n12/jfs/t3310/201/2005678460/28838/a8e99bd8/583d462dNae5c8b65.jpg!q70.jpg;https://m.360buyimg.com/n12/jfs/t3871/70/74635942/54915/5037a87c/583d4636Nc1671f2b.jpg!q70.jpg","article":{"id":33,"name":"iphone7","richText":"新世纪电脑一层新"},"catagory":{"id":34,"name":"手机"},"tags":[]},"status":"1","avaliable":100,"begintime":"2017-05-26T01:57:17.159Z","endtime":"2017-05-26T01:57:17.159Z"}]}
Exception in thread "main" java.lang.NumberFormatException: For input string: "2017-05-26T01:57:17.159Z"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Long.parseLong(Long.java:589)
at java.lang.Long.parseLong(Long.java:631)
at com.google.gson.JsonPrimitive.getAsLong(JsonPrimitive.java:238)
at io.swagger.client.JsonUtil$1.deserialize(JsonUtil.java:36)
at io.swagger.client.JsonUtil$1.deserialize(JsonUtil.java:1)
at com.google.gson.TreeTypeAdapter.read(TreeTypeAdapter.java:58)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:116)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:216)
at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:40)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:82)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:61)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:116)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:216)
at com.google.gson.Gson.fromJson(Gson.java:879)
at com.google.gson.Gson.fromJson(Gson.java:844)
at com.google.gson.Gson.fromJson(Gson.java:793)
at io.swagger.client.JsonUtil.deserializeToObject(JsonUtil.java:54)
at io.swagger.client.Main.main(Main.java:29)
```java
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The failure is reported at JsonUtil.java:36 during Main.java:29 deserialization; start there and inspect how the sample's Date fields are handled. Re-run the shown JSON through Main and verify that deserialization completes without NumberFormatException.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, java
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100