|
1 | 1 | # DTO Approach Comparison: JAXB vs Jackson XML |
2 | 2 |
|
3 | | -**Status:** Phase 1 Prototype Evaluation |
4 | | -**Date:** 2025-12-26 |
5 | | -**Purpose:** Evaluate two alternative approaches for ESPI 4.0 DTO implementation across 26 phases |
| 3 | +**Status:** ✅ **DECISION MADE** - Hybrid Approach (Jackson 3 Engine + JAXB Annotations) |
| 4 | +**Original Evaluation Date:** 2025-12-26 |
| 5 | +**Decision Date:** 2026-01-02 (PR #59) |
| 6 | +**Purpose:** Archive of evaluation process for ESPI 4.0 DTO implementation |
6 | 7 |
|
7 | 8 | --- |
8 | 9 |
|
9 | | -## Executive Summary |
| 10 | +## 🎯 CHOSEN APPROACH: Jackson 3 with JAXB Annotations |
| 11 | + |
| 12 | +**Implementation:** PR #59 (merged 2026-01-02) |
| 13 | + |
| 14 | +The team chose a **hybrid approach** that combines the best of both worlds: |
| 15 | + |
| 16 | +### What Was Chosen |
| 17 | +- **XML Serialization Engine**: Jackson 3 XmlMapper (`tools.jackson.dataformat:jackson-dataformat-xml:3.0.3`) |
| 18 | +- **DTO Annotations**: Jakarta XML Bind (JAXB 3.0) annotations (`jakarta.xml.bind.annotation.*`) |
| 19 | +- **Bridge Module**: `tools.jackson.module:jackson-module-jakarta-xmlbind-annotations:3.0.3` |
| 20 | + |
| 21 | +### Why This Approach |
| 22 | +✅ **Modern Performance**: Jackson 3's high-performance serialization engine |
| 23 | +✅ **Standard Annotations**: JAXB annotations remain the industry standard for XML mapping |
| 24 | +✅ **No Annotation Rewrites**: Existing DTOs keep their JAXB annotations |
| 25 | +✅ **Spring Boot 4.0 Ready**: Native Jackson 3 support in Spring Boot 4.0 |
| 26 | +✅ **Records Compatible**: Works with both classes and Java Records |
| 27 | +✅ **Proven**: Successfully implemented and tested in PR #59 |
| 28 | + |
| 29 | +### How It Works |
| 30 | +```java |
| 31 | +// DTOs use JAXB annotations (no change needed!) |
| 32 | +@XmlRootElement(name = "IntervalBlock", namespace = "http://naesb.org/espi") |
| 33 | +@XmlType(propOrder = {...}) |
| 34 | +public record IntervalBlockDto(...) { } |
| 35 | + |
| 36 | +// Jackson XmlMapper processes JAXB annotations |
| 37 | +XmlMapper xmlMapper = XmlMapper.xmlBuilder() |
| 38 | + .annotationIntrospector(new JakartaXmlBindAnnotationIntrospector()) |
| 39 | + .addModule(new JakartaXmlBindAnnotationModule()) |
| 40 | + .build(); |
| 41 | +``` |
| 42 | + |
| 43 | +**See:** `DtoExportServiceImpl.java:154-172` for complete implementation |
| 44 | + |
| 45 | +--- |
| 46 | + |
| 47 | +## Historical Evaluation Summary |
| 48 | + |
| 49 | +This section preserves the original evaluation that led to the decision. |
10 | 50 |
|
11 | 51 | Both **JAXB (Jakarta XML Binding)** and **Jackson XML** approaches successfully: |
12 | 52 | - ✅ Marshal/unmarshal TimeConfiguration XML correctly |
@@ -333,83 +373,84 @@ Time elapsed: 0.213 s |
333 | 373 |
|
334 | 374 | --- |
335 | 375 |
|
336 | | -## Recommendations |
337 | | - |
338 | | -### For Senior Spring Boot Developer Consideration: |
| 376 | +## ~~Recommendations~~ FINAL DECISION |
339 | 377 |
|
340 | | -**If prioritizing:** |
| 378 | +### ✅ Chosen Approach: Hybrid (Jackson 3 + JAXB Annotations) |
341 | 379 |
|
342 | | -1. **Long-term Maintainability → Choose Jackson XML** |
343 | | - - 24% less code to maintain across 26 phases |
344 | | - - Immutability reduces bugs |
345 | | - - Aligned with Spring Boot 3.x/4.0 direction |
346 | | - - Modern recruitment advantage |
| 380 | +The team chose **Option D: Hybrid Approach** (not originally listed) which provides: |
347 | 381 |
|
348 | | -2. **Short-term Delivery & Stability → Choose JAXB** |
349 | | - - Proven XSD compliance |
350 | | - - Team already familiar |
351 | | - - Matches existing pattern |
352 | | - - Lower risk for Phase 1 completion |
| 382 | +**✅ Best of Both Worlds:** |
| 383 | +1. **Jackson 3 Performance**: Modern, high-performance XML serialization engine |
| 384 | +2. **JAXB Standard Annotations**: Keep industry-standard XML mapping annotations |
| 385 | +3. **No Refactoring Required**: Existing DTOs continue using JAXB annotations |
| 386 | +4. **Spring Boot 4.0 Ready**: Native Jackson 3 support |
| 387 | +5. **XSD Compliance**: JAXB annotations ensure schema compliance |
353 | 388 |
|
354 | | -3. **ESPI XSD Strict Compliance → Choose JAXB** |
355 | | - - Built specifically for XML Schema |
356 | | - - Better validation tooling |
357 | | - - Industry standard for schema-first development |
| 389 | +**✅ Addresses All Concerns:** |
| 390 | +- **Maintainability**: Jackson 3 is the future for Spring Boot 4.0 |
| 391 | +- **Stability**: JAXB annotations are proven and stable |
| 392 | +- **Consistency**: All DTOs use same annotation style |
| 393 | +- **Compliance**: JAXB annotations guarantee ESPI 4.0 XSD compliance |
| 394 | +- **No Retraining**: Team continues using familiar JAXB annotations |
358 | 395 |
|
359 | | -### Decision Timeline |
| 396 | +### Implementation Status |
360 | 397 |
|
361 | | -**Recommendation:** Make decision **now at Phase 1**, not after multiple phases are complete. |
| 398 | +**✅ Completed (PR #59):** |
| 399 | +- Jackson 3 XML dependencies added to `openespi-common/pom.xml` |
| 400 | +- `DtoExportServiceImpl` updated with Jackson 3 XmlMapper configuration |
| 401 | +- All existing DTOs continue using JAXB annotations (no changes needed) |
| 402 | +- Integration tests passing with Jackson 3 serialization |
| 403 | +- Production XML output verified against ESPI 4.0 schema |
362 | 404 |
|
363 | | -**If choosing Jackson XML:** |
364 | | -- Budget time to refactor existing DTOs (`UsagePointDto`, etc.) for consistency |
365 | | -- Create team training on Jackson XML annotations |
366 | | -- Update DTO_PATTERN_GUIDE.md with Jackson patterns |
367 | | - |
368 | | -**If choosing JAXB:** |
369 | | -- Accept higher LOC count across remaining 25 phases |
370 | | -- Document defensive copying patterns for byte arrays |
371 | | -- Plan future migration to Jackson if Spring Boot 4.0 shifts direction |
| 405 | +**📋 Next Steps:** |
| 406 | +- All 26 phases will use JAXB annotations on DTOs |
| 407 | +- Jackson 3 XmlMapper handles serialization/deserialization |
| 408 | +- See `MULTI_PHASE_SCHEMA_COMPLIANCE_PLAN.md` for phase-by-phase plan |
372 | 409 |
|
373 | 410 | --- |
374 | 411 |
|
375 | | -## Files for Review |
| 412 | +## Implementation Files |
376 | 413 |
|
377 | | -### JAXB Implementation |
378 | | -- **DTO:** `src/main/java/org/greenbuttonalliance/espi/common/dto/usage/TimeConfigurationDto.java` |
379 | | -- **Tests:** `src/test/java/org/greenbuttonalliance/espi/common/dto/usage/TimeConfigurationDtoTest.java` |
380 | | -- **Mapper:** `src/main/java/org/greenbuttonalliance/espi/common/mapper/usage/TimeConfigurationMapper.java` |
| 414 | +### Jackson 3 Configuration |
| 415 | +- **Service:** `DtoExportServiceImpl.java` - XmlMapper configuration with JAXB annotation support |
| 416 | +- **Dependencies:** `openespi-common/pom.xml` - Jackson 3 XML and JAXB module |
| 417 | +- **Tests:** `DtoExportServiceImplTest.java` - Integration tests with sample XML output |
381 | 418 |
|
382 | | -### Jackson XML Implementation |
383 | | -- **DTO:** `src/main/java/org/greenbuttonalliance/espi/common/dto/usage/TimeConfigurationDtoJackson.java` |
384 | | -- **Tests:** `src/test/java/org/greenbuttonalliance/espi/common/dto/usage/TimeConfigurationDtoJacksonTest.java` |
385 | | -- **Dependencies:** Added `jackson-dataformat-xml` to `pom.xml` |
| 419 | +### DTO Examples (Using JAXB Annotations) |
| 420 | +- **IntervalBlockDto.java** - Record with JAXB annotations |
| 421 | +- **UsagePointDto.java** - DTO with JAXB annotations |
| 422 | +- **AtomEntryDto.java** - Atom wrapper with JAXB annotations |
386 | 423 |
|
387 | | -### Comparison Document |
388 | | -- **This file:** `DTO_APPROACH_COMPARISON.md` |
| 424 | +### Sample Output |
| 425 | +- **testdata.xml** - ESPI-compliant Atom XML produced by Jackson 3 |
389 | 426 |
|
390 | | ---- |
| 427 | +### Planning Documents |
| 428 | +- **MULTI_PHASE_SCHEMA_COMPLIANCE_PLAN.md** - Updated with Jackson 3 approach |
| 429 | +- **This file:** `DTO_APPROACH_COMPARISON.md` - Decision rationale |
391 | 430 |
|
392 | | -## Next Steps |
| 431 | +--- |
393 | 432 |
|
394 | | -1. **Team Review:** Distribute this document for review |
395 | | -2. **Decision Meeting:** Schedule architecture discussion |
396 | | -3. **Consensus:** Choose one approach for all 26 phases |
397 | | -4. **Update Plan:** Modify `SPRING_BOOT_CONVERSION_PLAN.md` with chosen approach |
398 | | -5. **Phase 1 Completion:** Implement chosen approach for TimeConfiguration |
399 | | -6. **Phases 2-26:** Apply chosen pattern consistently |
| 433 | +## Decision Rationale |
400 | 434 |
|
401 | | ---- |
| 435 | +**Why Not Pure JAXB?** |
| 436 | +- Requires JAXB runtime (javax.xml.bind implementation) |
| 437 | +- Slower performance compared to Jackson 3 |
| 438 | +- Not the direction of Spring Boot 4.0 |
402 | 439 |
|
403 | | -## Questions for Discussion |
| 440 | +**Why Not Pure Jackson XML?** |
| 441 | +- Would require rewriting all JAXB annotations to Jackson annotations |
| 442 | +- Jackson XML annotations less mature for strict XSD compliance |
| 443 | +- Team would need retraining on new annotation styles |
404 | 444 |
|
405 | | -1. How important is strict XSD validation vs code maintainability? |
406 | | -2. Are we comfortable requiring Java 17+ records? |
407 | | -3. Should we refactor existing DTOs for consistency? |
408 | | -4. What is the team's experience level with Jackson XML? |
409 | | -5. Do we expect ESPI schema changes that would benefit from JAXB's validation? |
| 445 | +**Why Hybrid (Jackson 3 + JAXB Annotations)?** |
| 446 | +- ✅ Jackson 3 processes JAXB annotations via bridge module |
| 447 | +- ✅ Keep proven JAXB annotations for XSD compliance |
| 448 | +- ✅ Gain Jackson 3 performance and Spring Boot 4.0 alignment |
| 449 | +- ✅ Zero annotation rewrites needed |
| 450 | +- ✅ Best long-term maintainability |
410 | 451 |
|
411 | 452 | --- |
412 | 453 |
|
413 | 454 | **Author:** Claude Sonnet 4.5 (Senior Spring Boot Architecture Consultant) |
414 | | -**Review Status:** Awaiting Team Decision |
| 455 | +**Review Status:** ✅ **DECISION MADE AND IMPLEMENTED** (PR #59, merged 2026-01-02) |
415 | 456 | **Impact:** High (affects all 26 DTO implementation phases) |
0 commit comments