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
Balázs Kossovics
@kosii
json4s/json4s#339
I'd need this in the other direction, i.e. decoding escaped non-ascii characters from a json string
Balázs Kossovics
@kosii
scala> parse(""""M\xe9ditel"""")
com.fasterxml.jackson.core.JsonParseException: Unrecognized character escape 'x' (code 120)
 at [Source: "M\xe9dit"; line: 1, column: 5]
  at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:1581)
  at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:533)
  at com.fasterxml.jackson.core.base.ParserMinimalBase._handleUnrecognizedCharacterEscape(ParserMinimalBase.java:510)
  at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._decodeEscaped(ReaderBasedJsonParser.java:2208)
  at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._finishString2(ReaderBasedJsonParser.java:1773)
  at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._finishString(ReaderBasedJsonParser.java:1747)
  at com.fasterxml.jackson.core.json.ReaderBasedJsonParser.getText(ReaderBasedJsonParser.java:233)
  at org.json4s.jackson.JValueDeserializer.deserialize(JValueDeserializer.scala:24)
  at com.fasterxml.jackson.databind.ObjectReader._bindAndClose(ObjectReader.java:1511)
  at com.fasterxml.jackson.databind.ObjectReader.readValue(ObjectReader.java:1136)
  at org.json4s.jackson.JsonMethods$class.parse(JsonMethods.scala:25)
  at org.json4s.jackson.JsonMethods$.parse(JsonMethods.scala:55)
  ... 42 elided
is this possible?
ilaerbfkbiiuhbi
@ilaerbfkbiiuhbi
Hey folks, this is probably a very noob question: how can one deserialize a (tagged) union type from JSON? I'm trying to use a sealed class + case class hierarchy and extract[BaseClass], but I'm getting "MappingException: Parsed JSON values do not match with class constructor".
abesanderson
@abesanderson
wondering if anybody can point me in the right direction on something: i have some input that is coming from a mongo source, and there are idiosyncracies that i'm having to handle. one of these is that i get fields in the bson dot notation that really are supposed to be nested json objects. e.g. {"foo.bar":false}. i've add some custom field serializers to turn this into proper documents {"foo":{"bar":5}} but i've just found out that i can possibly get updates to the same nested document {"foo.bar": false, "foo.bash": true} my question is, where would i even look to add something to merge objects like this? i was thinking org.json4s.Extraction might have it
Filippo De Luca
@filosganga

Guys I am writing a custom serializer that need to use another one:

case object TimeWindowFormats extends CustomSerializer[OpeningMeterReadingTimeWindow](format => (
  {
    case obj: JObject =>
      OpeningMeterReadingTimeWindow.Defined((obj \ "from").extract[Instant], (obj \ "to").extract[Instant])
    case JNull => OpeningMeterReadingTimeWindow.Undefined
  },
  {
    case defined: OpeningMeterReadingTimeWindow.Defined =>
      ("from" -> defined.from) ~ ("to" -> defined.to)
    case OpeningMeterReadingTimeWindow.Undefined => JNull
  }
))

this does not compile as defined.from and defined.to are java.time.Instant

