This repository contains the solution for the "Back End in Java for Information Processing" challenge. The goal of this project is to create a Java application that automates the process of reading scientific production data from JSON files and consolidating it into a single CSV report.
This project was developed as part of Sprint 2.
/src/main/java/
: Contains the main source code of the application.Publication.java
: POJO class representing a single data record.JsonReader.java
: Class responsible for reading and parsing JSON files.CsvWriter.java
: Class responsible for writing data to a CSV file.App.java
: The main entry point of the application that orchestrates the workflow.
/src/test/java/
: Contains unit tests for the application.pom.xml
: The Maven project configuration file, including all dependencies./data/
: Contains sample input JSON files./output/
: The default directory where the generated CSV report is saved.
- Java Development Kit (JDK) 11 or higher.
- Apache Maven.
- An IDE like IntelliJ IDEA or VS Code (recommended).
-
Clone the repository:
git clone https://github.com/carlop13/json-csv-processor.git cd json-csv-processor
-
Build the project with Maven: This will download all necessary dependencies.
mvn clean install
-
Run the application from your IDE:
- Open the project in IntelliJ IDEA.
- Navigate to the
src/main/java/com/org.example.processor/processor/App.java
file. - Right-click on the file and select "Run 'Main.main()'".
-
Verify the output:
- After running, a new file named
report.csv
will be created in theoutput/
directory. You can open this file with any spreadsheet program to see the result.
- After running, a new file named
This section describes the internal logic for converting JSON data to CSV, addressing the feedback on algorithm design.
-
Initialization: The
App
class starts by parsing command-line arguments to get the input and output file paths. -
JSON Reading & Parsing: The
JsonReader
class is invoked. It uses the Jackson library to read the specified JSON file. Jackson'sObjectMapper
handles the "node traversal" automatically, parsing the JSON text. -
Data Mapping (POJO Structure): The JSON array is deserialized into a
List<Publication>
. Each JSON object is mapped to aPublication
Java object. This step handles the "nested structures" mentioned in the feedback; for example, the JSON array of authors is mapped to aList<String>
inside thePublication
object. -
Data Transformation & CSV Writing: The
CsvWriter
class takes theList<Publication>
. Using Apache Commons CSV, it iterates through eachPublication
object and writes a new row. The key transformation happens here: theList<String> authors
is converted into a single, semi-colon delimited string (e.g., "Author 1; Author 2") to fit into a single CSV cell. -
Error Handling: The entire process within
App.java
is wrapped in atry-catch
block to handleIOException
, gracefully exiting if a file is not found or cannot be read/written.
This checklist confirms that all required functionalities and quality criteria are met before the final delivery.
Criteria | Status | Notes |
---|---|---|
Core Functionality | ✅ Complete | mvn clean install runs successfully. |
Reads a valid JSON file correctly. | ✅ Complete | Tested with data/publications.json . |
Writes a correctly formatted CSV file. | ✅ Complete | Output report.csv is generated as expected. |
Handles "File Not Found" error gracefully. | ✅ Complete | Program exits with a clear error message. |
Sprint 3 Features | ||
Accepts command-line arguments for I/O paths. | ✅ Complete | Tested via IntelliJ Run Configurations and command line. |
Code Quality & Documentation | ||
All classes and public methods have JavaDoc. | ✅ Complete | All .java files in src/main and src/test are documented. |
Unit tests for JsonReader pass. |
✅ Complete | JsonReaderTest runs and passes successfully. |
README.md is complete and clear. |
✅ Complete | Includes all required sections. |