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 12:25
    justdoit0823 starred json4s/json4s
  • Jan 30 11:05
    ericxsun commented #212
  • Jan 26 13:29

    seratch on v3.6.4

    (compare)

  • Jan 26 13:28

    seratch on 3.6

    version 3.6.4 Start 3.6.5 dev (compare)

  • Jan 26 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 12:53
    seratch closed #582
  • Jan 26 12:39
    seratch synchronize #582
  • Jan 26 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 12:39
    seratch closed #581
  • Jan 26 12:38
    seratch synchronize #582
  • Jan 26 12:38
    seratch opened #582
  • Jan 26 12:30
    seratch synchronize #581
  • Jan 26 12:30

    seratch on 3.6

    Add 3.6.3 to previous versions … (compare)

  • Jan 26 12:25

    seratch on master

    Reduced OrElse objects allocati… (compare)

  • Jan 26 12:25
    seratch closed #580
  • Jan 26 12:25
    seratch closed #579
  • Jan 26 12:25
    seratch commented #580
  • Jan 26 11:03
    poslegm commented #580
  • Jan 26 10:56
    poslegm synchronize #580
  • Jan 26 10:32
    seratch commented #580
Vamsi Ampolu
@vamsiampolu
Is it possible to serialize a json input to a custom xml using the toXml format based on a serializer of some sort?
I have a custom namespace to be added to my XML, I can do it using the scala-xml using toXML functions all over the place but can it be done using a json4s serializer or a similar objectr
samuelsayag
@samuelsayag
Hi all, I am searching how to compare my json document for equality (same data beyond the order notion) with json4s. I do not intend to multiply my dependencies on json libraries so would like to do this with json4s. I have compared to basic json array but yield false. Any idea how to do that ?
import org.json4s.native.JsonMethods._
 case class A(i:Int)
 import org.json4s.native.Serialization
import org.json4s.native.Serialization._
 val l1 = (1 to 10) map (i => A(i))
 val l2 = (1 to 10).reverse.map (i => A(i))
 implicit val formats = Serialization.formats(NoTypeHints)
Extraction.decompose(l1) == Extraction.decompose(l2)
Anthony Garo
@agaro1121

