package com.izouma.jiashanxia.utils;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class JsonUtils {
    public static class Builder {
        private Map<String, Object> map = new HashMap<>();

        public String build() {
            return new JSONObject(map).toJSONString();
        }

        public Builder add(String key, Object value) {
            map.put(key, value);
            return this;
        }
    }

    public static class ArrayBuilder {
        private List<Object> list = new ArrayList<>();

        public String build() {
            return new JSONArray(list).toString();
        }

        public ArrayBuilder add(Object object) {
            list.add(object);
            return this;
        }
    }
}
