Skip to content

Instantly share code, notes, and snippets.

View pdvrieze's full-sized avatar

Paul de Vrieze pdvrieze

View GitHub Profile
@pdvrieze
pdvrieze / JsonOrListSerializer.kt
Created September 13, 2024 10:21
Sample implementation of a serializer that, for json, encodes/decodes single element lists as their element directly.
import kotlinx.serialization.KSerializer
import kotlinx.serialization.builtins.ListSerializer
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
import kotlinx.serialization.json.JsonArray
import kotlinx.serialization.json.JsonDecoder
import kotlinx.serialization.json.JsonEncoder
class JsonOrListSerializer<T>(private val elementSerializer: KSerializer<T>): KSerializer<List<T>> {
@pdvrieze
pdvrieze / DelegatingFormat.kt
Last active June 5, 2024 09:08
Example code for a delegating format.
/*
* Copyright (c) 2024.
*
* This file is part of xmlutil.
*
* This file is licenced to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You should have received a copy of the license with the source distribution.
* Alternatively, you may obtain a copy of the License at
*