![JAR search and dependency download from the Maven repository](/logo.png)
com.adesigns.csv.util.ObjectReader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of csv-creator Show documentation
Show all versions of csv-creator Show documentation
Dead-simple way to generate CSV output.
The newest version!
/*
* Copyright [2016] Michael Yudin
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
package com.adesigns.csv.util;
import com.adesigns.csv.annotation.CsvColumn;
import java.lang.reflect.Field;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
public class ObjectReader {
/**
* Returns a List representing a row of header columns.
*
* @param pojoClass Class we want to retrieve header columns for.
* @return List representing a row of header columns.
*/
public static List getHeaderColumns(Class> pojoClass) {
List headerColumns = new LinkedList();
for (Field field : pojoClass.getDeclaredFields()) {
if (!field.isAnnotationPresent(CsvColumn.class)) {
continue;
}
CsvColumn csvColumn = field.getAnnotation(CsvColumn.class);
headerColumns.add(csvColumn.title());
}
return headerColumns;
}
/**
* Returns a List object containing row data.
*
* @param pojo Object to convert to a row.
* @return List of column data for a row
* @throws IllegalAccessException If a field cannot be accessed via reflection
*/
public static List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy