当前位置: 首页>>代码示例>>Java>>正文


Java InstanceCreator类代码示例

本文整理汇总了Java中com.google.gson.InstanceCreator的典型用法代码示例。如果您正苦于以下问题:Java InstanceCreator类的具体用法?Java InstanceCreator怎么用?Java InstanceCreator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


InstanceCreator类属于com.google.gson包,在下文中一共展示了InstanceCreator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getConstructor

import com.google.gson.InstanceCreator; //导入依赖的package包/类
public <T> ObjectConstructor<T> getConstructor(TypeToken<T> typeToken) {
    final Type type = typeToken.getType();
    Class<? super T> rawType = typeToken.getRawType();
    final InstanceCreator<T> creator = (InstanceCreator) this.instanceCreators.get(type);
    if (creator != null) {
        return new ObjectConstructor<T>() {
            public T construct() {
                return creator.createInstance(type);
            }
        };
    }
    ObjectConstructor<T> defaultConstructor = newDefaultConstructor(rawType);
    if (defaultConstructor != null) {
        return defaultConstructor;
    }
    ObjectConstructor<T> defaultImplementation = newDefaultImplementationConstructor(rawType);
    if (defaultImplementation != null) {
        return defaultImplementation;
    }
    return newUnsafeAllocator(type, rawType);
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:22,代码来源:ConstructorConstructor.java

示例2: testDeserializeAnyBeanWithCreateInstance

import com.google.gson.InstanceCreator; //导入依赖的package包/类
@Test
public void testDeserializeAnyBeanWithCreateInstance() {
	AnyBean expected = new AnyBean("Any Name", 35);
	expected.setType("Java");
	
	String json = oson.serialize(expected);
	String jsonExpected = "{\"name\":\"Any Name\",\"age\":35,\"type\":\"Java\"}";
	
	assertEquals(jsonExpected, json);
	
	AnyBean result = oson.setClassMappers(AnyBean.class, new ClassMapper()
	.setConstructor(new InstanceCreator(){
		@Override
		public Object createInstance(Type type) {
			return new AnyBean(null, 0);
		}
		
	})).deserialize(json, AnyBean.class);

	assertEquals(expected.toString(), result.toString());
}
 
开发者ID:osonus,项目名称:oson,代码行数:22,代码来源:NewInstanceTest.java

示例3: loadResultsFromFile

import com.google.gson.InstanceCreator; //导入依赖的package包/类
private DriftResults loadResultsFromFile(String path) throws IOException {
    BufferedReader reader = null;
    try {
        reader = new BufferedReader(new FileReader(path));

        Gson gson = new GsonBuilder().setPrettyPrinting().registerTypeAdapter(
                UnivariateFunction.class,
                new InstanceCreator<PolynomialSplineFunction>() {
                    @Override
                    public PolynomialSplineFunction createInstance(Type type) {
                        return new PolynomialSplineFunction(new double[]{1, 2}, new PolynomialFunction[]{new PolynomialFunction(new double[1])});
                    }
                }).create();
        return gson.fromJson(reader, DriftResults.class);
    } finally {
        if(reader != null) {
            reader.close();
        }
    }
}
 
开发者ID:zitmen,项目名称:thunderstorm,代码行数:21,代码来源:ResultsDriftCorrection.java

示例4: testInstanceCreatorReturnsSubTypeForTopLevelObject_add1163

import com.google.gson.InstanceCreator; //导入依赖的package包/类
@Test(timeout = 1000)
public void testInstanceCreatorReturnsSubTypeForTopLevelObject_add1163() {
    fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),this, "testInstanceCreatorReturnsSubTypeForTopLevelObject_add1163");
    Gson gson = new GsonBuilder().registerTypeAdapter(TestTypes.Base.class, new InstanceCreator<com.google.gson.common.TestTypes.Base>() {
        public TestTypes.Base createInstance(Type type) {
            return new TestTypes.Sub();
        }
    }).create();
    String json = "{baseName:\'Base\',subName:\'SubRevised\'}";
    TestTypes.Base base = gson.fromJson(json, TestTypes.Base.class);
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),1647,(base instanceof com.google.gson.common.TestTypes.Sub));
    TestTypes.Sub sub = ((TestTypes.Sub)(base));
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),1649,"SubRevised",1648,"SubRevised".equals(sub.subName));
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),1650,com.google.gson.common.TestTypes.Sub.SUB_NAME);
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),1651,sub.subName);
    fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread());
}
 
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:18,代码来源:InstanceCreatorTest.java

