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

java.lang.IllegalArgumentException: argument type mismatch #127

Closed
plokhotnyuk opened this issue Apr 5, 2019 · 12 comments
Closed

java.lang.IllegalArgumentException: argument type mismatch #127

plokhotnyuk opened this issue Apr 5, 2019 · 12 comments

Comments

@plokhotnyuk
Copy link
Contributor

Code to reproduce:

import com.dslplatform.json.{DslJson, DslJsonScala}

case class V(
              text: String,
              value: Int)

case class ES(
               distance: V,
               duration: V,
               status: String)

case class RS(elements: IndexedSeq[ES])

case class DM(
               destination_addresses: IndexedSeq[String],
               origin_addresses: IndexedSeq[String],
               rows: IndexedSeq[RS],
               status: String)


val dslJson = new DslJson[Any](Settings.withRuntime().`with`(new ConfigureScala))
val dslJsonScala = new DslJsonScala(dslJson)
val decoder = dslJsonScala.decoder[DM]
val reader = dslJson.newReader()
val bytes = "{\"destination_addresses\":[],\"origin_addresses\":[],\"rows\":[],\"status\":\"OK\"}".getBytes
reader.process(bytes, bytes.length)
reader.read()
println(decoder.read(reader))
@zapov
Copy link
Member

zapov commented Apr 6, 2019

I'm unable to reproduce this ;(

I pasted your code as is into the Scala example at: https://github.com/ngs-doo/dsl-json/blob/master/examples/Scala/src/main/scala/com/dslplatform/json/example/Example.scala and test, but it worked both times.

Which Java/Scala versions are you using?

@plokhotnyuk
Copy link
Contributor Author

I think it doesn't not depend on Java/Scala version... Just need to uncomment this line, it's implementation here, and run the test.

Top of the stack trace:

argument type mismatch
java.lang.IllegalArgumentException: argument type mismatch
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at com.dslplatform.json.runtime.ScalaClassAnalyzer$$anon$1.apply(ScalaClassAnalyzer.scala:318)
	at com.dslplatform.json.runtime.ScalaClassAnalyzer$$anon$1.apply(ScalaClassAnalyzer.scala:317)
	at com.dslplatform.json.runtime.ImmutableDescription.finalChecks(ImmutableDescription.java:147)
	at com.dslplatform.json.runtime.ImmutableDescription.read(ImmutableDescription.java:87)
	at com.dslplatform.json.runtime.ArrayBufferDecoder.read(ArrayBufferDecoder.scala:24)
	at com.dslplatform.json.runtime.ArrayBufferDecoder.read(ArrayBufferDecoder.scala:8)
	at com.dslplatform.json.runtime.ScalaClassAnalyzer$WriteCtor.read(ScalaClassAnalyzer.scala:407)
	at com.dslplatform.json.runtime.ImmutableDescription.read(ImmutableDescription.java:82)
	at com.github.plokhotnyuk.jsoniter_scala.benchmark.DslPlatformJson$.dslJsonDecode(DslPlatformJson.scala:57)
	at com.github.plokhotnyuk.jsoniter_scala.benchmark.GoogleMapsAPIBenchmark.readDslJsonScala(GoogleMapsAPIBenchmark.scala:34)
	at com.github.plokhotnyuk.jsoniter_scala.benchmark.GoogleMapsAPIBenchmarkSpec.$anonfun$new$2(GoogleMapsAPIBenchmarkSpec.scala:10)

@zapov
Copy link
Member

zapov commented Apr 6, 2019

I see that it complains about argument signature (ArrayBuffer vs IndexedSeq)
but I was unable to reproduce the issue locally ;(

It should work now in your benchmark with latest commit: 8b74480

@plokhotnyuk
Copy link
Contributor Author

plokhotnyuk commented Apr 6, 2019

May it be due this workaround which was required to get encoders for arrays of primitives?

@zapov
Copy link
Member

zapov commented Apr 6, 2019

The link is not working, but I figured out that it was not working because the failing test was using immutable.IndexedSeq while just IndexedSeq works.
I was not aware of this problem with array of primitives, fixed it now.

Released a new version, hopefully everything should work now :)

@plokhotnyuk
Copy link
Contributor Author

plokhotnyuk commented Apr 6, 2019

Thanks a lot!

I have removed that "workaround" and now the benchmark for Google Maps API parses DistanceMatrix without errors.

But the same exception throws now in the TwitterAPIBenchmark.readDslJsonScala benchmark.

@zapov
Copy link
Member

zapov commented Apr 6, 2019

:(
I added support for immutable Seq

Also I see that it's "failing" on the write test due to encoding empty collections. You can avoid that by using .skipDefaultValues(true) during config, but this will also omit other default properties, such as Boolean and other primitives.

@zapov
Copy link
Member

zapov commented Apr 6, 2019

Actually no, this does not work yet in Scala ;(

@zapov
Copy link
Member

zapov commented Apr 8, 2019

v1.9.3 released

@plokhotnyuk
Copy link
Contributor Author

Thank you! I will try it tomorrow.

BTW, what do you think about merging of Java and Scala projects to the one multi-project with the same version, and setting up a release automation by the git tag?

Here is an example how it can be done by sbt. Possible it is also can be automated by gradle or maven plugins ...

@zapov
Copy link
Member

zapov commented Apr 9, 2019

Yes, that would be nice but it would need to be Maven instead of SBT ;(
While SBT is much more powerful, it's foreign to most Java devs.

I didn't want to invest time in looking up how to setup Scala project with Maven ;( But I would prefer it was setup that way.

@plokhotnyuk
Copy link
Contributor Author

I have tested with v1.9.3

No more java.lang.IllegalArgumentException: argument type mismatch.

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