Design a data transformation library supporting formats like XML, JSON, CSV. Also, identify appropriate design pattern (e.g., Strategy Pattern)
Difficulty: MEDIUMCategory: LLDFrequency: 1Asked On 2024-10-27
Problem Statement
Designing a data transformation library that can read, process, and convert data between multiple formats such as JSON, XML, and CSV. The system should be extensible, so that adding support for new formats requires minimal code changes.
Functional Requirements
1.The library should support input parsing from formats:
•JSON → internal object model
•XML → internal object model
•CSV → internal object model
2.The library should support output serialization into any supported format (JSON, XML, CSV).
3.Transformation should work as:
1
2Input Format → Internal Representation → Output Format1.Must allow easy extension for new formats (e.g., YAML, Avro, Parquet).
2.Should handle invalid/malformed inputs gracefully.
Non-Functional Requirements
•Extensibility: Adding new formats shouldn’t require changing core logic.
•Reusability: Parsing and serialization should be decoupled.
•Maintainability: Minimize duplicate logic across formats.
•Performance: Should work efficiently for large files (streaming APIs optional).
Design Constraints & Edge Cases
•Input might be empty or corrupted → throw meaningful exceptions.
•Some formats may not represent nested structures (e.g., flat CSV).
•Transformation may lose information if source format richer than target.
Design Hints
•Patterns:
•Strategy Pattern → For format-specific parsing/serialization strategies.
•Factory Method / Abstract Factory → For creating appropriate parser/serializer.
•Adapter Pattern → For integrating external libraries (e.g., Jackson for JSON).
•Classes / Interfaces:
•DataParser (Strategy interface) → parse(String input): DataModel
•DataSerializer (Strategy interface) → serialize(DataModel model): String
•DataModel → Internal unified object structure (maps, lists, primitives).
•ParserFactory → Returns correct parser based on format.
Example Flow
1.User calls:
1
2DataModel model = ParserFactory.getParser("json").parse(jsonInput);
3String xmlOutput = SerializerFactory.getSerializer("xml").serialize(model);1.JSON input → Parsed to internal DataModel → Converted to XML output.
Evaluation Areas
•Correct identification of Strategy Pattern for format handling.
•Ability to define clean abstractions (interfaces) for parser/serializer.
•Handling edge cases like malformed inputs or lossy transformations.
•Designing an extensible factory for new formats.
👉 This LLD tests object-oriented design, extensibility, and application of design patterns (Strategy + Factory) in a practical library setting.