Skip to content
OUATTARA Romuald edited this page Apr 5, 2019 · 1 revision

Welcome to the syndication wiki!

Custom syndication feed type

In the current state, if the user wants to parse a feed that contains non-conventional fields, it is not possible. Also the API has lots of nullable fields, which you may not want.

Syndication comes with two annotations:

  • @Atom
  • @Rss

that can be used to mark custom classes. If a class is marked with the annotations above then the adapters will not enforce the return type to be AtomFeed or RssFeed.

Usage:

interface CustomReader {

  @Rss(returnClass = CustomRssFeed::class)
  fun read(): CustomRssFeed

  @Rss(returnClass = CustomRssFeed::class)
  fun readAsync(): Deferred<CustomRssFeed>

  @Rss(returnClass = CustomRssFeed::class)
  fun readOnce(): Single<CustomRssFeed>
}

then let Syndication class generates an implementation of that interface CustomReader:

val syndicationReader = Syndication(
  url = "https://www.lequipe.fr/rss/actu_rss.xml"
)
val reader = syndicationReader.create(CustomReader::class.java)
val rssFeed = reader.read() // this is synchronous

CustomRssFeed

@Root(name = "rss", strict = false)
data class CustomRssFeed(
  @field:Element(name = "channel")
  @param:Element(name = "channel")
  val channel: Channel
) : Serializable

Channel

@Root(strict = false)
class Channel(
  @field:Element(name = "title")
  @param:Element(name = "title")
  val title: String,

  @field:ElementList(name = "link", inline = true)
  @param:ElementList(name = "link", inline = true)
  val links: List<Link>,

  @field:Element(name = "description")
  @param:Element(name = "description")
  val description: String,

  @field:Element(name = "language", required = false)
  @param:Element(name = "language", required = false)
  val language: String? = null,

  @field:Element(name = "copyright", required = false)
  @param:Element(name = "copyright", required = false)
  val copyright: String? = null
) : Serializable
Clone this wiki locally