How can I reuse or assume the formats contains the serializer for Instant?
Filippo De Luca
@filosganga
Can I use decompose?
jmartell7
@jmartell7
I'm having trouble running the benchmarks.
/code > json4s-benchmark/runMain org.json4s.benchmark.Runner
[info] Running json4s-benchmark org.json4s.benchmark.Runner
[error] Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.io.Closeables.closeQuietly(Ljava/io/Closeable;)V
[error] at com.google.caliper.Runner.measure(Runner.java:301)
[error] at com.google.caliper.Runner.runScenario(Runner.java:229)
[error] at com.google.caliper.Runner.runOutOfProcess(Runner.java:378)
[error] at com.google.caliper.Runner.run(Runner.java:97)
[error] at com.google.caliper.Runner.main(Runner.java:423)
[error] at com.google.caliper.Runner.main(Runner.java:436)
[error] at org.json4s.benchmark.Runner$.main(Runner.scala:7)
[error] at org.json4s.benchmark.Runner.main(Runner.scala)
[info] 0% Scenario{vm=java, trial=0, benchmark=JacksonFullCircle}
java.lang.RuntimeException: Nonzero exit code returned from runner: 1
at scala.sys.package$.error(package.scala:27)
[trace] Stack trace suppressed: run last json4s-benchmark/compile:runMain for the full output.
[error] (json4s-benchmark/compile:runMain) Nonzero exit code returned from runner: 1
[error] Total time: 3 s, completed May 26, 2017 10:37:12 AM
Looks like something with Guava versions maybe?
liondancer
@liondancer
I do not undertand this error at all... construction cannot continue: "org.json4s.JsonAST$JNothing$ cannot be cast to org.json4s.JsonAST$JObject" (IP2GeoTestSuite.scala:50)
MasterInTraining23
@MasterInTraining23
Hi, I'm new to this so I'm not sure if just asking a question is the appropriate approach, but here it goes...I'm having problems testing case class equality after extraction. I found a similar stack overflow question: https://stackoverflow.com/questions/41100738/json4s-breaks-case-class-eqality but it was never answered. I've tried stepping through the debugger but I seem to always get lost. I've been unable to step through the 'equals' or '==' methods of the two objects and when comparing the object fields separately everything is the same. I then thought it had something to do with the class interfaces, like maybe an interface was lost during extraction, but the returned object is still a Product and has all of the same classes as an originally built object. Any help is greatly appreciated! Thank you.
Joshua E. Jodesty
@JEJodesty
how do i write json file with json4s?
Alexander Bjerkan
@alexanbj
Is it possible to create a custom serializer for Option[String]?
In the case of empty strings, I want it to be deserialized into None instead of ending up as Option("")
Jason Dusek
@solidsnack
Consider a file structured like { "Records": [ {Object}, {Object}, ...thousands of objects... ] }
For each {Object} it would be nice to use the AST; but one would like to use the pull-parser to step past "Records" and stream each {Object}.
Is there a way to reform an AST "thing" from pull parser tokens?
Dmitriy Zakomirnyi
@dmi3zkm
hi team!
how can i register modules in objectMapper to serialize/desirialize Java 8 Date and Time and Money and Currency API instances ?
Russell Cohen
@rcoh
Just serialized a case class with a UUID in it (was missing the JavaTypesSerializer). I expected it to throw an exception, but it silently inserted {} for the uuid. Is there a way to make it throw an exception instead?
drocsid
@drocsid
I'm trying to merge two Option[Jobject]. Tried to use fold and it was ugly and didn't work for me. ctl.tags.fold(ctl.baggage.getOrElse(None))(tag => if (ctl.baggage.isDefined) ctl.baggage.get.merge(tag) else tag )
Anybody have a better way?
drocsid
@drocsid
I have a List[JObject] and wish to transform a field and return a List[Jobject]
val logs = List[JObject]("timestamp" -> 1506384826L*math.pow(10,9).toLong ,"timestamp" -> 1506384826L*math.pow(10,9).toLong)
I tried using tranformField, but it doesn't appear to work for me. Can anybody suggest how to do this?
ctl.logs.map { jobj =>
        jobj.transformField {
          case JField("timestamp", JLong(num)) => ("timestamp", JLong(num / 1000))
          case JField("timestamp", JInt(num)) => ("timestamp", JInt(num / 1000))
          case JField("timestamp", JDouble(num)) => ("timestamp", JDouble(num / 1000))
          case JField("timestamp", JDecimal(num)) => ("timestamp", JDecimal(num / 1000))
        }
      }.asInstanceOf[List[JObject]].map(_.values)
that was my attempt but it didn't seem to behave as I expected....
drocsid
@drocsid
hmm maybe I did get it and confused this somehow. I don't really like that cast at the end but I assume that I need to do that due to type erasure. Anyhow looks like this channel is good for asking yourself questions...
Eugene Platonov
@jozic
Hey All, can someone take a look at this PR json4s/json4s#486 @seratch already reviewed it, but to my understanding a second review is needed
It should fix a long standing issue with non-strict arrays extraction
Vamsi Ampolu
@vamsiampolu

How can I parse a string of YYYY-MM-dd to java.time.LocalDate, currently I have tried the following approaches:

  1. import JavaTimeSerializers

throws Error JString cannot be converted to LocalDate

case class Dates(createdAt: LocalDate, updatedAt: LocalDate, startDate: LocalDate, endDate: LocalDate )
 implicit val formats =  defaultFormats ++ org.json4s.ext.JavaTimeSerializers.all

implicit val formats =  defaultFormats ++ org.json4s.ext.JavaTimeSerializers.all

    val input =
      """
        |{
        |  "createdAt": "1999-12-10",
        |  "updatedAt": "1999-12-16",
        |  "startDate": "2000-01-02",
        |  "endDate": "200-01-16"
        |}
      """.stripMargin

   val result = read[Dates] { input }
  1. override DefaultFormats:

throws error found java.time.format.DateTimeFormatter expected java.text.SimpleDateFormat

  implicit val formats = new org.json4s.DefaultFormats {
      override def dateFormatter = DateTimeFormatter.ofPattern("YYYY-MM-dd")
  }


    val input =
      """
        |{
        |  "createdAt": "1999-12-10",
        |  "updatedAt": "1999-12-16",
        |  "startDate": "2000-01-02",
        |  "endDate": "200-01-16"
        |}
      """.stripMargin

    val result = read[Dates] { input }
  1. try to define CustomFormatter based on example here

Error Expected type was: (PartialFunction[org.json4s.JValue,java.time.LocalDate], PartialFunction[Any,org.json4s.JValue])

object LocalDateSerializer extends CustomSerializer[LocalDate](
  format => (
    {
      case JString(str) => LocalTime.parse(str)
      case JNull => null
    }
  ))

 implicit val formats =  org.json4s.DefaultFormats ++ new LocalDateSerializer
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