Skip to content

Repository files navigation

phobos

Maven CentralBuildScala StewardDiscord

Phobos is an XML data-binding library based on stream parsing. It depends only on aalto-xml for parsing.

Scala 2.12 and 2.13 are supported.

QuickStart

Add phobos-core to your dependencies:

libraryDependencies += "ru.tinkoff" %% "phobos-core" % "0.13.2"

Then try this code out in sbt console or in a separate source file:

importru.tinkoff.phobos.decoding._importru.tinkoff.phobos.encoding._importru.tinkoff.phobos.syntax._importru.tinkoff.phobos.derivation.semiauto._caseclassTravelPoint(country: String, city: String)
objectTravelPoint {
implicitvaltravelPointElementEncoder:ElementEncoder[TravelPoint] = deriveElementEncoder
implicitvaltravelPointElementDecoder:ElementDecoder[TravelPoint] = deriveElementDecoder
}
caseclassPrice(@attr currency: String, @text value: Double)
objectPrice {
implicitvalpriceElementEncoder:ElementEncoder[Price] = deriveElementEncoder
implicitvalpriceElementDecoder:ElementDecoder[Price] = deriveElementDecoder
}
caseclassJourney(price: Price, departure: TravelPoint, arrival: TravelPoint)
objectJourney {
implicitvaljourneyXmlEncoder:XmlEncoder[Journey] = deriveXmlEncoder("journey")
implicitvaljourneyXmlDecoder:XmlDecoder[Journey] = deriveXmlDecoder("journey")
}
valjourney=Journey(
price =Price("EUR", 1000.0),
departure =TravelPoint("France", "Marcelle"),
arrival =TravelPoint("Germany", "Munich")
)
valxml:String=XmlEncoder[Journey].encode(journey)
println(xml)
valdecodedJourney=XmlDecoder[Journey].decode(xml)
println(decodedJourney)
assert(Right(journey) == decodedJourney)

Please see phobos wiki for explanation of the syntax and more details.

Performance

Performance details can be found out in phobos-benchmark repository.

Addons

There are several additional modules for some specific cases. These modules could be added with command below:

libraryDependencies += "ru.tinkoff" %% "phobos-<module>" % "0.13.2

Where <module> is module name.

Module nameFunctionality
akka-httpMarshallers and unmarshallers for akka-http
akka-streamStreaming decoding support for akka-stream
catsCats instances
derevoSeparate derivation of encoders and decoders separately using derevo annotations (e.g. @derive(xmlEncoder("foo")))
enumeratumSupport for enumeratum enums
fs2Streaming decoding support (Stream[F, Array[Byte]] => G[A]). Latest fs2 version (fs2 3.x, cats effect 3.x)
fs2-ce2Streaming decoding support (Stream[F, Array[Byte]] => G[A]). Same as fs2 module, but for fs2 version 2.x using cats effect 2.x
monixStreaming decoding support (Observable[Array[Byte]] => Task[A])
refinedSupport for refined

XSD and WSDL code-generation support

It will be soon implemented in deimos library.

About

Efficient and expressive XML data-binding library for Scala

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages