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
Wei Zhao
@fishmacs
in querying
Wei Zhao
@fishmacs
Yeah, there is a slice method
Wei Zhao
@fishmacs
I want to query a value as JDouble or JInt
for {
...
JField(“field”, JDouble(field)) <- obj
}
querying failed if field is a int,how do I handle both double and int?
Kazuhiro Sera
@seratch
Pedro Silva
@pedromss
Hello, is there a way to transform an instance of type T into a json tree of type JValue? All I see in the documentation is the direct transformation from instance to string.
Sam Smoot
@sam
@pedromss org.json4s.Extract.decompose(myObject)?
Pedro Silva
@pedromss
I'm using version 3.3.0 and that function caused problems when converting an Object that contained another object which in turn contained a Map. I was hoping to avoid it this time. Will try it again since it's a different context, thx.
Matt Farmer
@farmdawgnation
Hey everyone.
Don’t know how much this room is monitored, but I wanted to bring something to everyone’s attention.
It looks like the json4s native API broke compatibility with lift-json with regard to extracting polymorphic types.
Minimal example forthcoming...
But wanted to flag here in case someone wanted to say “No, there’s some known changed behavior between json4s and lift-json"
marios iliofotou
@imarios

Hi guys, anyone knows if there is a way to extract from a parsed string a class that looks like this?

case class Something(a: Int, b: Long, c: Option[Map[String,Any]])

I know that it has 3 fields but c can be an arbitrary json, so I want to extract what I can and then tread c differently down the road.

Bjørn Rustad
@burk
Hey guys! Is there any reason to believe that the memory footprint of parsing and transforming a large amount of json will be different between json4s.native and json4s.jackson?
Filippo De Luca
@filosganga

Hi Guys, I would like to write a serialiser for a class with a type parameter:

class Foo[T](val t: T)

How is it possible in json4s?

marios iliofotou
@imarios
Hey guys, I create a SO question for what I asked few days, back, let me know if you can help, thanks! http://stackoverflow.com/questions/41709882/json4s-extractor-for-partial-fields-when-we-care-to-preserve-the-original-json
marios iliofotou
@imarios
@mxl thanks for the answer on SO!
marios iliofotou
@imarios
Hi all! is there a way for json4s to give the line causing the syntax error in the stack trace?
Justin Reeves
@justinallenreeves
I'm a novice having some trouble using Json4s to extract a given hit from this json response. First thing first I have to decide on is the right data structure.
{
  "took":2,
  "timed_out":false,
  "_shards":{
    "total":4,
    "successful":4,
    "failed":0
  },
  "hits":{
    "total":3,
    "max_score":0.19245009,
    "hits":[{
      "_index":"production",
      "_type":"listings",
      "_id":"94936767",
      "_score":0.19245009,
      "fields":{
        "status":["Live"]
      }
    }]
  }
}
Reduced that down so there's only one result showing.
Justin Reeves
@justinallenreeves
I got it. Wound up going through it with val hits = (json \ "hits" \ "hits").extract[List[Map[String,JValue]]] then dealing with the hit seperately.
Luis Medina
@lu4nm3

There is a weird issue (or is it expected?) where a numeric value in a JSON keeps getting extracted as a String even though an error should probably get thrown.
As an example, say I have a json string that looks like this:

{
    "test": 3
}

When I go to extract the "test" field from this JSON as a String, I'm expecting it to fail:

def getVal[T: Manifest](json: JValue, fieldName: String): Option[T] = {
    val field = json findField {
      case JField(name, _) if name == fieldName => true
      case _ => false
    }

    field.map {
      case (_, value) => value.extract[T]
    }
}

val json = JsonMethods.parse("""{"test":3}""")
val s: Option[String] = getVal[String](json, "test")  // Some(3)

Is there any way to force a type mismatch to cause this to fail?

Jason Fine
@jasonf20

Hi,

I am wondering about a serialization situation I've encountered. When I have a class which extends another class with the same fields, they get serialized twice. For example:

  abstract class Base(a: Int, b: String) {
    def doSomething(): String = a.toString + b
  }
  case class MyClass(a: Int, b: String) extends Base(a, b)

when serializing an instance of MyClass we end up with the following:
{"a":1,"b":"something","a":1,"b":"something"}

Note: This won't happen if the fields are not used in the base class. I believe this is an issue with how getDecleredFields works, perhaps you want to filter out non-public fields from the super class?

Mark Grey
@DeaconDesperado
Hi friends. I am wondering if there is an easy way to obtain a JValue from a case class if I have a Formats and the necessary typeclasses in scope?
right now im using parse(write(cc)) but that seems a bit silly since it stringifies it and then reparses it
marios iliofotou
@imarios
@DeaconDesperado u r looking for render()
Shivam Sharma
@shivamsharma
does json4s support Either datatype parsing in scala
Sumana Ravikrishnan
@rsumana
Hey guys. I'm getting a error: not found: value JNothing error even after importing import org.json4s._. I'm running it in spark-shell using Scala.
I'm not sure why this error is popping up. Does anyone have an idea?
Justin Reeves
@justinallenreeves
Yo. Trying to deal with the fact that my data is standardized but I do need a Boolean extracted from the common cases. I tried writing a custom serializer in a scala worksheet but it says it can't find the constructor:
import org.json4s._
import org.json4s.native.JsonMethods._
import org.json4s.DefaultFormats
import org.json4s.native.JsonMethods.parse

class LooseBoolean(v: Option[Boolean]) {
  val value = v
}

class LooseBooleanSerializer(trueStrings: Seq[String], falseStrings: Seq[String])
  extends CustomSerializer[LooseBoolean](format => (
  {
    case JBool(x) => new LooseBoolean(Some(x))
    case JString(x) if x != null  => new LooseBoolean(Some(trueStrings.contains(x) || !falseStrings.contains(x)))
    case _ => new LooseBoolean(None)
  },
  {
    case x: LooseBoolean => JBool(x.value.get)
  }
))


val t = Seq("t","T","1","Yes")
val f = Seq("f","F","0","No")

implicit val jsonFormats: Formats = DefaultFormats + new LooseBooleanSerializer(t,f)

val json =
  parse("""{
          |"myInt" : 123,
          |"myDouble" : 123.456,
          |"myWord" : "werd",
          |"myBoolean" : true,
          |"myIntStr": "123",
          |"myDoubleStr": "123.456",
          |"myBooleanTrueStr": "true",
          |"myBooleanFalseStr": "false",
          |"myBoolean_t": "t",
          |"myBoolean_f": "f",
          |"myBoolean_T": "T",
          |"myBoolean_Yes": "Yes",
          |"myBoolean_F": "F",
          |"myBoolean_1": "1",
          |"myBoolean_0": "0",
          |"myNull" : null
          |}""".stripMargin
  )
(json \ "myBoolean").extract[LooseBoolean]
Ross
@breadmenace_twitter
@nonconvergent that actually works for me; can you try it outside a worksheet? I’ve never had much luck debugging json4s issues in an intellij worksheet
Justin Reeves
@justinallenreeves
Okay.
Justin Reeves
@justinallenreeves
@breadmenace_twitter trying putting it inside my scala-test and then just running that just that test and get the same result.
jukwaa1
@jukwaa1
Is there any support for java.timeserialization?
Alexey Novakov
@novakov-alexey
I've used this PR for java.time: json4s/json4s#243
Hanns Holger Rutz
@Sciss
Hi. Quick question - why would I choose native over jackson or the other way around? I want to parse JSON coming in from http via dispatch.
Hanns Holger Rutz
@Sciss

Another question. Parsing dates...

No usable value for created
Invalid date '2017-01-29T14:54:43.792240')

My case class has java.util.Date. How can I fix this?

Alexey Novakov
@novakov-alexey
@Sciss I am not sure, but looks like date value can't be parsed because you are using non-default date format or the overriden format does match to the sample value above.
default is "yyyy-MM-dd'T'HH:mm:ss'Z'"
can't go deeper at the moment, sorry
Justin Potter
@j-potts
Anyone know if it's possible to nest CustomSerializers?
Justin Potter
@j-potts
For example, if I want to create a CustomSerializer for the following:
case class User(
  id: String,
  name: String,
  phoneNumbers: Seq[Phone])
Where both User and Phone have their own custom serializer
But I somehow need to nest the Phone deserializer with the User deserializer
Justin Potter
@j-potts
within*
Balázs Kossovics
@kosii
hello!