question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

A Combination of Lists, Case Classes and Tuples does not compile.

See original GitHub issue

A simple combination of Lists, Cases Classes and Tuples does not compile. I see no reason, why it shouldn’t work. I minimized the example as far as i could. Note that it compiles when we remove one of the lists or change the tuple-type to a single Double or a Case Class.

  case class A(fills: List[B])
  case class B(stops: List[(Double,Double)])

  boopickle.Unpickle[A].fromBytes(null.asInstanceOf[ByteBuffer])

compileroutput with boopickle 1.0.0:

[error] C:\Users\florian.kirmaier\Dropbox\git\file.scala:32: Can
not materialize pickler for non-case class: scala.collection.immutable.List
[error]   boopickle.Unpickle[A].fromBytes(null.asInstanceOf[ByteBuffer])
[error]                     ^
[error] one error found
[error] (scalaServer/compile:compile) Compilation failed
[error] Total time: 59 s, completed Jun 23, 2015 11:52:35 AM

Issue Analytics

  • State:open
  • Created 8 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
XuJiawancommented, Jan 20, 2019

Thanks to @cornerman and @ochrons ! There is a perfect solution for this problem now!! Just simply add boopickle-shapeless to your project!!

This is the code for the test above:

import boopickle.Default._
import java.nio.ByteBuffer

case class A(fills: List[B])
case class B(stops: List[(Double,Double)])

object Test {
  def deserializer() = {
    Unpickle[A].fromBytes(null.asInstanceOf[ByteBuffer])
  }
}

It’ll return the complication error:

Cannot materialize pickler for non-case class: List[com.try-boopickle.test.B]. If this is a collection, the error can refer to the class inside.

To solve it, add this to scala project:

"io.suzaku" %% "boopickle-shapeless" % "1.3.0"

And then simply change import boopickle.Default._ to import boopickle.shapeless.Default._!

More details in #89 and codes are here.

0reactions
steinybotcommented, Feb 17, 2021

I encountered this when doing some refactoring. All I did was to remove a type parameter from something so it was looking for Pickler[Thing[A]] instead of Pickler[Thing[_, A]]. My guess is that the existential type was somehow preventing the implicit divergence although I haven’t been able to replicate that.

The workaround in my case was to hide the iterablePickler and the mapPickler:

import boopickle.Default.{iterablePickler => _, mapPickler => _, _}

Then explicitly declare the collections I need:

  private implicit def setPickler[A: Pickler]: Pickler[Set[A]] = boopickle.Default.iterablePickler[A, Set]
  private implicit def listPickler[A: Pickler]: Pickler[List[A]] = boopickle.Default.iterablePickler[A, List]

I feel like there is more to this bug than just it being a “known limitation of the macro/implicit system”. I’ve never encountered so many weird cases where this bug pops up with other libraries. There are tons of tiny little things that either make this error appear or go away. It is definitely related to higher-kinded types but there are also some other oddities in there too.

You can see a bunch of things I found here https://gist.github.com/steinybot/e8710f6ff40379bf2d0f2767b5784fd4.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Convert an Option of a case class into a tuple of its elements
1 Answer 1 ... The simple answer to your question is "no", your code is pretty much as good as it gets. Scala...
Read more >
Tuples bring generic programming to Scala 3
HLists and case classes can both be used to define products of types. However HLists do not require the developer to declare class...
Read more >
itertools — Functions creating iterators for efficient looping ...
The combination tuples are emitted in lexicographic ordering according to the order of the input iterable. So, if the input iterable is sorted,...
Read more >
9. Objects, Case Classes, and Traits - Learning Scala [Book]
The scala command will execute the contents of your file as if they were entered in a REPL, but you don't end up...
Read more >
Python Tuples Tutorial - DataCamp
Tuples versus Lists · You can't add elements to a tuple because of their immutable property. · You can't remove elements from a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found