Skip to content

carlop13/json-csv-processor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Back End in Java for Information Processing

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.

📚 Content Description

  • /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.

⚙️ How to Run the Project

Prerequisites

  • Java Development Kit (JDK) 11 or higher.
  • Apache Maven.
  • An IDE like IntelliJ IDEA or VS Code (recommended).

Steps to Run

  1. Clone the repository:

    git clone https://github.com/carlop13/json-csv-processor.git
    cd json-csv-processor
  2. Build the project with Maven: This will download all necessary dependencies.

    mvn clean install
  3. 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()'".
  4. Verify the output:

    • After running, a new file named report.csv will be created in the output/ directory. You can open this file with any spreadsheet program to see the result.

Transformation Algorithm

This section describes the internal logic for converting JSON data to CSV, addressing the feedback on algorithm design.

  1. Initialization: The App class starts by parsing command-line arguments to get the input and output file paths.

  2. JSON Reading & Parsing: The JsonReader class is invoked. It uses the Jackson library to read the specified JSON file. Jackson's ObjectMapper handles the "node traversal" automatically, parsing the JSON text.

  3. Data Mapping (POJO Structure): The JSON array is deserialized into a List<Publication>. Each JSON object is mapped to a Publication Java object. This step handles the "nested structures" mentioned in the feedback; for example, the JSON array of authors is mapped to a List<String> inside the Publication object.

  4. Data Transformation & CSV Writing: The CsvWriter class takes the List<Publication>. Using Apache Commons CSV, it iterates through each Publication object and writes a new row. The key transformation happens here: the List<String> authors is converted into a single, semi-colon delimited string (e.g., "Author 1; Author 2") to fit into a single CSV cell.

  5. Error Handling: The entire process within App.java is wrapped in a try-catch block to handle IOException, gracefully exiting if a file is not found or cannot be read/written.

Verification Checklist

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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages