fun getObjectMapper(): ObjectMapper {
return ObjectMapper().registerModule(
JavaTimeModule().addSerializer(
LocalDateTime::class, LocalDateTimeSerializer(DateTimeFormatter.ISO_LOCAL_DATE_TIME)
).addSerializer(
ZonedDateTime::class, ZonedDateTimeSerializer(DateTimeFormatter.ISO_OFFSET_DATE_TIME)
).addSerializer(YearMonth::class, YearMonthSerializer(DateTimeFormatter.ofPattern("yyyy-MM")))
).configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true)
}
inline fun <reified T> ObjectMapper.objectToMap(obj: T): Map<String, Any> =
this.readValue(this.writeValueAsString(obj), object : com.fasterxml.jackson.core.type.TypeReference<Map<String, Any>>() {})
fun outputPdfFile(bill: Any): File {
val jsonNode= getObjectMapper().objectToMap(bill)
val customerName = BillingStackConfig.getConfig().fastoneBilling.customer.name
return Path.of(
PathConst.OUTPUT_PATH,
PathConst.BILL_FOLDER,
jsonNode["billingCycle"].toString(),
"$customerName-${jsonNode.get("billingCycle")}-bill.pdf"
).toFile()
}
版权说明 : 本文为转载文章, 版权归原作者所有 版权申明
原文链接 : https://blog.csdn.net/sunyuhua_keyboard/article/details/123229697
内容来源于网络,如有侵权,请联系作者删除!