android json2java 1.4

V1.4下载地址

项目效果图

Alt Text

V1.1功能

  1. 序列化
  2. toString
  3. 无参构造(fastjson要求必须有)
  4. 有参构造

    V1.2增加功能

  5. 增加所有Class生成在同一个文件的选项
  6. 增加只能判断getter/setter的选项,不生成的时候字段类型为public

    V1.3增加功能

  7. 增加对json中null的处理,转成Object
  8. 增加对json数据类型的判断

    V1.4增加功能

  9. 对于”dataList”: []这样的类型处理会有错误,处理成List dataList;。

  10. 对于”data”: {}这样的类型处理会有错误,处理成Object data;。
  11. 对于”tag”: [“亚马逊”,”苹果”,”微软”,”公司财报”]这样的类型处理成List
  12. 如果json中key有java关键字(如abstract),原样生成会有错误,将首字母大写可避免出错,虽然有点不规范o(╯□╰)o
  13. 不同节点有相同的key,这个时候需要合并该key对应class的字段。比如:
    1
    2
    3
    4
    "emailaddrs": [   
    {"type": "work", "value": "kelly@seankelly.biz"},
    {"type": "home", "pref": 1, "value": "kelly@seankelly.tv"}
    ]

存在问题

  1. 对于"dataList": []这样的类型处理会有错误,将在下一版本修正。
  2. 对于"data": {}这样的类型处理会有错误,将在下一版本修正。

    json文件:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    {
    "errorCode":0,
    "errorMessage":"",
    "dataLong":2147483647888,
    "dataBoolean":false,
    "dataDouble":179762311111308.23232,
    "fullname": "Sean Kelly",
    "org": "SK Consulting",
    "emailaddrs": [
    {"type": "work", "value": "kelly@seankelly.biz"},
    {"type": "home", "pref": 1, "value": "kelly@seankelly.tv"}
    ],

    "telephones": [
    {"type": "work", "pref": 1, "value": "+1 214 555 1212"},
    {"type": "fax", "value": "+1 214 555 1213"},
    {"type": "mobile", "value": "+1 214 555 1214"}
    ],

    "addresses": [
    {"type": "work", "format": "us",
    "value": "1234 Main StnSpringfield, TX 78080-1216"},
    {"type": "home", "format": "us",
    "value": "5678 Main StnSpringfield, TX 78080-1316"}
    ],

    "urls": [
    {"type": "work", "value": "http://seankelly.biz/"},
    {"type": "home", "value": "http://seankelly.tv/"}
    ]
    }

最简版的效果

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package com.snscity;

public class ExampleBean{
public boolean dataBoolean;
public Emailaddrs emailaddrs;
public double dataDouble;
public String fullname;
public Telephones telephones;
public long dataLong;
public Addresses addresses;
public Urls urls;
public String org;
public long errorCode;
public String errorMessage;
}
class Urls{
public String value;
public String type;
}
class Addresses{
public String value;
public String format;
public String type;
}
class Telephones{
public String value;
public String type;
public long pref;
}
class Emailaddrs{
public String value;
public String type;
}

最完整版本

package com.snscity;

import java.io.Serializable;

public class ExampleBean implements Serializable{
    private static final long serialVersionUID = 66883584L;
    private boolean dataBoolean;
    private Emailaddrs emailaddrs;
    private double dataDouble;
    private String fullname;
    private Telephones telephones;
    private long dataLong;
    private Addresses addresses;
    private Urls urls;
    private String org;
    private long errorCode;
    private String errorMessage;

    public boolean getDataBoolean() {
        return this.dataBoolean;
    }

    public void setDataBoolean(boolean dataBoolean) {
        this.dataBoolean = dataBoolean;
    }

    public Emailaddrs getEmailaddrs() {
        return this.emailaddrs;
    }

    public void setEmailaddrs(Emailaddrs emailaddrs) {
        this.emailaddrs = emailaddrs;
    }

    public double getDataDouble() {
        return this.dataDouble;
    }

    public void setDataDouble(double dataDouble) {
        this.dataDouble = dataDouble;
    }

    public String getFullname() {
        return this.fullname;
    }

    public void setFullname(String fullname) {
        this.fullname = fullname;
    }

    public Telephones getTelephones() {
        return this.telephones;
    }

    public void setTelephones(Telephones telephones) {
        this.telephones = telephones;
    }

    public long getDataLong() {
        return this.dataLong;
    }

    public void setDataLong(long dataLong) {
        this.dataLong = dataLong;
    }

    public Addresses getAddresses() {
        return this.addresses;
    }

    public void setAddresses(Addresses addresses) {
        this.addresses = addresses;
    }

    public Urls getUrls() {
        return this.urls;
    }

    public void setUrls(Urls urls) {
        this.urls = urls;
    }

    public String getOrg() {
        return this.org;
    }

    public void setOrg(String org) {
        this.org = org;
    }

    public long getErrorCode() {
        return this.errorCode;
    }

    public void setErrorCode(long errorCode) {
        this.errorCode = errorCode;
    }

    public String getErrorMessage() {
        return this.errorMessage;
    }

    public void setErrorMessage(String errorMessage) {
        this.errorMessage = errorMessage;
    }

    public ExampleBean() {}

    public ExampleBean(boolean dataBoolean, Emailaddrs emailaddrs, double dataDouble, String fullname, Telephones telephones, long dataLong, Addresses addresses, Urls urls, String org, long errorCode, String errorMessage){
        super();
        this.dataBoolean = dataBoolean;
        this.emailaddrs = emailaddrs;
        this.dataDouble = dataDouble;
        this.fullname = fullname;
        this.telephones = telephones;
        this.dataLong = dataLong;
        this.addresses = addresses;
        this.urls = urls;
        this.org = org;
        this.errorCode = errorCode;
        this.errorMessage = errorMessage;
    }

    public String toString() {
        return "ExampleBean [dataBoolean = " + dataBoolean + ", emailaddrs = " + emailaddrs + ", dataDouble = " + dataDouble + ", fullname = " + fullname + ", telephones = " + telephones + ", dataLong = " + dataLong + ", addresses = " + addresses + ", urls = " + urls + ", org = " + org + ", errorCode = " + errorCode + ", errorMessage = " + errorMessage + "]";
    }
}
class Urls implements Serializable{
    private static final long serialVersionUID = 66883584L;
    private String value;
    private String type;

    public String getValue() {
        return this.value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public String getType() {
        return this.type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public Urls() {}

    public Urls(String value, String type){
        super();
        this.value = value;
        this.type = type;
    }

    public String toString() {
        return "ExampleBean [value = " + value + ", type = " + type + "]";
    }
}
class Addresses implements Serializable{
    private static final long serialVersionUID = 66883584L;
    private String value;
    private String format;
    private String type;

    public String getValue() {
        return this.value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public String getFormat() {
        return this.format;
    }

    public void setFormat(String format) {
        this.format = format;
    }

    public String getType() {
        return this.type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public Addresses() {}

    public Addresses(String value, String format, String type){
        super();
        this.value = value;
        this.format = format;
        this.type = type;
    }

    public String toString() {
        return "ExampleBean [value = " + value + ", format = " + format + ", type = " + type + "]";
    }
}
class Telephones implements Serializable{
    private static final long serialVersionUID = 66883584L;
    private String value;
    private String type;
    private long pref;

    public String getValue() {
        return this.value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public String getType() {
        return this.type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public long getPref() {
        return this.pref;
    }

    public void setPref(long pref) {
        this.pref = pref;
    }

    public Telephones() {}

    public Telephones(String value, String type, long pref){
        super();
        this.value = value;
        this.type = type;
        this.pref = pref;
    }

    public String toString() {
        return "ExampleBean [value = " + value + ", type = " + type + ", pref = " + pref + "]";
    }
}
class Emailaddrs implements Serializable{
    private static final long serialVersionUID = 66883584L;
    private String value;
    private String type;

    public String getValue() {
        return this.value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public String getType() {
        return this.type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public Emailaddrs() {}

    public Emailaddrs(String value, String type){
        super();
        this.value = value;
        this.type = type;
    }

    public String toString() {
        return "ExampleBean [value = " + value + ", type = " + type + "]";
    }
}
文章目录
  1. 1. 项目效果图
  2. 2. V1.1功能
  3. 3. V1.2增加功能
  4. 4. V1.3增加功能
  5. 5. V1.4增加功能
  6. 6. 存在问题
  7. 7. json文件:
  8. 8. 最简版的效果
  9. 9. 最完整版本