Skip to content

Instantly share code, notes, and snippets.

@l15k4
Last active June 6, 2016 10:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save l15k4/dc9bfb67215322f675271dc77e8d7425 to your computer and use it in GitHub Desktop.
Save l15k4/dc9bfb67215322f675271dc77e8d7425 to your computer and use it in GitHub Desktop.
trait Storage
case class ViewId(id: String, access: String = "rw", base: Boolean = false)
case class S3Storage(bucket: String, path: String) extends Storage
case class DruidStorage(coordinatorHost: String, overlordHost: String, dataSource: String) extends Storage
sealed trait Partitioning
case class TimePartitioning(granularity: String) extends Partitioning
case class Partition(p: String)
sealed trait View[+S <: Storage, +P <: Partitioning] {
def viewId: ViewId
def storage: S
def partitioning: P
}
case class S3TimeView(viewId: ViewId, storage: S3Storage, partitioning: TimePartitioning) extends View[S3Storage, TimePartitioning]
case class DruidTimeView(viewId: ViewId, storage: DruidStorage, partitioning: TimePartitioning) extends View[DruidStorage, TimePartitioning]
case class InputMessage[S<:Storage,P<:Partitioning](fromView: View[S,P], toView: View[S,P], partition: Partition)
ObjMapper.readValue[InputMessage[S3Storage, TimePartitioning]](json, new TypeReference[InputMessage[S3Storage, TimePartitioning]]() {})
_____________________________________________________________
[info] com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of gwi.gwiq.pm.View, problem: abstract types either need to be mapped to concrete types, have custom deserializer, or be instantiated with additional type information
[info] at [Source: {"fromView":{"viewId":{"id":"firstLevelHourlyView","access":"ro","base":true},"storage":{"bucket":"gwiq-views-t","path":"partition-manager/firstLevelHourlyView"},"partitioning":{"granularity":"HOUR"}},"toView":{"viewId":{"id":"firstLevelHourlyView","access":"ro","base":true},"storage":{"bucket":"gwiq-views-t","path":"partition-manager/firstLevelHourlyView"},"partitioning":{"granularity":"HOUR"}},"partition":{"p":""}}; line: 1, column: 13] (through reference chain: gwi.gwiq.pm.InputMessage["fromView"])
@l15k4
Copy link
Author

l15k4 commented Jun 6, 2016

Possible solution but that is very inconvenient because one has to create concrete View types like S3TimeView :

case class InputMessage[FV<:View[_,_],TV<:View[_,_]](fromView: FV, toView: TV, partition: Partition)
ObjMapper.readValue[InputMessage[S3TimeView, S3TimeView]](json, new TypeReference[InputMessage[S3TimeView, S3TimeView]]() {})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment