#1213: IdsOnlySerializer.kt

projectforge-business/src/main/kotlin/org/projectforge/framework/json/IdsOnlySerializer.kt JSON Serializer, projectforge-business/src/main/kotlin/org/projectforge/framework/json/IdsOnlySerializer.kt 54 lines · 27 code · 24 comments · 3 blank
Jackson JsonSerializer<Collection<*>> that serializes collections of IdObject entities as arrays of {"id": ...} objects. Uses HibernateUtils.isFullyInitialized() to check if the collection is loaded; writes null if not, preventing accidental database fetches during JSON serialization.

Architecture

Serialization Logic

  1. value == null: write null
  2. !HibernateUtils.isFullyInitialized(value): write null (prevents lazy fetch)
  3. Otherwise: iterate items; IdObject items use IdOnlySerializer.writeObject(), others use default serialization

Key Details

Git History

868d6abb7 2025 -> 2026
2df5e78ad IdsOnlySerializer fixed. Has caused json serialization errors e.g. on PFUserDO.
6a32032d6 Hibernate.isInitialized(obj) -> HibernateUtils.isFullyInitialized(obj).
63081666f Source file headers: 2024-> 2025.
59519ee50 Json serialization refactored: IdOnlySerializer and IdsOnlySerializer introduced.
0237d5eba Json serialization refactored: IdOnlySerializer and IdsOnlySerializer introduced.