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
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

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?