示例5: testInstanceCreatorReturnsSubTypeForTopLevelObject

import com.google.gson.InstanceCreator; //导入依赖的package包/类
public void testInstanceCreatorReturnsSubTypeForTopLevelObject() {
    fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),this, "testInstanceCreatorReturnsSubTypeForTopLevelObject");
    Gson gson = new GsonBuilder().registerTypeAdapter(TestTypes.Base.class, new InstanceCreator<com.google.gson.common.TestTypes.Base>() {
        public TestTypes.Base createInstance(Type type) {
            return new TestTypes.Sub();
        }
    }).create();
    String json = "foo";
    TestTypes.Base base = gson.fromJson(json, TestTypes.Base.class);
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),1647,(base instanceof com.google.gson.common.TestTypes.Sub));
    TestTypes.Sub sub = ((TestTypes.Sub)(base));
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),1649,"SubRevised",1648,"SubRevised".equals(sub.subName));
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),1650,com.google.gson.common.TestTypes.Sub.SUB_NAME);
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),1651,sub.subName);
    fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread());
}
 
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:17,代码来源:InstanceCreatorTest.java

示例6: testInstanceCreatorReturnsSubTypeForTopLevelObject_remove980

import com.google.gson.InstanceCreator; //导入依赖的package包/类
@Test(timeout = 1000)
public void testInstanceCreatorReturnsSubTypeForTopLevelObject_remove980() {
    fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),this, "testInstanceCreatorReturnsSubTypeForTopLevelObject_remove980");
    Gson gson = new GsonBuilder().registerTypeAdapter(TestTypes.Base.class, new InstanceCreator<com.google.gson.common.TestTypes.Base>() {
        public TestTypes.Base createInstance(Type type) {
            return new TestTypes.Sub();
        }
    }).create();
    String json = "{baseName:\'Base\',subName:\'SubRevised\'}";
    TestTypes.Base base = gson.fromJson(json, TestTypes.Base.class);
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),1647,(base instanceof com.google.gson.common.TestTypes.Sub));
    TestTypes.Sub sub = ((TestTypes.Sub)(base));
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),1649,"SubRevised",1648,"SubRevised".equals(sub.subName));
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),1650,com.google.gson.common.TestTypes.Sub.SUB_NAME);
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),1651,sub.subName);
    fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread());
}
 
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:18,代码来源:InstanceCreatorTest.java

示例7: testInstanceCreatorForCollectionType_add1155

import com.google.gson.InstanceCreator; //导入依赖的package包/类
@Test(timeout = 1000)
public void testInstanceCreatorForCollectionType_add1155() {
    fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),this, "testInstanceCreatorForCollectionType_add1155");
    @SuppressWarnings(value = "serial")
    class SubArrayList<T> extends ArrayList<T> {        }
    InstanceCreator<java.util.List<java.lang.String>> listCreator = new InstanceCreator<java.util.List<java.lang.String>>() {
        public List<java.lang.String> createInstance(Type type) {
            return new SubArrayList<java.lang.String>();
        }
    };
    Type listOfStringType = new TypeToken<java.util.List<java.lang.String>>() {        }.getType();
    Gson gson = new GsonBuilder().registerTypeAdapter(listOfStringType, listCreator).create();
    List<java.lang.String> list = gson.fromJson("[\"a\"]", listOfStringType);
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),1631,SubArrayList.class);
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),1633,list,1632,list.getClass());
    fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread());
}
 
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:18,代码来源:InstanceCreatorTest.java

示例8: testInstanceCreatorForCollectionType_add1156

import com.google.gson.InstanceCreator; //导入依赖的package包/类
@Test(timeout = 1000)
public void testInstanceCreatorForCollectionType_add1156() {
    fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),this, "testInstanceCreatorForCollectionType_add1156");
    @SuppressWarnings(value = "serial")
    class SubArrayList<T> extends ArrayList<T> {        }
    InstanceCreator<java.util.List<java.lang.String>> listCreator = new InstanceCreator<java.util.List<java.lang.String>>() {
        public List<java.lang.String> createInstance(Type type) {
            return new SubArrayList<java.lang.String>();
        }
    };
    Type listOfStringType = new TypeToken<java.util.List<java.lang.String>>() {        }.getType();
    Gson gson = new GsonBuilder().registerTypeAdapter(listOfStringType, listCreator).create();
    List<java.lang.String> list = gson.fromJson("[\"a\"]", listOfStringType);
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),1631,SubArrayList.class);
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),1633,list,1632,list.getClass());
    fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread());
}
 
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:18,代码来源:InstanceCreatorTest.java

示例9: testInstanceCreatorForCollectionType_add1157

import com.google.gson.InstanceCreator; //导入依赖的package包/类
@Test(timeout = 1000)
public void testInstanceCreatorForCollectionType_add1157() {
    fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),this, "testInstanceCreatorForCollectionType_add1157");
    @SuppressWarnings(value = "serial")
    class SubArrayList<T> extends ArrayList<T> {        }
    InstanceCreator<java.util.List<java.lang.String>> listCreator = new InstanceCreator<java.util.List<java.lang.String>>() {
        public List<java.lang.String> createInstance(Type type) {
            return new SubArrayList<java.lang.String>();
        }
    };
    Type listOfStringType = new TypeToken<java.util.List<java.lang.String>>() {        }.getType();
    Gson gson = new GsonBuilder().registerTypeAdapter(listOfStringType, listCreator).create();
    List<java.lang.String> list = gson.fromJson("[\"a\"]", listOfStringType);
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),1631,SubArrayList.class);
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),1633,list,1632,list.getClass());
    fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread());
}
 
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:18,代码来源:InstanceCreatorTest.java

示例10: testInstanceCreatorForCollectionType

import com.google.gson.InstanceCreator; //导入依赖的package包/类
public void testInstanceCreatorForCollectionType() {
    fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),this, "testInstanceCreatorForCollectionType");
    @SuppressWarnings(value = "serial")
    class SubArrayList<T> extends ArrayList<T> {        }
    InstanceCreator<java.util.List<java.lang.String>> listCreator = new InstanceCreator<java.util.List<java.lang.String>>() {
        public List<java.lang.String> createInstance(Type type) {
            return new SubArrayList<java.lang.String>();
        }
    };
    Type listOfStringType = new TypeToken<java.util.List<java.lang.String>>() {        }.getType();
    Gson gson = new GsonBuilder().registerTypeAdapter(listOfStringType, listCreator).create();
    List<java.lang.String> list = gson.fromJson("[\"a\"]", listOfStringType);
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),1631,SubArrayList.class);
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),1633,list,1632,list.getClass());
    fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread());
}
 
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:17,代码来源:InstanceCreatorTest.java

示例11: testInstanceCreatorForCollectionType_literalMutation1301

import com.google.gson.InstanceCreator; //导入依赖的package包/类
public void testInstanceCreatorForCollectionType_literalMutation1301() {
    fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),this, "testInstanceCreatorForCollectionType_literalMutation1301");
    @SuppressWarnings(value = "serial")
    class SubArrayList<T> extends ArrayList<T> {        }
    InstanceCreator<java.util.List<java.lang.String>> listCreator = new InstanceCreator<java.util.List<java.lang.String>>() {
        public List<java.lang.String> createInstance(Type type) {
            return new SubArrayList<java.lang.String>();
        }
    };
    Type listOfStringType = new TypeToken<java.util.List<java.lang.String>>() {        }.getType();
    Gson gson = new GsonBuilder().registerTypeAdapter(listOfStringType, listCreator).create();
    List<java.lang.String> list = gson.fromJson("foo", listOfStringType);
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),1631,SubArrayList.class);
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),1633,list,1632,list.getClass());
    fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread());
}
 
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:17,代码来源:InstanceCreatorTest.java

示例12: testInstanceCreatorForCollectionType_remove972

