#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
value == null: write null
!HibernateUtils.isFullyInitialized(value): write null (prevents lazy fetch)
- Otherwise: iterate items;
IdObject items use IdOnlySerializer.writeObject(), others use default serialization
Key Details
HibernateUtils.isFullyInitialized() is preferred over Hibernate.isInitialized() because Some ManyToOne lazy objects may not be fully loaded even when Hibernate reports them as initialized
- Delegates individual IdObject item serialization to
IdOnlySerializer.writeObject() (shared companion method)
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.