Skip to content

Instantly share code, notes, and snippets.

@schroedermatt
Created August 2, 2018 18:25
Show Gist options
  • Select an option

  • Save schroedermatt/de498c3cf3c82a781799a82758499295 to your computer and use it in GitHub Desktop.

Select an option

Save schroedermatt/de498c3cf3c82a781799a82758499295 to your computer and use it in GitHub Desktop.
toStruct extension example
// extension on model from 3rd party library
fun ArtistModel.toStruct() : Struct = Struct(Artist.SCHEMA)
        .put(BaseSchema.HREF_FIELD, this.href)
        .put(BaseSchema.ID_FIELD, this.id)
        .put(BaseSchema.NAME_FIELD, this.name)
// example when creating list of SourceRecords from result set
val results: List<ArtistModel> = client.getResults()
results.map {
SourceRecord(partition, offset, topic, keySchema, it.id, valueSchema, it.toStruct())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment