Skip to content

Instantly share code, notes, and snippets.

@jfsiii
Created November 29, 2016 17:52
Show Gist options
  • Save jfsiii/50e7e5fe1e50738b462e5afcb5cbe05b to your computer and use it in GitHub Desktop.
Save jfsiii/50e7e5fe1e50738b462e5afcb5cbe05b to your computer and use it in GitHub Desktop.
import com.fasterxml.jackson.annotation.JsonInclude.Include
import com.fasterxml.jackson.databind.{ObjectMapper, SerializationFeature}
import java.time.Instant
import no.ssb.jsonstat.JsonStatModule
import no.ssb.jsonstat.v2.{Dataset, Dimension}
val mapper = new ObjectMapper()
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": {
"present": true
},
"source": {
"present": false
},
"updated": {
"present": true
},
"dimension": {
"A": {
"version": "2.0",
"category": {
"label": {
"A1": "A1",
"A2": "A2",
"A3": "A3"
},
"index": ["A1", "A2", "A3"]
},
"label": {
"present": false
},
"class": "dimension"
},
"B": {
"version": "2.0",
"category": {
"label": {
"B1": "B1",
"B2": "B2"
},
"index": ["B1", "B2"]
},
"label": {
"present": false
},
"class": "dimension"
},
"C": {
"version": "2.0",
"category": {
"label": {
"C1": "C1",
"C2": "C2",
"C3": "C3",
"C4": "C4"
},
"index": ["C1", "C2", "C3", "C4"]
},
"label": {
"present": false
},
"class": "dimension"
}
},
"class": "dataset"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment