Package com.fasterxml.jackson.dataformat.csv

Examples of com.fasterxml.jackson.dataformat.csv.CsvSchema


    {
        System.out.print("Reading input as "+cls.getName()+" instances: ");
       
        int count = 0;
        CsvMapper mapper = new CsvMapper();
        CsvSchema schema = CsvSchema.builder()
            .setUseHeader(true)
            .build();

        MappingIterator<T> it = mapper.reader(cls)
            .with(schema).readValues(inputFile);
View Full Code Here


    @Override
    public List<ResultType> readFile(File path) throws IOException {
        if (!path.exists()) {
            return Collections.emptyList();
        }
        CsvSchema schema = mapper.schemaFor(resultType);
        try {
            MappingIterator<ResultType> iterator = mapper.reader(schema).withType(resultType)
                .readValues(path);
            return Lists.newArrayList(iterator);
        } catch (IOException e) {
View Full Code Here

        }
    }

    @Override
    public void writeFile(File path, List<ResultType> models) throws IOException {
        CsvSchema schema = mapper.schemaFor(resultType);
        System.out.println(schema.getColumnDesc());
        ObjectWriter writer = mapper.writer(schema);
        // supplying the file directly does not work.
        // java.lang.UnsupportedOperationException: Generator of type com.fasterxml.jackson.core.json.UTF8JsonGenerator
        // does not support schema of type 'CSV'
        writer.writeValue(new FileOutputStream(path), models);
View Full Code Here

import com.google.common.collect.ImmutableMap;

public class TestWriterWithSomeMoreMissingValues extends ModuleTestBase {

    public void testWithAStringAndAUuid() throws JsonProcessingException {
        final CsvSchema schema = new CsvSchema.Builder()
                .addColumn("string1", CsvSchema.ColumnType.STRING)
                .addColumn("string2", CsvSchema.ColumnType.STRING)
                .build();
        final ObjectWriter writer = new CsvMapper().writer().withSchema(schema);
View Full Code Here

        assertEquals("hello,\"2a36b911-9699-45d2-abd5-b9f2d2c9c4a3\"\n", csv);
    }

    public void testWithTwoStringsAndAUuid() throws JsonProcessingException {

        final CsvSchema schema = new CsvSchema.Builder()
                .addColumn("string1", CsvSchema.ColumnType.STRING)
                .addColumn("string2", CsvSchema.ColumnType.STRING)
                .addColumn("string3", CsvSchema.ColumnType.STRING)
                .build();
        final ObjectWriter writer = new CsvMapper().writer().withSchema(schema);
View Full Code Here

        assertEquals("hello,world,\"2a36b911-9699-45d2-abd5-b9f2d2c9c4a3\"\n", csv);
    }

    public void testWithANullAStringAndAUuid() throws JsonProcessingException {

        final CsvSchema schema = new CsvSchema.Builder()
                .addColumn("string1", CsvSchema.ColumnType.STRING)
                .addColumn("string2", CsvSchema.ColumnType.STRING)
                .addColumn("string3", CsvSchema.ColumnType.STRING)
                .build();
        final ObjectWriter writer = new CsvMapper().writer().withSchema(schema);
View Full Code Here

        assertEquals(",world,\"2a36b911-9699-45d2-abd5-b9f2d2c9c4a3\"\n", csv);
    }

    public void testWithAStringANullAndAUuid() throws JsonProcessingException {

        final CsvSchema schema = new CsvSchema.Builder()
                .addColumn("string1", CsvSchema.ColumnType.STRING)
                .addColumn("string2", CsvSchema.ColumnType.STRING)
                .addColumn("string3", CsvSchema.ColumnType.STRING)
                .build();
        final ObjectWriter writer = new CsvMapper().writer().withSchema(schema);
View Full Code Here

        assertEquals("hello,,\"2a36b911-9699-45d2-abd5-b9f2d2c9c4a3\"\n", csv);
    }

    public void testWithThreeStringsAndAUuid() throws JsonProcessingException {

        final CsvSchema schema = new CsvSchema.Builder()
                .addColumn("string1", CsvSchema.ColumnType.STRING)
                .addColumn("string2", CsvSchema.ColumnType.STRING)
                .addColumn("string3", CsvSchema.ColumnType.STRING)
                .addColumn("string4", CsvSchema.ColumnType.STRING)
                .build();
View Full Code Here

        assertEquals("hello,dear,world,\"2a36b911-9699-45d2-abd5-b9f2d2c9c4a3\"\n", csv);
    }

    public void testWithANullAStringAStringAndAUuid() throws JsonProcessingException {

        final CsvSchema schema = new CsvSchema.Builder()
                .addColumn("string1", CsvSchema.ColumnType.STRING)
                .addColumn("string2", CsvSchema.ColumnType.STRING)
                .addColumn("string3", CsvSchema.ColumnType.STRING)
                .addColumn("string4", CsvSchema.ColumnType.STRING)
                .build();
View Full Code Here

        assertEquals(",hello,world,\"2a36b911-9699-45d2-abd5-b9f2d2c9c4a3\"\n", csv);
    }

    public void testWithAStringANullAStringAndAUuid() throws JsonProcessingException {

        final CsvSchema schema = new CsvSchema.Builder()
                .addColumn("string1", CsvSchema.ColumnType.STRING)
                .addColumn("string2", CsvSchema.ColumnType.STRING)
                .addColumn("string3", CsvSchema.ColumnType.STRING)
                .addColumn("string4", CsvSchema.ColumnType.STRING)
                .build();
View Full Code Here

TOP

Related Classes of com.fasterxml.jackson.dataformat.csv.CsvSchema

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.