Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic value readers for abstract classes? #27

Open
saifellafi opened this issue May 20, 2016 · 1 comment
Open

Dynamic value readers for abstract classes? #27

saifellafi opened this issue May 20, 2016 · 1 comment

Comments

@saifellafi
Copy link

saifellafi commented May 20, 2016

Hi,

How would you approach an abstract reader?

eg:

abstract class AbClass
case class C1Class(x1: Int, x2:String) extends AbClass
case class C2Class(x3: String) extends AbClass

Then have a config which looks like

{
"C2Class": {
"x1": "foo"
}
}

and let config.as[AbClass] do its job inferring the type. Without having to list all possible case classes as None options by default

Thanks,
Saif

@kailuowang
Copy link
Member

As of now you would need to write your own custom ValueReader[AbClass] which looks at the field name and determine which sub-class is in the config and use the appropriate ValueReader for that subclass to read the value. The ValueReader for subclasses can be automatically generated by import net.ceedubs.ficus.readers.ArbitraryTypeReader._ and then implicitly[ValueReader[C1Class]] .
We would also love to see efforts to enhance the current macro to handle coproduct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants