Scala 2.12.0 compilation warning when using Jackson @JsonTypeInfo-annotation

479 views
Skip to first unread message

Morten Kjetland

unread,
Nov 25, 2016, 2:39:25 AM11/25/16
to scala-internals
Hi,

The following code using Jackson 2.8.4 and Scala 2.12.0:

import com.fasterxml.jackson.annotation.JsonTypeInfo.{As, Id}
import com.fasterxml.jackson.annotation.{JsonSubTypes, JsonTypeInfo}

@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
include = JsonTypeInfo.As.PROPERTY,
property = "type")
@JsonSubTypes(Array(
new Type(value = classOf[AddCfsRelation], name = "add"),
new Type(value = classOf[RemoveCfsRelation], name = "remove")
))

trait MyTrait {
def someProperty: String
}

Gives this compiler-warning:

[WARNING] warning: While parsing annotations in C:\path\MyTrait.class, could not find NAME in enum <none>.
[INFO] This is likely due to an implementation restriction: an annotation argument cannot refer to a member of the annotated class (SI-7014).




This was not an issue with Scala 2.11


Best regards,
Morten Kjetland


Lukas Rytz

unread,
Nov 25, 2016, 3:10:09 AM11/25/16
to scala-i...@googlegroups.com
Hi Morten

Thanks for the report. Could you provide exact instructions how to reproduce?
I put this on my classpath and changed your example a little, and it compiles without warnings for me:

import com.fasterxml.jackson.annotation.JsonTypeInfo.{As, Id}
import com.fasterxml.jackson.annotation.{JsonSubTypes, JsonTypeInfo}
import JsonSubTypes.Type // <<< added import

@JsonTypeInfo(
  use = JsonTypeInfo.Id.NAME,
  include = JsonTypeInfo.As.PROPERTY,
  property = "type")
@JsonSubTypes(Array(
  new Type(value = classOf[Object], name = "add"),   // <<< changed to Object
  new Type(value = classOf[Object], name = "remove") // <<< changed to Object
))
trait MyTrait {
  def someProperty: String
}

Thanks: Lukas


--
You received this message because you are subscribed to the Google Groups "scala-internals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-internals+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Morten Kjetland

unread,
Nov 25, 2016, 4:12:53 AM11/25/16
to scala-internals
Thanks for looking into it.

I'm seeing the warning both when compiling in IntelliJ 2016.3 and with maven using this plugin:

<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<scalaVersion>${scala.version}</scalaVersion>
<args>
<arg>-deprecation</arg>
<arg>-feature</arg>
</args>
</configuration>
<executions>
<execution>
<id>scala-compile-first</id>
<phase>process-resources</phase>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>scala-test-compile</id>
<phase>process-test-resources</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>doc-jar</goal>
</goals>
</execution>
</executions>
</plugin>
To unsubscribe from this group and stop receiving emails from it, send an email to scala-interna...@googlegroups.com.

Alan Stewart

unread,
Dec 12, 2016, 8:17:31 PM12/12/16
to scala-internals

Hi,
I also see the same warnings using 2.12.1 and Jackson 2.8.4 with:

@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type")
@JsonSubTypes(Array(
new Type(value = classOf[TagObject], name = "tag"),
new Type(value = classOf[CommitObject], name = "commit"),
new Type(value = classOf[BlobObject], name = "blob")))
sealed trait TypedObject extends GitHubRef

and same compiler plugin configuration

Jason Zaugg

unread,
Dec 12, 2016, 8:24:35 PM12/12/16
to scala-internals
It would be a great help if you could produce a standalone project that we could clone to investigate further.

-jason

Reply all
Reply to author
Forward
0 new messages