本文整理汇总了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));
}
示例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;
}
示例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"])
}
示例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);
}
示例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());
}