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


Java CsvMapper.schemaFor方法代码示例

本文整理汇总了Java中com.fasterxml.jackson.dataformat.csv.CsvMapper.schemaFor方法的典型用法代码示例。如果您正苦于以下问题:Java CsvMapper.schemaFor方法的具体用法?Java CsvMapper.schemaFor怎么用?Java CsvMapper.schemaFor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.fasterxml.jackson.dataformat.csv.CsvMapper的用法示例。


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

示例1: setUp

import com.fasterxml.jackson.dataformat.csv.CsvMapper; //导入方法依赖的package包/类
@Setup(Level.Iteration)
public void setUp() {
    dsl = CsvWriter.from(SmallBenchmarkObject.class).skipHeaders();
    sbo = new SmallBenchmarkObject();
    sbo.setId(2);
    sbo.setEmail("[email protected]");
    sbo.setName("name");
    sbo.setYearStarted(222);

    CsvMapper mapper = new CsvMapper();
    CsvSchema schema = mapper.schemaFor(SmallBenchmarkObject.class);


    myObjectWriter = mapper.writer(schema);

    settings = new CsvWriterSettings();
    settings.setHeaders("id", "year_started", "name", "email");
    settings.setRowWriterProcessor(new BeanWriterProcessor<SmallBenchmarkObject>(SmallBenchmarkObject.class));

}
 
开发者ID:arnaudroger,项目名称:orm-benchmark,代码行数:21,代码来源:CsvWriterTest.java

示例2: fromCsv

import com.fasterxml.jackson.dataformat.csv.CsvMapper; //导入方法依赖的package包/类
private List<BinaryLabeledContributionInterchange> fromCsv(String inputFileName) throws IOException{
	List<BinaryLabeledContributionInterchange> itemList = new ArrayList<>();
	try(InputStream in = new FileInputStream(inputFileName);) {
		CsvMapper mapper = new CsvMapper();
		CsvSchema schema = mapper.schemaFor(BinaryLabeledContributionInterchange.class);
		MappingIterator<BinaryLabeledContributionInterchange> it = mapper.readerFor(BinaryLabeledContributionInterchange.class).with(schema).readValues(in);
		while (it.hasNextValue()) {
			itemList.add(it.next());
		}
	}			
	return itemList;
}
 
开发者ID:DiscourseDB,项目名称:discoursedb-core,代码行数:13,代码来源:ContributionBinaryLabelImporter.java

示例3: main

import com.fasterxml.jackson.dataformat.csv.CsvMapper; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
    CostDetail costDetail = new CostDetail();
    costDetail.setAmount(BigDecimal.valueOf(12.55D));
    costDetail.setApplyId(11L);
    costDetail.setCostCenterId(66L);
    costDetail.setCreatedTime(new Date());
    costDetail.setStatus(1L);
    costDetail.setTypeId(77L);
    costDetail.setTypeName("v");
    costDetail.setUserId(88L);
    CsvMapper csvMapper = new CsvMapper();
    CsvSchema csvSchema = csvMapper.schemaFor(CostDetail.class);
    String writeValueAsString = csvMapper.writer(csvSchema).writeValueAsString(costDetail);
    System.out.println(writeValueAsString);// 12.55,11,66,1456645956239,1,77,v,88

    CostDetail readValue = csvMapper.readerFor(CostDetail.class).with(csvSchema).readValue(writeValueAsString);
    System.out.println(readValue);// {"applyId":11,"typeId":77,"typeName":"v","status":1,"amount":12.55,"createdTime":"Feb 28, 2016 3:52:36 PM","userId":88,"costCenterId":66}

    Test test = new Test();

    test.setName("doctor");
    Map<String, String> map = new HashMap<>();
    map.put("age", "16");
    map.put("ke", "vv");

    test.setMap(map);
    CsvSchema testSh = csvMapper.schemaFor(Test.class);
    String writeValueAsString2 = csvMapper.writer(testSh).writeValueAsString(test);
    System.out.println(writeValueAsString2);
    // Exception in thread "main" com.fasterxml.jackson.databind.JsonMappingException: CSV generator does not support Object values for properties (through reference chain: com.doctor.jackson.Test["map"])

}
 
开发者ID:sdcuike,项目名称:book-reading,代码行数:33,代码来源:JacksonDataformatCsv.java

示例4: csvSchema

import com.fasterxml.jackson.dataformat.csv.CsvMapper; //导入方法依赖的package包/类
public static CsvSchema csvSchema() {
    CsvMapper csvMapper = new CsvMapper();
    csvMapper.disable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY);
    return csvMapper.schemaFor(Entry.class);
}
 
开发者ID:openregister,项目名称:openregister-java,代码行数:6,代码来源:Entry.java

示例5: createCsvSchema

import com.fasterxml.jackson.dataformat.csv.CsvMapper; //导入方法依赖的package包/类
/**
 * Creates a Jackson CSV schema based on a mapper and the current object
 * class.
 * 
 * @param csvMapper
 *            The source CSV mapper.
 * @return A Jackson CSV schema
 */
protected CsvSchema createCsvSchema(CsvMapper csvMapper) {
    return csvMapper.schemaFor(getObjectClass());
}
 
开发者ID:restlet,项目名称:restlet-framework,代码行数:12,代码来源:JacksonRepresentation.java


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