Search in sources :

Example 1 with Department

use of com.alibaba.json.test.entity.Department in project fastjson by alibaba.

the class GenerateJavaTest method testGenerate.

public void testGenerate() {
    Group group = new Group();
    group.setName("Alibaba Group");
    group.setDescription("Alibaba Group makes it easy for anyone to buy or sell online anywhere in the world. ");
    {
        Company company = new Company();
        company.setId(createId());
        company.setName("Alibaba.com");
        company.setDescription("Global leader in e-commerce for small businesses");
        company.setStock("1688.HK");
        group.getCompanies().add(company);
        Department root = new Department();
        root.setId(createId());
        root.setName("B2B");
        company.setRootDepartment(root);
        {
            Department cbu = new Department();
            cbu.setId(createId());
            cbu.setName("CBU");
            root.getChildren().add(cbu);
            Employee emp0 = new Employee();
            emp0.setName("校长");
            emp0.setDescription("神棍敌人姐");
            emp0.setAge(3);
            emp0.setSalary(new BigDecimal("123456789.0123"));
            emp0.setBirthdate(new Date());
            emp0.setBadboy(true);
            cbu.getMembers().add(emp0);
        }
        {
            Department icbu = new Department();
            icbu.setId(createId());
            icbu.setName("ICBU");
            root.getChildren().add(icbu);
        }
    }
    {
        Company company = new Company();
        company.setId(createId());
        company.setName("Taobao");
        company.setDescription("China's largest online retail website and one-stop platform for shopping, socializing and information sharing");
        group.getCompanies().add(company);
    }
    {
        Company company = new Company();
        company.setId(createId());
        company.setName("Alipay");
        company.setDescription("China's leading third-party online payment platform");
        group.getCompanies().add(company);
    }
    {
        Company company = new Company();
        company.setId(createId());
        company.setName("Alibaba Cloud Computing");
        company.setDescription("Developer of advanced data-centric cloud computing services");
        group.getCompanies().add(company);
    }
    {
        Company company = new Company();
        company.setId(createId());
        company.setName("China Yahoo");
        company.setDescription("One of China's leading Internet portals");
        group.getCompanies().add(company);
    }
    String jsonString = JSON.toJSONString(group, true);
    System.out.println(jsonString);
}
Also used : Group(com.alibaba.json.test.entity.Group) Company(com.alibaba.json.test.entity.Company) Department(com.alibaba.json.test.entity.Department) Employee(com.alibaba.json.test.entity.Employee) BigDecimal(java.math.BigDecimal) Date(java.util.Date)

Example 2 with Department

use of com.alibaba.json.test.entity.Department in project fastjson by alibaba.

the class JacksonGroupParser method parseDepartment.

private Department parseDepartment() throws Exception {
    accept(JsonToken.START_OBJECT);
    Department company = new Department();
    for (; ; ) {
        JsonToken tok = parser.getCurrentToken();
        if (tok == JsonToken.END_OBJECT) {
            break;
        }
        if (tok == JsonToken.FIELD_NAME) {
            String name = parser.getCurrentName();
            tok = parser.nextToken();
            if ("name" == name) {
                company.setName(acceptString(tok));
            } else if ("description" == name) {
                company.setDescription(acceptString(tok));
            } else if ("id" == name) {
                company.setId(acceptLong(tok));
            } else if ("children" == name) {
                parseDepartment(company.getChildren());
            } else if ("members" == name) {
                parseEmployee(company.getMembers());
            } else {
                throw new RuntimeException("not match property : " + name);
            }
        }
    }
    accept(JsonToken.END_OBJECT);
    return company;
}
Also used : Department(com.alibaba.json.test.entity.Department) JsonToken(com.fasterxml.jackson.core.JsonToken)

Example 3 with Department

use of com.alibaba.json.test.entity.Department in project fastjson by alibaba.

the class ObjectEncodePerformanceTest method createObject.

private Object createObject() {
    Group group = new Group();
    group.setName("Alibaba Group");
    group.setDescription("Alibaba Group makes it easy for anyone to buy or sell online anywhere in the world. ");
    {
        Company company = new Company();
        company.setId(createId());
        company.setName("Alibaba.com");
        company.setDescription("Global leader in e-commerce for small businesses");
        company.setStock("1688.HK");
        group.getCompanies().add(company);
        Department root = new Department();
        root.setId(createId());
        root.setName("B2B");
        company.setRootDepartment(root);
        {
            Department cbu = new Department();
            cbu.setId(createId());
            cbu.setName("CBU");
            root.getChildren().add(cbu);
            Employee emp0 = new Employee();
            emp0.setName("校长");
            emp0.setDescription("神棍敌人姐");
            emp0.setAge(3);
            emp0.setSalary(new BigDecimal("123456789.0123"));
            emp0.setBirthdate(new Date());
            emp0.setBadboy(true);
            cbu.getMembers().add(emp0);
        }
        {
            Department icbu = new Department();
            icbu.setId(createId());
            icbu.setName("ICBU");
            root.getChildren().add(icbu);
        }
    }
    {
        Company company = new Company();
        company.setId(createId());
        company.setName("Taobao");
        company.setDescription("China's largest online retail website and one-stop platform for shopping, socializing and information sharing");
        group.getCompanies().add(company);
    }
    {
        Company company = new Company();
        company.setId(createId());
        company.setName("Alipay");
        company.setDescription("China's leading third-party online payment platform");
        group.getCompanies().add(company);
    }
    {
        Company company = new Company();
        company.setId(createId());
        company.setName("Alibaba Cloud Computing");
        company.setDescription("Developer of advanced data-centric cloud computing services");
        group.getCompanies().add(company);
    }
    {
        Company company = new Company();
        company.setId(createId());
        company.setName("China Yahoo");
        company.setDescription("One of China's leading Internet portals");
        group.getCompanies().add(company);
    }
    return group;
}
Also used : Group(com.alibaba.json.test.entity.Group) Company(com.alibaba.json.test.entity.Company) Department(com.alibaba.json.test.entity.Department) Employee(com.alibaba.json.test.entity.Employee) BigDecimal(java.math.BigDecimal) Date(java.util.Date)

Aggregations

Department (com.alibaba.json.test.entity.Department)3 Company (com.alibaba.json.test.entity.Company)2 Employee (com.alibaba.json.test.entity.Employee)2 Group (com.alibaba.json.test.entity.Group)2 BigDecimal (java.math.BigDecimal)2 Date (java.util.Date)2 JsonToken (com.fasterxml.jackson.core.JsonToken)1