Skip to content

Instantly share code, notes, and snippets.

val vehicleAdapterFactory: RuntimeTypeAdapterFactory =
RuntimeTypeAdapterFactory.of(Vehicle::class.java, "type")
.registerSubtype(Vehicle::class.java, "car")
.registerSubtype(Vehicle::class.java, "truck")
val Gson = GsonBuilder().registerTypeAdapterFactory(vehicleAdapterFactory)
.create()
try {
val vehicleContainer = moshi.adapter(VehicleContainer::class.java)
.fromJson(jsonStr, VehicleContainer.class)
} catch(error: JsonDataException) {
}
val vehicleContainer = Gson.fromJson(jsonStr, VehicleContainer.class)
val vehicleAdapterFactory = PolymorphicJsonAdapterFactory.of(Vehicle::class.java, "type")
.withSubtype(Car::class.java, "car")
.withSubtype(Truck::class.java, "truck")
val moshi = Moshi.Builder().add(vehicleAdapterFactory).build()
data class VehicleContainer(val vehicles: List)
abstract class Vehicle {
abstract val model: String
abstract val type : String
abstract val tyres: List?
}
data class Car(override val model: String,
override val type: String,
@JsonClass(generateAdapter = true)
data class Car(override val model: String,
override val type: String,
override val tyres: List?): Vehicle()
on:
issue_comment:
types: [created]
jobs:
build-head:
runs-on: ubuntu-latest
steps:
- uses: khan/pull-request-comment-trigger@master
id: check
with:
trigger: 'benchmark-build'
- uses: xt0rted/pull-request-comment-branch@v1
id: comment-branch
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
# Clone head commit
- name: Clone Repo
uses: actions/checkout@v2
with:
submodules: recursive
ref: ${{ steps.comment-branch.outputs.head_ref }}