#1215: JsonUtils.kt
projectforge-business/src/main/kotlin/org/projectforge/framework/json/JsonUtils.kt JSON Utility Object, projectforge-business/src/main/kotlin/org/projectforge/framework/json/JsonUtils.kt 153 lines · 102 code · 34 comments · 17 blank
Central JSON serialization/deserialization utility. Maintains three Jackson ObjectMapper instances: default, ignore-nullable-props, and ignore-unknown-props. Registers KotlinModule, Hibernate6Module, and custom serializers/deserializers for LocalDate, LocalTime, PFDateTime, PFDay, java.util.Date, Timestamp, and java.sql.Date.
Architecture
ObjectMapper Instances
| Instance | Configuration | Use Case |
objectMapper | KotlinModule + Hibernate6Module + custom serializers | Default JSON operations |
objectMapperIgnoreNullableProps | Same + Include.NON_NULL | Excludes null properties from output |
objectMapperIgnoreUnknownProps | Same + FAIL_ON_UNKNOWN_PROPERTIES = false | Lenient deserialization |
Registered Serializers/Deserializers (via initializeMapper)
| Type | Serializer | Deserializer |
LocalDate | LocalDateSerializer (ISO yyyy-MM-dd) | LocalDateDeserializer (flexible parsing via PFDayUtils) |
LocalTime | LocalTimeSerializer | LocalTimeDeserializer |
PFDateTime | PFDateTimeSerializer | PFDateTimeDeserializer |
PFDay | PFDaySerializer | PFDayDeserializer |
java.util.Date | UtilDateSerializer (JS_TIME_DATE_MILLIS) | UtilDateDeserializer |
Timestamp | TimestampSerializer (JS_TIME_DATE_MILLIS) | TimestampDeserializer |
java.sql.Date | SqlDateSerializer | SqlDateDeserializer |
Core Methods
| Method | Signature | Description |
toJson | (obj, ignoreNullableProps=false): String | Serialize to JSON string |
fromJson | (json, Class<T>, failOnUnknownProps=true): T? | Deserialize to typed object |
fromJson | (json, TypeReference<T>, failOnUnknownProps=true): T? | Deserialize to generic type |
writeField | (gen, field, value) | Write a field with type-appropriate JSON type (Long, Int, String) |
add | (cls, typeAdapter) | Register extra type adapters in a map (unused by default mappers) |
Error Handling
toJson catches JsonProcessingException and returns empty string on error
fromJson throws IOException to caller
Git History
868d6abb7 2025 -> 2026
5b042ab5f UserGroupCache: debug export json, registerModule(Hibernate6Module()), DatabaseTester added.
7b32b554a WIP: Forecast of orders.... AuftragFilter refactored.
63081666f Source file headers: 2024-> 2025.
0237d5eba Json serialization refactored: IdOnlySerializer and IdsOnlySerializer introduced.
fbf3290bb JsonUtils: missing initializer for objectMapperIgnoreNullableProps added.
57935eb50 Java 11, Wicket 9. Runs more or less.
b6092df09 Copyright 2023 -> 2024
cb2915283 WIP D.velop
ab45d51fa Copyright 2001-2022 -> 2001-2023.
c6d8f4426 JsonUtils shares now module settings with JacksonConfiguration.
5f7ef41b8 Copyright 2021 -> 2022
7e5daae24 JsonUtils moved to business package.
c9d973a14 SourceFileHeader fixed.
7c5080e8c WIP: Save variables after editing.