0

Supposing I have a case class whose members types are Scala/Java that I can't or want to modify, and that are not supported by uPickle default writer/reader. Is there a way to say to upickle how to manage it? To be more clear, let's take an example.

Let's suppose I have these classes:

case class MyClass1 (a:BigInteger, b:BigInteger, c:Int, d:String)
case class MyClass2 (a:BigInteger, b:BigInteger, d:String)

(I know that uPickle can manage BigInt, but supposing that I must use java.math.BigInteger and to complexify that I want to use a hexadecimal representation instead than decimal. (so nb.toString(16) to convert to hexa, and the appropriate constructor to the reverse)

Is there a way to say to say to uPickle reader and writer how to manage BigInteger in a way that it will automatically be used each time a BigInteger occurred? In a way that I don't have to write specific code for each of my classes (MyClass1 and MyClass2).

The uPickle documentation only speaks about "Custom Picklers" for classes that are controlled by the developper. Which is obviously not the case for java.math.BigInteger. The most direct approach would be I suppose to define a custom reader/writer which extend the default provided by uPickle? Unless some implicit conversions can be provided. But I don't see how to do it nor if it is even possible.

ndesmoul
  • 103
  • 6
  • 1
    Define a `Writer[BigInteger]` according to the "Custom Picklers". Then make sure it's in implicit scope higher than the defined by upickle. That's the tricky part. https://stackoverflow.com/questions/8623055/scala-implicit-parameter-resolution-precedence – Reactormonk Mar 20 '17 at 14:15
  • OK. I already did the Writer[BigInteger], but messed up the implicit imports. It is actually quite simple. Thanks a lot. – ndesmoul Mar 20 '17 at 14:42

0 Answers0