Search in sources :

Example 1 with ValueProxyMaker

use of org.nutz.ioc.ValueProxyMaker in project nutz by nutzam.

the class IocCustomizedValueTypeTest method test_simple_customized.

@Test
public void test_simple_customized() {
    String json = "{xb:{name:{cc:'XiaoBai'}}}";
    Ioc2 ioc = new NutIoc(new MapLoader(json));
    ioc.addValueProxyMaker(new ValueProxyMaker() {

        public ValueProxy make(IocMaking ing, IocValue iv) {
            if ("cc".equalsIgnoreCase(iv.getType())) {
                return new StaticValue("CC:" + iv.getValue());
            }
            return null;
        }

        public String[] supportedTypes() {
            return Lang.array("cc");
        }
    });
    Pet pet = ioc.get(Pet.class, "xb");
    assertEquals("CC:XiaoBai", pet.getName());
    ioc.depose();
}
Also used : NutIoc(org.nutz.ioc.impl.NutIoc) MapLoader(org.nutz.ioc.loader.map.MapLoader) IocMaking(org.nutz.ioc.IocMaking) ValueProxy(org.nutz.ioc.ValueProxy) ValueProxyMaker(org.nutz.ioc.ValueProxyMaker) IocValue(org.nutz.ioc.meta.IocValue) Ioc2(org.nutz.ioc.Ioc2) Pet(org.nutz.dao.test.meta.Pet) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 Pet (org.nutz.dao.test.meta.Pet)1 Ioc2 (org.nutz.ioc.Ioc2)1 IocMaking (org.nutz.ioc.IocMaking)1 ValueProxy (org.nutz.ioc.ValueProxy)1 ValueProxyMaker (org.nutz.ioc.ValueProxyMaker)1 NutIoc (org.nutz.ioc.impl.NutIoc)1 MapLoader (org.nutz.ioc.loader.map.MapLoader)1 IocValue (org.nutz.ioc.meta.IocValue)1