/** * Similar to {@link #putAt(String,Object) putAt(String,Object)}, but used to append to collections and arrays. * * <p> * For example, the following code is equivalent: * </p> * <p class='bcode w800'> * ObjectMap m = getObjectMap(); * * <jc>// Long way</jc> * m.getObjectMap(<js>"foo"</js>).getObjectList(<js>"bar"</js>).append(123); * * <jc>// Using this method</jc> * m.postAt(<js>"foo/bar"</js>, 123); * </p> * * <p> * This method uses the {@link PojoRest} class to perform the lookup, so the map can contain any of the various * class types that the {@link PojoRest} class supports (e.g. beans, collections, arrays). * * @param path The path to the entry. * @param o The new value. * @return The previous value, or <jk>null</jk> if the entry doesn't exist. */ public Object postAt(String path, Object o) { return getPojoRest().post(path, o); }
/** * Similar to {@link #putAt(String,Object) putAt(String,Object)}, but used to append to collections and arrays. * * <p> * For example, the following code is equivalent: * </p> * <p class='bcode w800'> * ObjectMap m = getObjectMap(); * * <jc>// Long way</jc> * m.getObjectMap(<js>"foo"</js>).getObjectList(<js>"bar"</js>).append(123); * * <jc>// Using this method</jc> * m.postAt(<js>"foo/bar"</js>, 123); * </p> * * <p> * This method uses the {@link PojoRest} class to perform the lookup, so the map can contain any of the various * class types that the {@link PojoRest} class supports (e.g. beans, collections, arrays). * * @param path The path to the entry. * @param o The new value. * @return The previous value, or <jk>null</jk> if the entry doesn't exist. */ public Object postAt(String path, Object o) { return getPojoRest().post(path, o); }
/** * Similar to {@link #putAt(String,Object) putAt(String,Object)}, but used to append to collections and arrays. * * <p> * For example, the following code is equivalent: * </p> * <p class='bcode w800'> * ObjectMap m = getObjectMap(); * * <jc>// Long way</jc> * m.getObjectMap(<js>"foo"</js>).getObjectList(<js>"bar"</js>).append(123); * * <jc>// Using this method</jc> * m.postAt(<js>"foo/bar"</js>, 123); * </p> * * <p> * This method uses the {@link PojoRest} class to perform the lookup, so the map can contain any of the various * class types that the {@link PojoRest} class supports (e.g. beans, collections, arrays). * * @param path The path to the entry. * @param o The new value. * @return The previous value, or <jk>null</jk> if the entry doesn't exist. */ public Object postAt(String path, Object o) { return getPojoRest().post(path, o); }
/** * Similar to {@link #putAt(String,Object) putAt(String,Object)}, but used to append to collections and arrays. * * <p> * For example, the following code is equivalent: * </p> * <p class='bcode w800'> * ObjectMap m = getObjectMap(); * * <jc>// Long way</jc> * m.getObjectMap(<js>"foo"</js>).getObjectList(<js>"bar"</js>).append(123); * * <jc>// Using this method</jc> * m.postAt(<js>"foo/bar"</js>, 123); * </p> * * <p> * This method uses the {@link PojoRest} class to perform the lookup, so the map can contain any of the various * class types that the {@link PojoRest} class supports (e.g. beans, collections, arrays). * * @param path The path to the entry. * @param o The new value. * @return The previous value, or <jk>null</jk> if the entry doesn't exist. */ public Object postAt(String path, Object o) { return getPojoRest().post(path, o); }
/** * Similar to {@link #putAt(String,Object) putAt(String,Object)}, but used to append to collections and arrays. * * <p> * For example, the following code is equivalent: * </p> * <p class='bcode w800'> * ObjectMap m = getObjectMap(); * * <jc>// Long way</jc> * m.getObjectMap(<js>"foo"</js>).getObjectList(<js>"bar"</js>).append(123); * * <jc>// Using this method</jc> * m.postAt(<js>"foo/bar"</js>, 123); * </p> * * <p> * This method uses the {@link PojoRest} class to perform the lookup, so the map can contain any of the various * class types that the {@link PojoRest} class supports (e.g. beans, collections, arrays). * * @param path The path to the entry. * @param o The new value. * @return The previous value, or <jk>null</jk> if the entry doesn't exist. */ public Object postAt(String path, Object o) { return getPojoRest().post(path, o); }
/** * Similar to {@link #putAt(String,Object) putAt(String,Object)}, but used to append to collections and arrays. * * <p> * For example, the following code is equivalent: * </p> * <p class='bcode w800'> * ObjectMap m = getObjectMap(); * * <jc>// Long way</jc> * m.getObjectMap(<js>"foo"</js>).getObjectList(<js>"bar"</js>).append(123); * * <jc>// Using this method</jc> * m.postAt(<js>"foo/bar"</js>, 123); * </p> * * <p> * This method uses the {@link PojoRest} class to perform the lookup, so the map can contain any of the various * class types that the {@link PojoRest} class supports (e.g. beans, collections, arrays). * * @param path The path to the entry. * @param o The new value. * @return The previous value, or <jk>null</jk> if the entry doesn't exist. */ public Object postAt(String path, Object o) { return getPojoRest().post(path, o); }
@Test public void testConstructors() throws Exception { PojoRest model = new PojoRest(new AddressBook(), JsonParser.DEFAULT); // Try adding a person to the address book. Person billClinton = new Person("Bill Clinton", 65, new Address("55W. 125th Street", "New York", "NY", 10027, true) ); model.post("/", billClinton); // Make sure we get the original person back. billClinton = (Person)model.get("/0"); }
@Test public void testBasic() { // TODO: Need to write some exhaustive tests here. Will open work item // to do that later. PojoRest model = new PojoRest(new ObjectMap()); // An empty model. // Do a PUT model.put("A", new ObjectMap()); model.put("A/B", new ObjectMap()); model.put("A/B/C", "A new string"); assertEquals("{A:{B:{C:'A new string'}}}", model.toString()); // Do a POST to a list. model.put("A/B/C", new LinkedList()); model.post("A/B/C", "String #1"); model.post("A/B/C", "String #2"); assertEquals("{A:{B:{C:['String #1\','String #2']}}}", model.toString()); // Do some GETs String s = (String) model.get("A/B/C/0"); assertEquals("String #1", s); Map m = (Map) model.get("A/B"); assertEquals("{C:['String #1','String #2']}", m.toString()); }
@Test public void testAddressBook() { PojoRest model; model = new PojoRest(new AddressBook()); // Try adding a person to the address book. Person billClinton = new Person("Bill Clinton", 65, new Address("55W. 125th Street", "New York", "NY", 10027, true) ); model.post("/", billClinton); // Make sure we get the original person back. billClinton = (Person)model.get("/0"); }
model.post("addresses", new Address("street C", "city C", "state C", 12345, true)); s = ((Address)model.get("addresses/2")).toString(); expectedValue = "Address(street=street C,city=city C,state=state C,zip=12345,isCurrent=true)"; model.post("", new Integer(1)); model.post("/", new Integer(2)); s = model.get("").toString(); assertEquals("[1,2]", s);