public static <T> T createFromJsonMapResource(Class<T> type, String resource) { Map<String,Object> config = null; JsonParserAndMapper laxParser = new JsonParserFactory().createLaxParser(); if (resource.endsWith( ".json" )) { config = laxParser.parseMap( IO.read(resource) ); } else if (resource.endsWith( "/" )) { config = new LinkedHashMap<>( ); handleDir( config, laxParser, resource ); } return Creator.create( type, config ); }
@Test public void testCreateWithInstance7() { Foo foo = createFromJsonMapResource( fooType, "classpath://config/config.json" ); boolean ok = foo != null || die(); ok = foo.bar != null || die(); ok = foo.bar.name.equals( "barFromJsonResource" ) || die(); }
@Test public void testCreateWithInstance5() { Foo foo = createFromJsonMap( fooType, "{'bar':{'class':'org.boon.di.CreatorTest$Bar', 'name': 'barFromJson'}}" ); boolean ok = foo != null || die(); ok = foo.bar != null || die(); ok = foo.bar.name.equals( "barFromJson" ) || die(); }
@Test public void testCreateWithInstance8() { Foo foo = createFromJsonMapResource( fooType, "classpath://config/" ); boolean ok = foo != null || die(); ok = foo.bar != null || die(); ok = foo.bar.name.equals( "barFromJsonResource" ) || die(); }
public static <T> T createFromJsonMapResource(Class<T> type, String resource) { Map<String,Object> config = null; JsonParserAndMapper laxParser = new JsonParserFactory().createLaxParser(); if (resource.endsWith( ".json" )) { config = laxParser.parseMap( IO.read(resource) ); } else if (resource.endsWith( "/" )) { config = new LinkedHashMap<>( ); handleDir( config, laxParser, resource ); } return Creator.create( type, config ); }
public static <T> T createFromJsonMapResource(Class<T> type, String resource) { Map<String,Object> config = null; JsonParserAndMapper laxParser = new JsonParserFactory().createLaxParser(); if (resource.endsWith( ".json" )) { config = laxParser.parseMap( IO.read(resource) ); } else if (resource.endsWith( "/" )) { config = new LinkedHashMap<>( ); handleDir( config, laxParser, resource ); } return Creator.create( type, config ); }