All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.coder.struts.view.JSONMap Maven / Gradle / Ivy

There is a newer version: 1.0.0
Show newest version
package cn.coder.struts.view;

import java.util.HashMap;
import java.util.Map;

import cn.coder.struts.wrapper.JSONWrapper;

public final class JSONMap {

	private final HashMap data = new HashMap<>();
	private final JSONWrapper wrapper = new JSONWrapper();
	
	public static JSONMap success() {
		return new JSONMap().put("success", true).put("errcode", 0).put("errmsg", "ok");
	}
	
	public static JSONMap error(int errcode, String errmsg) {
		return new JSONMap().put("success", false).put("errcode", errcode).put("errmsg", errmsg);
	}

	public JSONMap put(String name, Object value) {
		this.data.put(name, value);
		return this;
	}

	public JSONMap putAll(Map values) {
		this.data.putAll(values);
		return this;
	}

	public void clear() {
		this.data.clear();
	}

	@Override
	public String toString() {
		return wrapper.write(data);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy