Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jan 30 2019 12:25
    justdoit0823 starred json4s/json4s
  • Jan 30 2019 11:05
    ericxsun commented #212
  • Jan 26 2019 13:29

    seratch on v3.6.4

    (compare)

  • Jan 26 2019 13:28

    seratch on 3.6

    version 3.6.4 Start 3.6.5 dev (compare)

  • Jan 26 2019 12:53

    seratch on 3.6

    Reduced OrElse objects allocati… Merge branch '3.6' into pr-580-… Merge branch '3.6' into pr-580-… and 1 more (compare)

  • Jan 26 2019 12:53
    seratch closed #582
  • Jan 26 2019 12:39
    seratch synchronize #582
  • Jan 26 2019 12:39

    seratch on 3.6

    fix Type alias for parameterize… Merge branch '3.6' into pr-577-… Merge pull request #581 from se… (compare)

  • Jan 26 2019 12:39
    seratch closed #581
  • Jan 26 2019 12:38
    seratch synchronize #582
  • Jan 26 2019 12:38
    seratch opened #582
  • Jan 26 2019 12:30
    seratch synchronize #581
  • Jan 26 2019 12:30

    seratch on 3.6

    Add 3.6.3 to previous versions … (compare)

  • Jan 26 2019 12:25

    seratch on master

    Reduced OrElse objects allocati… (compare)

  • Jan 26 2019 12:25
    seratch closed #580
  • Jan 26 2019 12:25
    seratch closed #579
  • Jan 26 2019 12:25
    seratch commented #580
  • Jan 26 2019 11:03
    poslegm commented #580
  • Jan 26 2019 10:56
    poslegm synchronize #580
  • Jan 26 2019 10:32
    seratch commented #580
Stefan Ollinger
@dozed
Ok, I would definitely suggest choosing typeclass-based codecs
Stefan Ollinger
@dozed
Supporting Every[T] with the Formats approach is not trivial
With typeclasses you can declare an implicit def which has the constraint that there needs to be an instance of the typeclass for the "contained" type.
implicit def listJSONW[A: JSONW]: JSONW[List[A]] = new JSONW[List[A]] {
  def write(values: List[A]) = JArray(values.map(x => implicitly[JSONW[A]].write(x)))
}
E.g. like this.
A:JSONW says: there needs to be a JSONW[A]
And then the compiler can do the work
It is a lot clearer
@sam
Sam Smoot
@sam

@dozed How do you actually use the type class support?

> JSONW(User(“bob”, “password”))
res0: JObject(List(JField(“name”, JString(“bob”)), JField(“password”, JString(“password”))))

maybe?

Oh. No. That’s the typeclass. Never mind. Duh. Uhmm. Just write your own decompose[A: JSONW](value: A)?
Is the plan that json4s will have both forms going forward or is the type class one planned to obsolete Formats someday?
Stefan Ollinger
@dozed
A lot of existing code depends on json4s, so I think both forms will co-exist.
There is also not much in the docs yet about the alternatives.
Imo teaching people about Formats is not the most responsible thing
Sam Smoot
@sam
@dozed Hmm… it should be possible to write a CustomSerializer[ T : JSONW ] though actually right? That’s not a crazy idea maybe? And then if you have a JSONW[Every[T]], that could bridge it to your Formats?
Stefan Ollinger
@dozed
If you can get it to work, that would be nice
The fundamental difference is that with Formats the typeclass instances are stored in a list, whereas a standard typeclass approach would declare only dependencies via implicit parameters
Sam Smoot
@sam
I’ll need to figure something out in the next few days for my few cases of Every. I’ll let you know if anything comes of it. Or if I just have to fall-back to a factory method for different variations of def factory[A]() = new CustomerSerializer[Every[A]](…).
Stefan Ollinger
@dozed
And I am working currently here https://github.com/dozed/json4s-drafts/
Here is for example a JSONW/JSONR instance for NonEmptyList (which is similar to Every): https://github.com/dozed/json4s-drafts/blob/master/src/test/scala/TupleMaps1.scala#L19
Stefan Ollinger
@dozed
@sam The typeclasses are basically functions: A => JValue and JValue => Result[A]
Where Result[A] has two possible cases, Success(a) and Failure(errors)
eugene yokota
@eed3si9n
hi
Sam Smoot
@sam
howdy
eugene yokota
@eed3si9n
is there a functional sjson style serializer for json4s that doesn't use reflection?
sort of like sprayjson4s?
Sam Smoot
@sam
Heh. I think we were just talking about that.
Stefan Ollinger
@dozed
Hey
What is sjson style?
Sam Smoot
@sam
(typeclasses?)
eugene yokota
@eed3si9n
Stefan Ollinger
@dozed
Ah right, they have reflection and typeclasses
Sam Smoot
@sam
package services.json.formats

import services.schema.User
import User.Account
import services.schema.User
import spray.json._

object AccountFormat extends RootJsonFormat[Account] {

  import DefaultJsonProtocol._

  implicit val dateTimeFormat = DateTimeFormat

  val format = jsonFormat5(Account.apply)

  def read(value: JsValue) = format.read(value)

  def write(account: Account) = format.write(account)
}
Stefan Ollinger
@dozed
@eed3si9n There are the JSONW[A], JSONR[A] typeclasses in https://github.com/json4s/json4s/tree/3.4/scalaz
Sam Smoot
@sam
I don’t think I’ve seen spray-json use reflection. But I could’ve just missed it.
Stefan Ollinger
@dozed
I am currently working on it a bit here https://github.com/dozed/json4s-drafts
Sam Smoot
@sam
Oh… well, duh. I guess the jsonFormatN helpers must be reflection based.
Stefan Ollinger
@dozed
@sam I referred to sjson
They had two modes
Sam Smoot
@sam
Ah. I read ‘spray’ and confused myself. Nevermind me. :)
eugene yokota
@eed3si9n
yea. I should've been more clear
so it doesn't exist yet, but you guys are thinking about it?
Stefan Ollinger
@dozed
It exists, officially in form of https://github.com/json4s/json4s/tree/3.4/scalaz, but it needs some polishing
eugene yokota
@eed3si9n
i see, but I am guessing that it pulls in Scalaz as dependency
anyfoo. thanks for the info!
Stefan Ollinger
@dozed
Yep, the scalaz dependency might be a problem (dependency size, conflicts)
Sam Smoot
@sam
Pretty sure I just spotted a bug while browsing the code trying to point out why using json4s-native 3.3.x was an issue for another project: https://github.com/json4s/json4s/pull/339/files#r60582054