1 package org.opensrf.test;
4 import org.opensrf.util.*;
7 public class TestJSON {
9 public static void main(String args[]) throws Exception {
11 Map<String,Object> map = new HashMap<String,Object>();
12 map.put("key1", "value1");
13 map.put("key2", "value2");
14 map.put("key3", "value3");
15 map.put("key4", "athe\u0301s");
16 map.put("key5", null);
18 List<Object> list = new ArrayList<Object>(16);
19 list.add(new Integer(1));
20 list.add(new Boolean(true));
23 map.put("key6", list);
25 System.out.println(new JSONWriter(map).write() + "\n");
27 String[] fields = {"isnew", "name", "shortname", "ill_address"};
28 OSRFRegistry.registerObject("aou", OSRFRegistry.WireProtocol.ARRAY, fields);
30 OSRFObject obj = new OSRFObject(OSRFRegistry.getRegistry("aou"));
31 obj.put("name", "athens clarke county");
32 obj.put("ill_address", new Integer(1));
33 obj.put("shortname", "ARL-ATH");
37 System.out.println(new JSONWriter(map).write() + "\n");
40 Message m = new Message(1, Message.REQUEST);
41 Method method = new Method("opensrf.settings.host_config.get");
42 method.addParam("app07.dev.gapines.org");
45 String s = new JSONWriter(m).write();
46 System.out.println(s + "\n");
48 Object o = new JSONReader(s).read();
49 System.out.println("Read+Wrote: " + new JSONWriter(o).write());