com.eshore.tools.TestJsonEncode Maven / Gradle / Ivy
package com.eshore.tools;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.eshore.uas.extensions.IPropertiesEncoder;
import com.eshore.uas.extensions.option.DefaultProperisEncoder;
import com.eshore.uas.extensions.option.PropertiesEncoder;
import com.eshore.uas.system.option.Vcckey;
public class TestJsonEncode {
public static void main(String[] args) {
IPropertiesEncoder dpe = new IPropertiesEncoder() {
@Override
public String encode(String key, String value) {
if(accept(key))
return "#"+value;
return value;
}
@Override
public boolean accept(String key) {
return "cccc".equals(key)||"ddd".equals(key)||"test1".equals(key);
}};
dpe=new PropertiesEncoder(new Vcckey().getkey("abcd") );
Map map = new HashMap();
map.put("test","aaaa");
map.put("name","aaaa");
map.put("cellphone", "13777777777");
map.put("id","bbb");
map.put("roles", new String [] {"aaa","ccc","bbb"});
List list =new ArrayList();
map.put("ddd", list);
list.add("1");
list.add("2");
list.add("3");
String str = Json2StringEncoder.asJsonString(map, dpe, "test");
System.out.println(str);
}
}