hey guys
just a quick question about syntax
for { JObject(fields) <- parse(“some json string”) … yield (...)

How is the generator syntax working here? I don’t see a flatMap on the JValue

Tom Lous
@TomLous
Hi maybe a dumb question, but I couldn't find an answer:
How should I use TypeTags instead of Manifests with json4s (since Manifests are deprecated)
eg with this function that converts json to case classes
def decode[T: Manifest](jsonStr: String): T = {
  parse(jsonStr).extract[T]
}
Tom Lous
@TomLous
Are there plans to move away from Manifests btw?
Anthony Garo
@agaro1121
hey guys does json4s support deserializing sealed traits?
samuelsayag
@samuelsayag

Hi all, I have the following problem that a guy already had in stackoverflow (https://stackoverflow.com/questions/23423774/json4s-jackson-does-not-serialize-properties-of-the-superclass) but could'nt solve it either:

  abstract class A(s: String, i: Int)

  case class B(l: Long) extends A("my A", 0)

The automatic serialization give me just the field of the B class. I have written a custom serializer
of B and add it to the format but it does not take it when serializing a B.

Andriy Plokhotnyuk
@plokhotnyuk
@samuelsayag have you tried with case class B(l: Long, s: String = "my A", i: Int = 0) extends A(s, i) ?
samuelsayag
@samuelsayag
@plokhotnyuk Thanks for answering. I don't want to change the signature of my class. I want a way for the automatic serialization of a case class in json4s to take a super abstract class
Ariel Kogan
@arikogan

Hi guys,
I’m using a for comprehencion that looks more or less like the below,

for {
    JObject(candle) <- json
    JField(“Delay", JDouble(delay)) <- candle
} yield delay

The thing is that the value of Delay sometimes is 0 instead of 0.123 and the for comprehension doesn’t match it. Any ideas of how to tackle it right?

Thanks!

Manu Zhang
@manuzhang
Hi all, is there any updates on this type alias issue json4s/json4s#397 (and several similar issues) ?
Emil Dafinov
@EmilDafinov
Hello everybody, I have a rather noob question: is it possible to set up JSON4s so that it always fails the deserialization if the value of a required field is null?
I see that Formats has an allowNull field, is that what controls this behavior?
Emil Dafinov
@EmilDafinov
Ideally I would like to define that in the Formats, since I am using akka-http-json and I'm not calling parse / extract from my code
Yadu Krishnan
@yadavan88
Hello All, I am facing an issue with json conversion. Have posted as an issue in github and SO, but didn't get any response.

Here is the link to my question, can anyone help me ? json4s/json4s#548 and https://stackoverflow.com/questions/52325532/scalasig-exception-on-fieldserializer-with-typetag

I am getting ScalaSig error after upgrading to scala 2.12

monksy
@monksy
Is there any way to add in a formatter to modify the way a value is serialized?
I've got a case class that holds a boolean and it needs to output True or False upon it's value
I'm not sure how to customize just that one's behavior
monksy
@monksy
just did that with a custom serializatn
Francisco Albert Albusac
@tatitati
people, I want to serialize an object, the object include some dates. Is there any warkaround to specify the format of the dates when serializing? (if possible not forcing me to speicify the whole json conversion field by field)
Francisco Albert Albusac
@tatitati
someone here?
I was strugling for more than expected with this library........
Francisco Albert Albusac
@tatitati
I have this test, which is giving me a json that I don't want
class ToJsonSpec extends FunSuite {

  class GivenClassWithDate(val firstName: String, val mydatetime: DateTime)

  test("asdf") {

    val hints = new ShortTypeHints(classOf[DateTime] :: Nil) {
      override def serialize: PartialFunction[Any, JObject] = {
        case t: DateTime => JObject(JField("mydatetime", JString(t.toString)) :: Nil)
      }

      override def deserialize: PartialFunction[(String, JObject), Any] = {
        case ("DateTime", JObject(JField("mydatetime", JString(t)) :: Nil)) => new DateTime(t)
      }
    }

    implicit val formats = native.Serialization.formats(hints)

    val sample = new GivenClassWithDate(firstName = "Francisco", mydatetime = DateTime.now())

    println(Serialization.writePretty(sample))
  }
}
The resulting json is this:
{
  "firstName":"Francisco",
  "mydatetime":{
    "jsonClass":"DateTime",       <----------------------------- I DONT WANT THIS FIELD and this nested structure
    "mydatetime":"2019-02-20T22:19:14.511Z"
  }
}
Also I didn't see this documented in the readme.md, and in the Specs in the code, I was having a look into the examples, and this field is not reflected in any test, so likely someone else is having the same surprise than me
Francisco Albert Albusac
@tatitati
OK, thanks guys, my team decided to use other library
Andriy Plokhotnyuk
@plokhotnyuk
@tatitati please share which one and for solving of which challenges...
Sam Smoot
@sam
Hello, I was curious if json4s ever made any progress on a typeclass interface for serializers? I thought there was some code for it in the project, but was looking for it the other day and couldn’t find it. Was it removed/abandoned?
Sam Smoot
@sam
@dozed It looks like we chatted about that back in 2016 ^^^ Is that still a goal?
samuelsayag
@samuelsayag

hello, I have a little problem extracting json from a recursive structure. I have different type of Nodes all inheriting from a Node abstract class such as:

  abstract class Node {
    val nodeType: Int
    val id: Option[String]
    val parentNode: Option[String]
    val nextSibling: Option[String]
  }

  final case class Node1(id: Option[String],
                         parentNode: Option[String],
                         nextSibling: Option[String],
                         tagName: String,
                         attributes: Option[List[Attribute]],
                         childNodes: Option[List[Node]])
      extends Node {
    val nodeType = 1
  }

and I had to write a custom ser/unser for this. But when I test the extraction, it does not extract recursively the childNodes (see field of the Node1 case class). Here is the serializer I wrote:

    implicit val f: Formats = DefaultFormats + Attribute.serListAttr
    val serNode = new CustomSerializer[Node](format =>
      ({
        case jo @ JObject(fields) if (jo \ "nodeType") != JNothing && (jo \ "nodeType") != JNull =>
          (jo \ "nodeType").extract[Int] match {
            case 1  => jo.extract[Node1]
            case 3  => jo.extract[Node3]
            case 8  => jo.extract[Node8]
            case 11 => jo.extract[Node11]
          }
      }, {
        case n: Node1  => decompose(n) merge decomposeNode(n.asInstanceOf[Node])
        case n: Node3  => decompose(n) merge decomposeNode(n.asInstanceOf[Node])
        case n: Node8  => decompose(n) merge decomposeNode(n.asInstanceOf[Node])
        case n: Node11 => decompose(n) merge decomposeNode(n.asInstanceOf[Node])
      }))

    import org.json4s.JsonDSL._
    private def decomposeNode(n: Node) =
      ("nodeType"     -> n.nodeType) ~ ("nextSibling" -> n.nextSibling) ~
        ("parentNode" -> n.parentNode) ~ ("id"        -> n.id)

Does somebody could give me an explanation about the way to extract recursive structure ? Thanks

jrciii
@jrciii
How would I go about supporting :: aka $colon$colon$ aka Scala's native nonempty list?
I tried writing a generic custom serializer but now all my nested case classes turned into maps :/
jrciii
@jrciii
class DoubleColonSerializer[A](formats: Formats = DefaultFormats)(implicit m: Manifest[A]) extends CustomSerializer[::[A]]({ _ =>
  implicit val f = formats
  ({
    case jArr: JArray =>
      val l = jArr.extract[List[A]]
      ::(l.head, l.tail)
  },{
    case nel: ::[A] =>
      JArray(nel.map(Extraction.decompose))
  })
})
implicit val formats =
      DefaultFormats +
        new DoubleColonSerializer[Any]
Seems to turn any case class in a :: into an object. Wonder if Im missing a special function instead of extract/decompose
jrciii
@jrciii
I and the deserialized value's class is the same as the final type, but the deserialized object's inner fields are maps where they should be case classes... what sorcery is this? Both the expected and actual class == each other but they have different fields!
Maybe case classes actually are maps?
jrciii
@jrciii
So I had to write a second custom serializer that can use the generic serializer for decompose, but I had to write the extract part painstakingly by had D:
Gear-bao
@Gear-bao
have anyone have face the trouble that merge is invaild
jsonObj1 merge jsonOb2 just return jsonOb2
violence102
@violence102
hello, is there a way to set in my CustomSerializer strictOptionParsing to true?
I have Formats that came in the constructor CustomSerializerSomeType => implicit val f: Formats = format ...
is there a way to change strictOptionParsing in the taken format somehow?
violence102
@violence102
like i.e. DoubleColonSerializer above I would like that the local val f = formats will have a strict option parsing enabled
fromscalatohaskell
@fromscalatohaskell_gitlab
Is there a way to tell json4s to ignore some class completely? I'm getting cant find scalasig err
belgacea
@belgacea
Hello, do anyone know where I could find the documentation ? The website looks down..
Jonas Natten
@jnatten
Anyone has any idea why my deserialization breaks when going from json4s 3.5.5 to 3.6.x?
I just use read[LearningPath](jsonString) in my constructor to deserialize and the LearningPath type is defined like this: http://scalikejdbc.org/documentation/one-to-x.html
stacktrace -> https://hastebin.com/naxadomano.scala
Jonas Natten
@jnatten
Correction: It breaks from 3.6.0 -> 3.6.1 ^