import com.google.gson.InstanceCreator; //导入依赖的package包/类
@Test(timeout = 1000)
public void testInstanceCreatorForCollectionType_remove972() {
    fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),this, "testInstanceCreatorForCollectionType_remove972");
    @SuppressWarnings(value = "serial")
    class SubArrayList<T> extends ArrayList<T> {        }
    InstanceCreator<java.util.List<java.lang.String>> listCreator = new InstanceCreator<java.util.List<java.lang.String>>() {
        public List<java.lang.String> createInstance(Type type) {
            return new SubArrayList<java.lang.String>();
        }
    };
    Type listOfStringType = new TypeToken<java.util.List<java.lang.String>>() {        }.getType();
    Gson gson = new GsonBuilder().registerTypeAdapter(listOfStringType, listCreator).create();
    List<java.lang.String> list = gson.fromJson("[\"a\"]", listOfStringType);
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),1631,SubArrayList.class);
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),1633,list,1632,list.getClass());
    fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread());
}
 
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:18,代码来源:InstanceCreatorTest.java

示例13: testInstanceCreatorForCollectionType_remove973

import com.google.gson.InstanceCreator; //导入依赖的package包/类
@Test(timeout = 1000)
public void testInstanceCreatorForCollectionType_remove973() {
    fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),this, "testInstanceCreatorForCollectionType_remove973");
    @SuppressWarnings(value = "serial")
    class SubArrayList<T> extends ArrayList<T> {        }
    InstanceCreator<java.util.List<java.lang.String>> listCreator = new InstanceCreator<java.util.List<java.lang.String>>() {
        public List<java.lang.String> createInstance(Type type) {
            return new SubArrayList<java.lang.String>();
        }
    };
    Type listOfStringType = new TypeToken<java.util.List<java.lang.String>>() {        }.getType();
    Gson gson = new GsonBuilder().registerTypeAdapter(listOfStringType, listCreator).create();
    List<java.lang.String> list = gson.fromJson("[\"a\"]", listOfStringType);
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),1631,SubArrayList.class);
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),1633,list,1632,list.getClass());
    fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread());
}
 
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:18,代码来源:InstanceCreatorTest.java

示例14: testInstanceCreatorForCollectionType_remove974

import com.google.gson.InstanceCreator; //导入依赖的package包/类
@Test(timeout = 1000)
public void testInstanceCreatorForCollectionType_remove974() {
    fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),this, "testInstanceCreatorForCollectionType_remove974");
    @SuppressWarnings(value = "serial")
    class SubArrayList<T> extends ArrayList<T> {        }
    InstanceCreator<java.util.List<java.lang.String>> listCreator = new InstanceCreator<java.util.List<java.lang.String>>() {
        public List<java.lang.String> createInstance(Type type) {
            return new SubArrayList<java.lang.String>();
        }
    };
    Type listOfStringType = new TypeToken<java.util.List<java.lang.String>>() {        }.getType();
    Gson gson = new GsonBuilder().registerTypeAdapter(listOfStringType, listCreator).create();
    List<java.lang.String> list = gson.fromJson("[\"a\"]", listOfStringType);
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),1631,SubArrayList.class);
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),1633,list,1632,list.getClass());
    fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread());
}
 
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:18,代码来源:InstanceCreatorTest.java

示例15: testInstanceCreatorForParametrizedType_add1158

import com.google.gson.InstanceCreator; //导入依赖的package包/类
@SuppressWarnings(value = { "unchecked" , "rawtypes" })
@Test(timeout = 1000)
public void testInstanceCreatorForParametrizedType_add1158() throws Exception {
    fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),this, "testInstanceCreatorForParametrizedType_add1158");
    @SuppressWarnings(value = "serial")
    class SubTreeSet<T> extends TreeSet<T> {        }
    InstanceCreator<java.util.SortedSet> sortedSetCreator = new InstanceCreator<java.util.SortedSet>() {
        public SortedSet createInstance(Type type) {
            return new SubTreeSet();
        }
    };
    Gson gson = new GsonBuilder().registerTypeAdapter(SortedSet.class, sortedSetCreator).create();
    Type sortedSetType = new TypeToken<java.util.SortedSet<java.lang.String>>() {        }.getType();
    SortedSet<java.lang.String> set = gson.fromJson("[\"a\"]", sortedSetType);
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),1635,set,1634,set.first());
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),1636,SubTreeSet.class);
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),1638,set,1637,set.getClass());
    set = gson.fromJson("[\"b\"]", SortedSet.class);
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),1640,set,1639,set.first());
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),1641,SubTreeSet.class);
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),1643,set,1642,set.getClass());
    fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread());
}
 
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:24,代码来源:InstanceCreatorTest.java


注:本文中的com.google.gson.InstanceCreator类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。