Implementation of JSON Stat in Java - http://json-stat.org
Add json stat dependency into your project
<dependency>
<groupId>no.ssb.jsonstat</groupId>
<artifactId>json-stat</artifactId>
<version>0.1.3</version>
</dependency>
Create a new json stat data set
Dataset.Builder builder = Dataset.create().withLabel("")
.withDimension(Dimension.create("year")
.withRole(Dimension.Roles.TIME)
.withIndexedLabels(ImmutableMap.of("2003", "2003", "2004", "2004", "2005", "2005")))
.withDimension(Dimension.create("month").withRole(Dimension.Roles.TIME)
.withIndexedLabels(ImmutableMap.of("may", "may", "june", "june", "july", "july")))
.withDimension(Dimension.create("week").withTimeRole()
.withIndexedLabels(ImmutableMap.of("30", "30", "31", "31", "32", "32")))
.withDimension(Dimension.create("population")
.withIndexedLabels(ImmutableMap.of(
"A", "active population",
"E", "employment",
"U", "unemployment",
"I", "inactive population",
"T", "population 15 years old and over"
)))
.withDimension(Dimension.create("amount").withMetricRole()
.withIndexedLabels(ImmutableMap.of("millions", "millions")))
.withDimension(Dimension.create("percent").withMetricRole()
.withIndexedLabels(ImmutableMap.of("%", "percent")));
Dataset dataset = builder.withMapper(
dimensions -> newArrayList(
dimensions.hashCode(),
dimensions.hashCode())
);
Deserialize a dataset
mapper = new ObjectMapper();
mapper.registerModule(new JsonStatModule());
Dataset.Builder builder = mapper.readValue("{ ... }", Dataset.Builder.class);
// Or
Dataset dataset = mapper.readValue("{ ... }", Dataset.class);