Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Nikita Gazarov
    @raquo
    Anton Sviridov
    @keynmol
    coursier is exceptional for a lot of things, and that's what ammonite itself uses internally (not cli, but API) for dependency resolution (and SBT, and Mill)
    Dmitri Priimak
    @priimak
    Got it. Thanks a lot to all.
    Tobias Roeser
    @lefou
    Please push the latest release tag(s) to github
    Kenner Stross
    @kennerstross
    I've run into a very strange problem where I'm suddenly seeing "macro has not been expanded" errors related to macroRW in my companion object. I've seen these before, in various classes that seem to be finicky, but doing a clean and recompile always fixes it. Not this time! I've tried every trick I can think of, but it just won't compile. And there's more strangeness: 1) It's in a class that didn't change; it just started happening for no reason I can identify. 2) It's in a class shared between two modules: my jvm module and my js module. When I compile the jvm module, no problem. When I compile the js module - "macro has not been expanded." Scala 2.13.3, upickle 1.1.0 Has anyone run into this?
    Ok, maybe the file did change (I need to check), but all the other issues/descriptions remain true. I'm stuck.
    Kenner Stross
    @kennerstross
    Update - yes, I did indeed add a field to that class, and that field had a default value. When I removed the default, it started working again. Is a default value a no-no with upickle? Why only a problem with the js module?
    Dmitri Priimak
    @priimak

    Hi All. I see that for release 0.5.1 there is a following note:

     ujson.write now takes an optional `sortKeys` flag, if you want the JSON dictionaries to rendered in a standardized order 

    That flag sortKeys disappeared in the very next release and I do not see in there any notes wrt. removal of that flag. What is now a correct way of serializing map with a specific order for keys? And does such feature exists now?

    Anton Sviridov
    @keynmol

    Quick one - I can see that upickle (and its deps, down to geny) are not published for SJS on 3.0.0-M3 - is there a reason? Not seeing an issue on geny.

    Or is it something that needs to be contributed?

    jodersky
    @jodersky
    What version are you using?
    oh, sorry I saw you mentioned ScalaJS
    Anton Sviridov
    @keynmol
    yep, doesn't seem to be there
    upickle-core_3.0.0-M3/                                           -         -      
    upickle-core_native0.3_2.11/                                     -         -      
    upickle-core_native0.4.0-M2_2.11/                                -         -      
    upickle-core_native0.4_2.12/                                     -         -      
    upickle-core_native0.4_2.13/                                     -         -      
    upickle-core_sjs0.6_2.11/                                        -         -      
    upickle-core_sjs0.6_2.12/                                        -         -      
    upickle-core_sjs0.6_2.13/                                        -         -      
    upickle-core_sjs0.6_2.13.0-M5/                                   -         -      
    upickle-core_sjs1.0-RC2_2.12/                                    -         -      
    upickle-core_sjs1.0-RC2_2.13/                                    -         -      
    upickle-core_sjs1_2.12/                                          -         -      
    upickle-core_sjs1_2.13/                                          -         -
    jodersky
    @jodersky
    I didn't know that ScalaJS was already available for 3
    if so, I think it's only a matter of changing the build files an publishing
    there's no technical reason they aren't published for ScalaJS. Just an oversight
    Anton Sviridov
    @keynmol
    Ok cool :+1: if no one else gets to it, I will. SJS was "100% supported" by M2, according to Sebastiene's release notes :)
    My yak shaving tool has my work cutout for a couple of days :D
    ? Here's a list of actions you need to do (in this order)
    * [ ] you'll need to publish com.lihaoyi:geny for 3.0.0-M3 (Scala.js)
    * [ ] you'll need to publish com.lihaoyi:upickle-core for 3.0.0-M3 (Scala.js)
    * [ ] you'll need to publish com.lihaoyi:upack for 3.0.0-M3 (Scala.js)
    * [ ] you'll need to publish com.lihaoyi:upickle-implicits for 3.0.0-M3 (Scala.js)
    * [ ] you'll need to publish com.lihaoyi:ujson for 3.0.0-M3 (Scala.js)
    * [ ] you'll need to publish com.lihaoyi:upickle for 3.0.0-M3 (Scala.js)
    jodersky
    @jodersky
    it's unfortunate that I didn't see this message a couple of hours earlier. I just submitted a bunch of PRs to upgrade to Scala 3.0.0-RC1
    but I reckon that the JS changes can be added on top
    Anton Sviridov
    @keynmol
    That'd be awesome :+1: Unless it breaks the build and is hard to fix, in this case don't bother and I will add it myself (I looked at the build, should be a one-liner)
    Brian Stern
    @realbrianstern

    Hey! I'm getting an error trying to read a ujson.Value into a case class. I'm getting the following error:

    Caused by: java.util.NoSuchElementException: None.get
            at scala.None$.get(Option.scala:627)
            at scala.None$.get(Option.scala:626)
            at upickle.AttributeTagged$$anon$4.visitEnd(Api.scala:240)
            at upickle.core.TraceVisitor$$anon$1.visitEnd(TraceVisitor.scala:122)
            at ujson.AstTransformer.transformObject(AstTransformer.scala:21)
            at ujson.AstTransformer.transformObject$(AstTransformer.scala:14)
            at ujson.Value$.transformObject(Value.scala:131)
            at ujson.Value$.transform(Value.scala:197)
            at ujson.Value$.transform(Value.scala:131)
            at ujson.AstTransformer.$anonfun$transformArray$1(AstTransformer.scala:11)
            at ujson.AstTransformer.$anonfun$transformArray$1$adapted(AstTransformer.scala:11)
            at scala.collection.IterableOnceOps.foreach(IterableOnce.scala:553)
            at scala.collection.IterableOnceOps.foreach$(IterableOnce.scala:551)
            at scala.collection.AbstractIterable.foreach(Iterable.scala:920)
            at ujson.AstTransformer.transformArray(AstTransformer.scala:11)
            at ujson.AstTransformer.transformArray$(AstTransformer.scala:9)
            at ujson.Value$.transformArray(Value.scala:131)
            at ujson.Value$.transform(Value.scala:196)
            at ujson.Value.transform(Value.scala:113)
            at ujson.Value.transform$(Value.scala:113)
            at ujson.Arr.transform(Value.scala:256)
            at upickle.Api.$anonfun$read$1(Api.scala:37)
            at upickle.core.TraceVisitor$.withTrace(TraceVisitor.scala:21)
            at upickle.Api.read(Api.scala:37)
            at upickle.Api.read$(Api.scala:36)
            ...

    I've been searching everywhere to see if this sort of thing has been encountered before, and looking at the lines referenced in the stack trace hasn't shed any light. Does anyone know what might cause this failure?

    Brian Stern
    @realbrianstern
    Digging deeper, it seems that when the class I'm reading into extends a trait/abstract class of any kind, that error arises, but when it extends nothing, it works. That
    That's bizarre, isn't it?
    jodersky
    @jodersky
    It's difficult to diagnose without more info. What Scala version is this for, 2 or 3? Can you show a minimal example that causes this error?
    Li Haoyi
    @lihaoyi
    @realbrianstern @jodersky I think the issue is that if your case class inherits from a sealed trait, uPickle assumes it has a $type field that tags it to confirm when concrete class to deserialize it as
    Brian Stern
    @realbrianstern

    True, sorry, should have provided some code and context! We're on Scala 2.13.3. @lihaoyi that's exactly it, extending a sealed trait.

    import upickle.default._
    
    sealed trait TestTrait
    
    final case class Spot(name: String) extends TestTrait
    
    implicit val spotReader: Reader[Spot] = macroR
    
    val spot = """{"name": "TEST"}"""
    
    read[Spot](spot)

    We've been keeping our case class definitions separate from our reader definitions, as we prefer to keep the latter closer to our API-wrapping logic. Thus, we're not defining them in the companion object. Would that fix it, and is there any other way to do it separately from the definition of the case class? At this point we're preparing to manually write mappings from Js.Value to our case classes. We love the ujson AST, but we'll forego macroR if it denies us some of our flexibility.

    Li Haoyi
    @lihaoyi
    @realbrianstern it could probably be fixed in upickle, but yeah for now using ujson.readwriter[ujson.Value].bimap might tide you over
    @/all uPickle 1.3.0 is out
    Brian Stern
    @realbrianstern
    @lihaoyi That's fair, thanks for the assist!
    Mo Be
    @kiviuk
    
    import upickle.default.{ ReadWriter => RW, macroRW }
    
    object BrandEntity {
    
      final case class Brand(id: Option[BrandID], value: BrandValueObject)
    
      final case class BrandID private (url: String)
      final case class BrandValueObject private (name: Option[BrandName], country: Option[Country])
    
      final case class BrandName private (name: String)
      final case class Country private (country: String)
    
      case class RawBrand(pageUrl: String, brandName: String, country: String)
    
      // https://stackoverflow.com/questions/27941585/pattern-matching-to-check-if-string-is-null-or-empty
      // vs
      // https://youtu.be/BIt3jLLGY0s?t=729 (https://github.com/lutzh/pattern-matching-talk/blob/master/pattern-matching.txt)
      // vs
      // https://riptutorial.com/scala/example/3434/unapply---custom-extractors
    
      object Brand {
        implicit val rw: RW[Brand] = macroRW
        def apply(rawBrand: RawBrand): Brand = {
          Brand(BrandID(rawBrand.pageUrl), BrandValueObject(rawBrand.brandName, rawBrand.country))
        }
      }
    
      object BrandID {
        implicit val rw: RW[BrandID] = macroRW
        // hide default ctor
        private[this] def apply() = None
    
        private[this] def unapply(url: String): Option[String] = if (url == null || url.trim.isEmpty) None else Some(url)
    
        def apply(url: String): Option[BrandID] = {
          url match {
            case BrandID(url) => Some(new BrandID(url))
            case _ => None
          }
        }
      }
    
      object BrandValueObject {
        implicit val rw: RW[BrandValueObject] = macroRW
        // hide default ctor
        private[this] def apply() = new BrandValueObject(None, None)
    
        private[BrandEntity] def isEmpty(value: String) = (value == null || value.trim.isEmpty)
    
        def apply(name: String, country: String) = {
          (name, country) match {
            case (name, country) if (isEmpty(name) && isEmpty(country)) => new BrandValueObject(None, None)
            case (name, country) if (isEmpty(name)) => new BrandValueObject(None, Some(Country(country)))
            case (name, country) if (isEmpty(country)) => new BrandValueObject(Some(BrandName(name)), None)
            case _ => new BrandValueObject(Some(BrandName(name)), Some(Country(country)))
          }
        }
      }
    
      object BrandName {
        implicit val rw: RW[BrandName] = macroRW
        // hide default ctor
        private[BrandEntity] def apply() = new BrandName("")
        private[BrandEntity] def apply(name: String) = new BrandName("")
      }
    
      object Country {
        implicit val rw: RW[Country] = macroRW
        // hide default ctor
        private[BrandEntity] def apply() = new Country("")
        private[BrandEntity] def apply(name: String) = new Country("")
      }
    }
    [error] ...../01-entities/src/main/scala/de/mobe/scraper/entities/Brand.scala:31:36: type mismatch;
    [error]  found   : Option[de.mobe.scraper.entities.BrandEntity.BrandID]
    [error]  required: de.mobe.scraper.entities.BrandEntity.BrandID
    [error]     implicit val rw: RW[BrandID] = macroRW
    Hi can you please help me straighten this out. Maybe I'm missing sth. Thanks a lot!
    1 reply
    scalway
    @scalway

    @kiviuk I guess upickle.default.macroRW macro is trying to use BrandId.apply method to instantiate BrandID but it returns different type (Option[BrandID] instead of BrandID). You can provide proper apply method that blows when data is invalid :(.

    https://scalafiddle.io/sf/IQ7aEAJ/0

    moonpatroller
    @moonpatroller
    Should I not call write inside of bimap to serialize something?
    How do fix this so the second array element isn't output with the extra quotes around it? https://scalafiddle.io/sf/A99Oiqp/0
    implicit val rw: ReadWriter[charData] =
        readwriter[ujson.Value].bimap[charData](
            charData => 
                ujson.Arr(
                    charData.num,
                    write(charData.address),
    ...
    How do I fix that so the second array element doesn't have extra quotes in the output?
    scalway
    @scalway
    @moonpatroller please make it compile and then share it. Please :)
    And yes: you should not use write inside definition of any ReadWrite value.
    moonpatroller
    @moonpatroller
    @scalway Then what should I use?
    charData.address has its own implicit macroRW
    What's the recommended way to convert that into a ujson.Value?
    moonpatroller
    @moonpatroller
    scalway
    @scalway
    @moonpatroller https://scalafiddle.io/sf/A99Oiqp/2 You should use writeJS I guess. It serialize your Address to ujson's AST. I've propose also Reader implementation :)
    moonpatroller
    @moonpatroller
    thanks
    @scalway That should be in that main blog! And is there a real API page, apart from the blog?
    Mo Be
    @kiviuk
    @scalway thanks, I tried using the sealed abstract case class to make the primary ctor and the copy method unavailable but it got even stranger
    https://scalafiddle.io/sf/HXoRiD6/0
    ScalaFiddle.scala:31: error: The referenced trait [[BrandID]] does not have any sub-classes. This may happen due to a limitation of scalac (SI-7046). To work around this, try manually specifying the sealed trait picklers as described in http://www.lihaoyi.com/upickle/#ManualSealedTraitPicklers
          implicit val rw: RW[BrandID] = macroRW
                                         ^
    ScalaFiddle.scala:40: error: class BrandID is abstract; cannot be instantiated
              case BrandID(url) => Some(new BrandID(url))
                                        ^
    scalway
    @scalway
    @kiviuk don't know why you need this abstractthere