Closed cacoco closed 4 years ago
I wanted to add that we've discovered another common case where this fails for us as well. When attempting to bind or read the bound instance of a Jackson ObjectMapper augmented with the ScalaObjectMapper:
java.lang.UnsupportedOperationException: Could not convert scalaType com.fasterxml.jackson.databind.ObjectMapper with com.fasterxml.jackson.module.scala.ScalaObjectMapper to a javaType: scala.reflect.internal.Types$RefinedType0
at net.codingwell.scalaguice.TypeConversions$.scalaTypeToJavaType(TypeConversions.scala:89)
at net.codingwell.scalaguice.package$.typeLiteral(package.scala:37)
Thanks.
I can probably look at that in a few days. If you wanted to fiddle with substituting the contents of the scalatypetojavatype method with the json4s stuff that would greatly speed it up. The only time I have to work on this is after dinner when the spouse is busy.
If the json4s thing worked it would fix a lot of issues and probably get rid of all the ignored tests. We should sure to make regression tests for all the cases you are finding.
@tsuckow understood -- thanks for your help here. Let me see if I can get json4s stuff working without too much surgery. Thanks again.
@tsuckow took a stab at something minimally invasive: https://github.com/codingwell/scala-guice/pull/88.
Additionally looking at scala.reflect.internal.Types, there's a comment which list a standard pattern match against types, see here which is a bit illuminating on the cases to potentially be accounted for.
Should be fixed in 4.2.9. Thank you for your PR's
Hey there, back again. We're continuing our upgrade of Finatra to the latest version of scalaguice and have encountered another issue around the TypeConversions logic.
We have a fair amount of usage of the finagle-mysql library where a common pattern is to create a MySQL client, then augment it for doing transactions, e.g.,
Client with Transactions
. An instance of this type is then typically provided to the object graph via an@Provides
-annotated method in a Module. However, with the latest scalaguice library, the TypeConversions fails to translate the ScalaType to a JavaType and thus any attempt to get the bound instance via an injector lookup throws an exception like this:Here's an example repro using Scala 2.12.10, JDK 8, scalaguice 4.2.8 and guice 4.2.3.
Binding this type via the scalaguice bind DSL in the ScalaModule also fails similarly:
And like before this worked in scalaguice 4.2.0 pre the transition from Manifests to TypeTags.
I wanted to also point out that translation from Scala types to Java types is something we have to do a lot in JSON serialization/deserialization and after years of having our own hand-rolled stuff we switched to make use of the reflection portion of the json4s library which handles a fair amount of these cases -- not sure if it's worth taking a look but thought I'd mention.
Any help here would be greatly appreciated as this blocks our Finatra library upgrade to the latest version of scalaguice which enables us to get to Scala 2.13 support. Thanks!