#1212: IdOnlySerializer.kt
projectforge-business/src/main/kotlin/org/projectforge/framework/json/IdOnlySerializer.kt JSON Serializer, projectforge-business/src/main/kotlin/org/projectforge/framework/json/IdOnlySerializer.kt 67 lines · 37 code · 24 comments · 6 blank
Jackson JsonSerializer<IdObject<*>> that serializes entity references to a compact {"id": ...} JSON object. Consults JsonThreadLocalContext to determine behavior: if preferEmbeddedSerializers or ignoreIdOnlySerializers is set, it falls back to full serialization or another registered serializer. Prevents deep object graphs by default.
Architecture
Serialization Decision Tree
- If
value == null: write null
- If
JsonThreadLocalContext.get() != null:
- If
preferEmbeddedSerializers == true and another serializer exists for the class: use it
- If
ignoreIdOnlySerializers == true: use Jackson's default serialization
- Default: write
{"id": value.id} (id may be null, written as appropriate JSON type via JsonUtils.writeField)
Integration
- Used globally in Jackson
ObjectMapper configuration
- Companion object's
writeObject() shared with IdsOnlySerializer
JsonThreadLocalContext provides per-thread serialization override flags
Git History
868d6abb7 2025 -> 2026
63081666f Source file headers: 2024-> 2025.
59519ee50 Json serialization refactored: IdOnlySerializer and IdsOnlySerializer introduced.
0237d5eba Json serialization refactored: IdOnlySerializer and IdsOnlySerializer introduced.
b6092df09 Copyright 2023 -> 2024
ab45d51fa Copyright 2001-2022 -> 2001-2023.