Skip to content

Instantly share code, notes, and snippets.

@jfsiii
Created November 29, 2016 17:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jfsiii/c53b7829f4a4338b9038cdb8ab645781 to your computer and use it in GitHub Desktop.
Save jfsiii/c53b7829f4a4338b9038cdb8ab645781 to your computer and use it in GitHub Desktop.
import com.fasterxml.jackson.annotation.JsonInclude.Include
import com.fasterxml.jackson.databind.{ObjectMapper, SerializationFeature}
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module
import com.fasterxml.jackson.module.scala.DefaultScalaModule
import java.time.Instant
import no.ssb.jsonstat.JsonStatModule
import no.ssb.jsonstat.v2.{Dataset, Dimension}
val mapper = new ObjectMapper()
mapper.registerModule(new DefaultScalaModule())
mapper.registerModule(new Jdk8Module())
mapper.registerModule(new JsonStatModule())
mapper.setSerializationInclusion(Include.NON_EMPTY)
val builder = Dataset.create().
withLabel("test label").
updatedAt(Instant.now()).
withDimension(Dimension.create("A").withCategories("A1", "A2", "A3")).
withDimension(Dimension.create("B").withCategories("B1", "B2")).
withDimension(Dimension.create("C").withCategories("C1", "C2", "C3", "C4"))
mapper.writeValueAsString(builder.build())
{
"version": "2.0",
"id": ["A", "B", "C"],
"size": [3, 2, 4],
"label": "test label",
"updated": {
"nano": 778000000,
"epochSecond": 1480441799
},
"dimension": {
"A": {
"version": "2.0",
"category": {
"label": {
"A1": "A1",
"A2": "A2",
"A3": "A3"
},
"index": ["A1", "A2", "A3"]
},
"class": "dimension"
},
"B": {
"version": "2.0",
"category": {
"label": {
"B1": "B1",
"B2": "B2"
},
"index": ["B1", "B2"]
},
"class": "dimension"
},
"C": {
"version": "2.0",
"category": {
"label": {
"C1": "C1",
"C2": "C2",
"C3": "C3",
"C4": "C4"
},
"index": ["C1", "C2", "C3", "C4"]
},
"class": "dimension"
}
},
"class": "dataset"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment