/Main.kt Secret
Created
August 27, 2024 21:19
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
plugins { | |
kotlin("jvm") version "2.0.20" | |
kotlin("plugin.serialization") version "2.0.0" | |
} | |
group = "local.test" | |
version = "1.0-SNAPSHOT" | |
repositories { | |
mavenCentral() | |
} | |
dependencies { | |
implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:1.7.1") | |
implementation("io.github.pdvrieze.xmlutil:serialization-jvm:0.90.1") | |
testImplementation(kotlin("test")) | |
} | |
tasks.test { | |
useJUnitPlatform() | |
} | |
kotlin { | |
jvmToolchain(17) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kotlinx.serialization.SerialName | |
import kotlinx.serialization.Serializable | |
import nl.adaptivity.xmlutil.serialization.XML | |
import nl.adaptivity.xmlutil.serialization.XmlElement | |
import nl.adaptivity.xmlutil.serialization.XmlNamespaceDeclSpec | |
import nl.adaptivity.xmlutil.xmlStreaming | |
fun main() { | |
val result = HelloWorld::class.java.classLoader.getResourceAsStream("test.xml")?.use { | |
XML { | |
defaultPolicy { | |
pedantic = false | |
isStrictAttributeNames = false | |
} | |
}.decodeFromReader(HelloWorld.serializer(), xmlStreaming.newReader(it.reader())) | |
} ?: error("Couldn't read file") | |
println(result) | |
} | |
@Serializable | |
@SerialName("test:HelloWorld") | |
@XmlNamespaceDeclSpec("test=https://test.local") | |
data class HelloWorld( | |
@XmlElement | |
val user: String | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<test:HelloWorld xmlns:test="https://test.local"> | |
<user>You!</user> | |
</test:HelloWorld> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment