gpt4 book ai didi

koltin 如何使用Jackson的ObjectMapper()获取json中的值

转载 作者:知者 更新时间:2024-03-13 06:03:33 26 4
gpt4 key购买 nike

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()
	}

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com