@Override public CsvFactory copy() { return new CsvFactory(this); }
/** * Method that we need to override to actually make restoration go * through constructors etc. * Also: must be overridden by sub-classes as well. */ protected Object readResolve() { return new CsvFactory(this); }
/** * Method that we need to override to actually make restoration go * through constructors etc. * Also: must be overridden by sub-classes as well. */ @Override protected Object readResolve() { return new CsvFactory(this, _objectCodec); }
@Override public CsvFactory build() { // 28-Dec-2017, tatu: No special settings beyond base class ones, so: return new CsvFactory(this); }
public CsvMapper() { this(new CsvFactory()); }
public CsvMapper() { this(new CsvFactory()); }
public static CsvMapper.Builder builder() { return new CsvMapper.Builder(new CsvFactory()); }
public CsvMapper() { this(new Builder(new CsvFactory())); }
@Override public CsvFactory copy() { _checkInvalidCopy(CsvFactory.class); return new CsvFactory(this, null); }
result = new ObjectMapper(yamlFactory); } else if (MediaType.TEXT_CSV.isCompatible(getMediaType())) { CsvFactory csvFactory = new CsvFactory(); csvFactory.configure(Feature.AUTO_CLOSE_TARGET, false); result = new CsvMapper(csvFactory);
@Test public final void testRunSorterFirstColumn() throws Exception { CsvFactory csvFactory = new CsvFactory(); csvFactory.enable(CsvParser.Feature.TRIM_SPACES); // csvFactory.enable(CsvParser.Feature.WRAP_AS_ARRAY); csvFactory.configure(JsonParser.Feature.ALLOW_YAML_COMMENTS, true); CsvMapper mapper = new CsvMapper(csvFactory); mapper.enable(CsvParser.Feature.TRIM_SPACES); // mapper.enable(CsvParser.Feature.WRAP_AS_ARRAY); mapper.configure(JsonParser.Feature.ALLOW_YAML_COMMENTS, true); // mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, // true); CsvSchema schema = CsvSchema.builder().setUseHeader(false).build(); verifyCSV(testInput1, 1, 2, 4, mapper, schema); try (Reader inputReader = Files.newBufferedReader(testInput1, StandardCharsets.UTF_8)) { CSVSorter.runSorter(inputReader, testOutput, 1, schema, CSVSorter.getComparator(0), true); } verifyCSV(testOutput, 1, 2, 4, mapper, schema); }
@Test public final void testRunSorterSecondColumnThenFirst() throws Exception { CsvFactory csvFactory = new CsvFactory(); csvFactory.enable(CsvParser.Feature.TRIM_SPACES); // csvFactory.enable(CsvParser.Feature.WRAP_AS_ARRAY); csvFactory.configure(JsonParser.Feature.ALLOW_YAML_COMMENTS, true); CsvMapper mapper = new CsvMapper(csvFactory); mapper.enable(CsvParser.Feature.TRIM_SPACES); // mapper.enable(CsvParser.Feature.WRAP_AS_ARRAY); mapper.configure(JsonParser.Feature.ALLOW_YAML_COMMENTS, true); // mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, // true); CsvSchema schema = CsvSchema.builder().setUseHeader(false).build(); verifyCSV(testInput3, 1, 2, 5, mapper, schema); try (Reader inputReader = Files.newBufferedReader(testInput3, StandardCharsets.UTF_8)) { CSVSorter.runSorter(inputReader, testOutput, 1, schema, CSVSorter.getComparator(1, 0), true); } verifyCSV(testOutput, 1, 2, 5, mapper, schema); }
@Test public final void testRunSorterFirstColumnThenSecond() throws Exception { CsvFactory csvFactory = new CsvFactory(); csvFactory.enable(CsvParser.Feature.TRIM_SPACES); // csvFactory.enable(CsvParser.Feature.WRAP_AS_ARRAY); csvFactory.configure(JsonParser.Feature.ALLOW_YAML_COMMENTS, true); CsvMapper mapper = new CsvMapper(csvFactory); mapper.enable(CsvParser.Feature.TRIM_SPACES); // mapper.enable(CsvParser.Feature.WRAP_AS_ARRAY); mapper.configure(JsonParser.Feature.ALLOW_YAML_COMMENTS, true); // mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, // true); CsvSchema schema = CsvSchema.builder().setUseHeader(false).build(); verifyCSV(testInput3, 1, 2, 5, mapper, schema); try (Reader inputReader = Files.newBufferedReader(testInput3, StandardCharsets.UTF_8)) { CSVSorter.runSorter(inputReader, testOutput, 1, schema, CSVSorter.getComparator(0, 1), true); } verifyCSV(testOutput, 1, 2, 5, mapper, schema); }
@Test public final void testRunSorterSecondColumn() throws Exception { CsvFactory csvFactory = new CsvFactory(); csvFactory.enable(CsvParser.Feature.TRIM_SPACES); // csvFactory.enable(CsvParser.Feature.WRAP_AS_ARRAY); csvFactory.configure(JsonParser.Feature.ALLOW_YAML_COMMENTS, true); CsvMapper mapper = new CsvMapper(csvFactory); mapper.enable(CsvParser.Feature.TRIM_SPACES); // mapper.enable(CsvParser.Feature.WRAP_AS_ARRAY); mapper.configure(JsonParser.Feature.ALLOW_YAML_COMMENTS, true); // mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, // true); CsvSchema schema = CsvSchema.builder().setUseHeader(false).build(); verifyCSV(testInput1, 1, 2, 4, mapper, schema); try (Reader inputReader = Files.newBufferedReader(testInput1, StandardCharsets.UTF_8)) { CSVSorter.runSorter(inputReader, testOutput, 1, schema, CSVSorter.getComparator(1), true); } verifyCSV(testOutput, 1, 2, 4, mapper, schema); }
@Test public final void testRunSorterTSV() throws Exception { CsvFactory csvFactory = new CsvFactory(); csvFactory.enable(CsvParser.Feature.TRIM_SPACES); // csvFactory.enable(CsvParser.Feature.WRAP_AS_ARRAY); csvFactory.configure(JsonParser.Feature.ALLOW_YAML_COMMENTS, true); CsvMapper mapper = new CsvMapper(csvFactory); mapper.enable(CsvParser.Feature.TRIM_SPACES); // mapper.enable(CsvParser.Feature.WRAP_AS_ARRAY); mapper.configure(JsonParser.Feature.ALLOW_YAML_COMMENTS, true); // mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, // true); CsvSchema schema = CsvSchema.builder().setUseHeader(false).setColumnSeparator('\t').build(); verifyCSV(testInput4, 1, 2, 5, mapper, schema); try (Reader inputReader = Files.newBufferedReader(testInput4, StandardCharsets.UTF_8)) { CSVSorter.runSorter(inputReader, testOutput, 1, schema, CSVSorter.getComparator(0, 1), true); } verifyCSV(testOutput, 1, 2, 5, mapper, schema); }
@Test public final void testRunSorterTSVMultipleHeaderLines() throws Exception { CsvFactory csvFactory = new CsvFactory(); csvFactory.enable(CsvParser.Feature.TRIM_SPACES); // csvFactory.enable(CsvParser.Feature.WRAP_AS_ARRAY); csvFactory.configure(JsonParser.Feature.ALLOW_YAML_COMMENTS, true); CsvMapper mapper = new CsvMapper(csvFactory); mapper.enable(CsvParser.Feature.TRIM_SPACES); // mapper.enable(CsvParser.Feature.WRAP_AS_ARRAY); mapper.configure(JsonParser.Feature.ALLOW_YAML_COMMENTS, true); // mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, // true); CsvSchema schema = CsvSchema.builder().setUseHeader(false).setColumnSeparator('\t').build(); verifyCSV(testInput5, 10, 2, 5, mapper, schema); try (Reader inputReader = Files.newBufferedReader(testInput5, StandardCharsets.UTF_8)) { CSVSorter.runSorter(inputReader, testOutput, 10, schema, CSVSorter.getComparator(0, 1), true); } verifyCSV(testOutput, 10, 2, 5, mapper, schema); }