### Programmatically Creating a JSON-stat Dataset in Java Source: https://github.com/statisticsnorway/json-stat.java/blob/develop/README.md This Java example illustrates how to construct a `Dataset` object using the `Dataset.Builder` pattern. It demonstrates adding multiple dimensions with various roles (TIME, METRIC) and indexed labels, providing a structured way to define a JSON-stat dataset programmatically. ```Java class Example { static { Dataset.Builder builder = Dataset.create().withLabel("My dataset"); builder.withDimension( Dimension.create("year") .withRole(Dimension.Roles.TIME) .withIndexedLabels(ImmutableMap.of("2003", "2003", "2004", "2004", "2005", "2005") ) ); builder.withDimension( Dimension.create("month").withRole(Dimension.Roles.TIME) .withIndexedLabels(ImmutableMap.of("may", "may", "june", "june", "july", "july") ) ); builder.withDimension( Dimension.create("week").withTimeRole() .withIndexedLabels(ImmutableMap.of("30", "30", "31", "31", "32", "32") ) ); builder.withDimension( Dimension.create("population").withMetricRole() .withIndexedLabels(ImmutableMap.of( "A", "active population", "E", "employment", "U", "unemployment", "I", "inactive population", "T", "population 15 years old and over")) ); builder.withDimension( Dimension.create("amount").withMetricRole() .withIndexedLabels(ImmutableMap.of("millions", "millions")) ); builder.withDimension( Dimension.create("percent").withMetricRole() .withIndexedLabels(ImmutableMap.of("%", "percent")) ); Dataset dataset = builder.withMapper( dimensions -> newArrayList( dimensions.hashCode(), dimensions.hashCode()) ); } } ``` -------------------------------- ### Adding JSON-stat Java Dependency to Maven Project Source: https://github.com/statisticsnorway/json-stat.java/blob/develop/README.md This XML snippet demonstrates how to add the `json-stat-java` library as a dependency to a Maven project's `pom.xml` file. This allows the project to access and use the JSON-stat functionalities provided by the library. ```XML no.ssb.jsonstat json-stat-java 0.2.5 ``` -------------------------------- ### Registering JsonStatModule with Jackson ObjectMapper in Java Source: https://github.com/statisticsnorway/json-stat.java/blob/develop/README.md This Java code shows how to initialize a Jackson `ObjectMapper` and register the `JsonStatModule` along with `JavaTimeModule`. Registering these modules is crucial for `ObjectMapper` to correctly serialize and deserialize JSON-stat objects and Java 8 Date and Time API types. ```Java class Example { static { mapper = new ObjectMapper(); mapper.registerModule(new JsonStatModule()); mapper.registerModule(new JavaTimeModule()); } } ``` -------------------------------- ### Deserializing JSON-stat Dataset with Jackson ObjectMapper in Java Source: https://github.com/statisticsnorway/json-stat.java/blob/develop/README.md This Java code snippet demonstrates how to deserialize a JSON-stat dataset string into a `Dataset.Builder` or `Dataset` object using a configured Jackson `ObjectMapper`. It highlights the necessity of registering `GuavaModule`, `Jdk8Module`, `JavaTimeModule`, and `JsonStatModule` for proper deserialization of complex types. ```Java class Example { static { mapper = new ObjectMapper(); mapper.registerModule(new GuavaModule()); mapper.registerModule(new Jdk8Module()); mapper.registerModule(new JavaTimeModule()); mapper.registerModule(new JsonStatModule()); Dataset.Builder builder = mapper.readValue("{ ... }", Dataset.Builder.class); // Or Dataset dataset = mapper.readValue("{ ... }", Dataset.class); } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.