Skip to content

MS-238/Add @ToString to DTOs and SafeObjectParser utility class

salaheddine zidani a demandé de fusionner feature/MS-238 vers develop

Summary

This MR adds Lombok @ToString annotations to service DTOs and introduces a new SafeObjectParser utility class for safe object-to-string conversion in mydressin-cart-service.

Motivation

  • @ToString on DTOs: Simplifies debugging and logging by providing consistent string representation
  • SafeObjectParser: Provides a robust mechanism to convert complex objects to strings while handling circular references, preventing stack overflow, and supporting various data types

Changes

New Utility Classes

SafeObjectParser

A utility class for safe object-to-string parsing with the following features:

  • Circular reference detection using identity-based tracking
  • Maximum depth limit (50) to prevent stack overflow
  • Support for arrays, collections, maps, and Optional
  • Handles primitive types, enums, dates, and UUIDs
  • Skips static and synthetic fields
  • Safe handling of JDK internal classes

SafeObjectParserTest

Comprehensive test suite covering:

  • Null and simple types (String, Integer, Long, Double, Boolean, Character, Enum, UUID, Date, LocalDate, LocalDateTime)
  • Arrays (primitive, object, empty, with nulls, multidimensional)
  • Collections (List, Set, nested)
  • Maps (simple, empty, nested)
  • Optional (with value, empty)
  • Complex objects (POJOs, nested, with null fields, inheritance, static fields)
  • Circular references (mutual, self-reference)
  • Edge cases (objects with collection/map fields, deeply nested objects)

DTOs (added @ToString)

DTO Package
CartCountConfigDTO com.marketingconfort.mydressin.dtos
CartDTO com.marketingconfort.mydressin.dtos
ClientCartDTO com.marketingconfort.mydressin.dtos
DeleteItemsResponseDTO com.marketingconfort.mydressin.dtos
ItemCartDTO com.marketingconfort.mydressin.dtos
ItemRequestDTO com.marketingconfort.mydressin.dtos
ProductDetailsCartDTO com.marketingconfort.mydressin.dtos
ProductRequestDTO com.marketingconfort.mydressin.dtos
SessionOrderDTO com.marketingconfort.mydressin.dtos

Testing

  • Added 35+ unit tests for SafeObjectParser covering all edge cases
  • All tests passing
  • Confirmed DTOs produce readable string output for logging purposes

Closes MS-238

Rapports de requête de fusion