Dynamic name fields in Json

22 views
Skip to first unread message

Simon Vos

unread,
Mar 20, 2015, 3:53:53 PM3/20/15
to raptur...@googlegroups.com
Hi,

Is there a way to handle dynamic values in the name fields of a Json structure.
For example:

{
    "changes" : {
        "1411998164000" : [{
            "key" : "JIRA-123",
            "column" : {
                "notDone" : true,
                "newStatus" : "10001"
            }
        }],
        "1412171743000" : [{
            "key" : "JIRA-456",
            "column" : {
                "notDone" : true,
                "newStatus" : "10001"
            }
        }],
        "1412873835000" : [{
            "key" : "JIRA-789",
            "timeC" : {
                "oldEstimate" : 0,
                "newEstimate" : 86400,
                "changeDate" : 1412873835000
            },
            "column" : {
                "notDone" : true,
                "newStatus" : "10001"
            }
        }]
    }
}

In this case, I'd like to get some sort of structure for each of these changes, preferably already converting the longs into dates :-).

Jon Pretty

unread,
Mar 22, 2015, 1:44:25 PM3/22/15
to raptur...@googlegroups.com
Hi Simon,

So, you can quite easily define an extractor for some kind of `Date` type like this:

implicit val ext: Extractor[Date, Json] =
  Json.extractor[Long].map(new Date(_))

To serialize from `Date`s, you do this:

implicit val ser: Serializer[Date, Json] =
  Json.serializer[Long].contramap[Date](_.getTime)

But you don't get any help (at least yet) if you want to convert the keys of the `Map` from `String`s to something else. What you can do is extract as a `Map[String, Whatever]` first, and then map across the `Map`.

But it's an interesting idea, so I've create an issue for it:

Cheers,
Jon


--
You received this message because you are subscribed to the Google Groups "Rapture users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rapture-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages