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

Error when the last field is a nested class #15

Closed
zhenghub opened this issue Apr 11, 2016 · 6 comments
Closed

Error when the last field is a nested class #15

zhenghub opened this issue Apr 11, 2016 · 6 comments

Comments

@zhenghub
Copy link

I meet an error when transform a typesafe config to a case class below.

case class Weapon(t: String, attack: Int, defense: Int)
case class Weapon2(t: String, attack: Int)
case class Person(name: String, weapon: Weapon, life: Long)
case class WWeapon(weapon: Weapon)
case class Person2(name: String, life: Long, weapon: Weapon)
case class WWeapon2(weapon: Weapon2)

Class Weapon has two fields: attack and defense. Both are Int. It may cause some problems:

val conf: Config
extract Option, Weapon // OK
extract Option, Weapon2 // OK
extract Option, Person // OK
extract Option, WWeapon // ERROR
extract Option, Person2 // ERROR
extract Option, WWeapon2 // ERROR
implicitly[Extractor[Option,Config,Weapon]] // OK
implicitly[Extractor[Option,Config,Weapon2]] // OK
implicitly[Extractor[Option,Config,Person]] // OK
implicitly[Extractor[Option,Config,WWeapon]] // ERROR
implicitly[Extractor[Option,Config,Person2]] // ERROR
implicitly[Extractor[Option,Config,WWeapon2]] // ERROR

scala 2.11, java 7, henken 0.1.0

@kailuowang
Copy link
Owner

Probably a bug. I would recommend you to use ficus for now. Since there is an ongoing attempt to fix SI2712 which affects henkan greatly, I am going to hold on making any change to it.

@kailuowang
Copy link
Owner

I noticed as well that henkan might got confused when the last field is a nested field. A work around could be having an implicit Extractor of the nested class first.

@zhenghub
Copy link
Author

I use the work around as below and it works

implicit val ev1 = implicitly[Extractor[Option,Config,Weapon]] // OK. why announce the implicit value again works?
implicit val ev2 = implicitly[Extractor[Option,Config,Weapon2]] // OK
implicitly[Extractor[Option,Config,Person]] // OK
implicitly[Extractor[Option,Config,WWeapon]] // OK
implicitly[Extractor[Option,Config,Person2]] // OK
implicitly[Extractor[Option,Config,WWeapon2]] // OK

I want to use henkan to handle not only typesafe configs but also serialization and unserialization to json and byte array, so Ficus cannot solve my problem. Since shapeless is still confusing to me and you consider not change henkan recently, could you give me some hints so I can fix this in my fork?

@kailuowang
Copy link
Owner

@zhenghub I don't have a clue how to fix this bug yet. but this scala fix scala/scala#5102 will greatly simplify Henkan code, which will probably make it a lot easier to fix this problem.
Have you looked at scala pickling yet? https://github.com/scala/pickling Henkan is still pretty immature, scala pickling is probably a more robust library for json/byte serialization.

@zhenghub
Copy link
Author

zhenghub commented Apr 19, 2016

@kailuowang I've tried https://github.com/netvl/picopickle . It fixed the bug. But it is quite complicated to adapt picopickle to typesafe config, since many classes of typesafe config are not public which conflicts with picopickle's type transformation implementation. Meaning I need to write another series of classes as intermediate conversion. I would try pickling next.

@kailuowang kailuowang changed the title Error when nested case class has continous fields of the same type Error when the last field is a nested class Apr 20, 2016
@kailuowang
Copy link
Owner

closing this because the experimental extract module has been removed.

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