XML serialisation
The smithy4s-xml
module provides fs2-data encoders/decoders that can read/write generated data-types from/to XML bytes/strings. It is provided at the following coordinates :
sbt : "com.disneystreaming.smithy4s" %% "smithy4s-xml" % "0.18.33"
mill : "com.disneystreaming.smithy4s::smithy4s-xml:0.18.33"
The entrypoint for smithy4s.xml.Xml
. See below for example usage.
import smithy4s.example.hello.Person
import smithy4s.Blob
import smithy4s.xml.Xml
val personEncoder = Xml.encoders.fromSchema(Person.schema)
// personEncoder: smithy4s.codecs.package.BlobEncoder[Person] = smithy4s.xml.internals.XmlPayloadEncoderCompilerImpl$$anonfun$fromSchema$2@67ed4e4d
val personXML = personEncoder.encode(Person(name = "John Doe")).toUTF8String
// personXML: String = "<Person><name>John Doe</name></Person>"
val personDecoder = Xml.decoders.fromSchema(Person.schema)
// personDecoder: smithy4s.codecs.package.BlobDecoder[Person] = smithy4s.xml.Xml$$anon$1$$anon$2@3ea607ef
val maybePerson = personDecoder.decode(Blob(personXML))
// maybePerson: Either[smithy4s.codecs.PayloadError, Person] = Right(
// value = Person(name = "John Doe", town = None)
// )
By default, smithy4s-xml
abides by the semantics of :