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
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 ^
Colin Williams
@KE7CFN_twitter
Hi I'm looking at what should be a simple example parsed Json. I'd like to navigate the AST to obtain a subvalue but am not following how to do that after looking at the LINQ style and XPath examples. Can someone elucidate me. E.G.
My JValue looks like
org.json4s.JValue = JObject(List((@context,JArray(List(JString(https://raw.githx,JString(https://api.weather.gov/ontology#)), (geo,JString(http://www.opengis.net/ontapi.weather.gov/ontology#))))))), (type,JString(Feature)), (geometry,JObject(List((typ, (coordinates,JArray(List(JDouble(-123.0102602), JDouble(48.5993352)))))), JObject(Li0288715), JDouble(48.6073768))), JArray(List(JDouble(-123.0224183), JDouble(48.5870264...
Then for example how can I get a flat easy to read list of reference "keys" to traverse maybe 1st level of the JObject ?
Colin Williams
@KE7CFN_twitter
I look at .values and it looks like
Map(@context -> List(https://raw.githubusercontent.com/geojson/geojson-ld/master/contexts/geojson-base.jsonld, Map(wx -> https://api.weather.gov/ontology#, geo -> http://www.opengis.net/ont/geosparql#, unit -> http://codes.wmo.int/common/unit/, @vocab -> https://api.weather.gov/ontology#)), type -> Feature, geometry -> Map(type -> GeometryCollection, geometries -> List(Map(type -> Point, coordinates -> List(-123.0102602, 48.5993352)), Map(type -> Polygon, coordinates -> List(List(List(-123.0288715, 48.6073768), List(-123.0224183, 48.5870264), List(-122.9916522, 48.5912913), List(-122.9980987, 48.6116418), List(-123.0288715, 48.6073768)))))), properties -> HashMap(periods -> List(HashMap(number -> 1, shortForecast -> Mostly Cloudy then Chance Light Rain, startTime ...
Colin Williams
@KE7CFN_twitter
Well I've exposed my ignorance. I will fiddle with it more and see if I can get somewhere...
Colin Williams
@KE7CFN_twitter
Looks like I can extract the xpath elements but still I'm curious why the .values "Map" doesn't provide Map "methods"
scala> parsed.values.
!=   +    ==             ensuring   formatted   hashCode       toString   
##   ->   asInstanceOf   equals     getClass    isInstanceOf   →
Colin Williams
@KE7CFN_twitter
scala> parsed.values.getClass
res117: Class[_ <: parsed.Values] = class scala.collection.immutable.Map$Map4
Anirudh Vyas
@AnirudhVyas
Hi there - how do I convert a case class to JObject directly without handcoding jObject - So far I can only see parse(write(caseClassInstance).snakizeKeys.asInstanceOf[JObject] ... but that is a lot of work to get case class
Anirudh Vyas
@AnirudhVyas
by a lot of work I meant lot of I/O
Andriy Plokhotnyuk
@plokhotnyuk
@AnirudhVyas as w/a you can try jsoniter-scala. It derives a safe and efficient JSON codec for a whole nested data structure by a one-liner macro call like here.
Andy Czerwonka
@andyczerwonka
wondering if there is an established pattern for parsing an array of dynamic objects, e.g. List[Either[ThisType, ThatTYpe]]
{
  "stuff": [
    {
      "a": null,
      "b": "wombat",
      "c": [],
      "d": 7,
      "uids": {
        "id": "0cd1a7f8-cee0-4f54-9c6b-534c123f2ec6"
      }
    },
    {
      "file_links": [],
      "name": "Abstract Butter",
      "notes": "Shortening for making rich, buttery baked goods",
      "process": {
        "id": "b8f748cf-c313-4f2c-8e38-84d7701f9609",
        "scope": "id",
        "type": "link_by_uid"
      }
    }
  ]
}
Anirudh Vyas
@AnirudhVyas

by a lot of work I meant lot of I/O

I am answering my question - to do what I needed (transform a product type to JObject directly -> http://json4s.org/ use decompose)

Markus
@mnotti
Hi, wondering if there's an idiomatic/easy way to write a JObject to a file?
Anirudh Vyas
@AnirudhVyas
Unsure about file - but I have used jackson.Serialization.write before to transform to a string and then perhaps to a file, but if someone else knows of a cleaner way all ears 👂
Greg Zoller
@gzoller
G'day... is there a json4s build against dotty?
Sankarshan Mudkavi
@Sankarshan-Mudkavi
Hey guys, does json4s support parsing and extraction in an akka stream? It seems to be hanging on the first object every time. I'm using JSONframing to stream the json objects from a filestream
Qubiq1337
@Qubiq1337
Hey guys, how to pop/remove value from json?
Anirudh Vyas
@AnirudhVyas
 val originalRequestWithoutRequestId = wc.originalRequest.removeField {
      case ("blah_field_name", _) => true
      case ("another_blah_field_name", _) => true
      case _                 => false
    }
@Qubiq1337 ^^
Qubiq1337
@Qubiq1337
Ty
Anirudh Vyas
@AnirudhVyas
@gzoller dotty is not stable yet ... unsure why there would until they finalize everything?
Pavel Zorin
@pazone

Hi folks. How do I filter off objects from a json array?
For example:

  {
    "name": "John"
  },
  {
    "name": "Joseph"
  },
  {
    "name": "Peter"
  }
]

I'd like to filter off objects with names which are not starting with Jo:

  {
    "name": "John"
  },
  {
    "name": "Joseph"
  }
]

The result might be a String or JValue with json array inside.
Thanks.

Anirudh Vyas
@AnirudhVyas
JArray(List.empty).map { case JObject(values) => JObject(values.filter { case (fName, _) => fName.startsWith("Jo") }) } would something like this work?
Pavel Zorin
@pazone
Wow! Thanks. I'll try it
Jack Koenig
@jackkoenig
Is there a way to not error on Exception in thread "main" org.json4s.package$MappingException: Do not know how to serialize key of type class my.custom.Type. Consider implementing a CustomKeySerializer., like a low-priority custom serializer that turns the error into a String in the emitted JSON or something?
Rohan Sircar
@rohan-sircar
Hi I'm trying to create a custom serializer for java.time Instant
``` object MyJInstantSerializer
extends CustomSerializerInstant => Instant.ofEpochMilli(d.toLong)
case JString(d) => Instant.parse(d)
case JNull => null
}, {
// case d: Instant => JInt(d.toEpochMilli)
case d: Instant => JString(d.toString())
}
)
)
and I'm getting this error - ``` Caused by: java.lang.IncompatibleClassChangeError: wow.doge.chatto.service.MyJInstantSerializer$ and wow.doge.chatto.service.MyJInstantSerializer$$anonfun$$lessinit$greater$1$$anonfun$apply$1 disagree on InnerClasses attribute
Rohan Sircar
@rohan-sircar
Messed up the formatting. Reposting with correct formatting -
class MyJInstantSerializer
    extends CustomSerializer[Instant](format =>
      (
        {
          // case JInt(d) => Instant.ofEpochMilli(d.toLong)
          case JString(d) => Instant.parse(d)
          case JNull      => null
        }, {
          // case d: Instant => JInt(d.toEpochMilli)
          case d: Instant => JString(d.toString())
        }
      )
    )
Thomas Järvstrand
@tjarvstrand
Hi! Is this room still active? I was wondering if there are any plans to release 3.7.0 soon?