-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Mechite <[email protected]>
- Loading branch information
Showing
5 changed files
with
185 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.avaje</groupId> | ||
<artifactId>java11-oss</artifactId> | ||
<version>4.4</version> | ||
<relativePath/> | ||
</parent> | ||
|
||
<groupId>io.avaje</groupId> | ||
<artifactId>avaje-config-json</artifactId> | ||
<version>4.1-SNAPSHOT</version> | ||
|
||
<scm> | ||
<connection>scm:git:[email protected]:avaje/avaje-config.git</connection> | ||
<developerConnection>scm:git:[email protected]:avaje/avaje-config.git</developerConnection> | ||
<tag>HEAD</tag> | ||
</scm> | ||
|
||
<properties> | ||
<snakeyaml.version>2.3</snakeyaml.version> | ||
<nexus.staging.autoReleaseAfterClose>true</nexus.staging.autoReleaseAfterClose> | ||
<surefire.useModulePath>false</surefire.useModulePath> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.avaje</groupId> | ||
<artifactId>avaje-config</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.avaje</groupId> | ||
<artifactId>avaje-jsonb</artifactId> | ||
<version>2.1</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.avaje</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>1.5</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>ch.qos.logback</groupId> | ||
<artifactId>logback-classic</artifactId> | ||
<version>1.5.7</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.avaje</groupId> | ||
<artifactId>avaje-applog-slf4j</artifactId> | ||
<version>1.0</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-repository-plugin</artifactId> | ||
<version>2.4</version> | ||
</plugin> | ||
<!-- <plugin>--> | ||
<!-- <groupId>org.sonatype.plugins</groupId>--> | ||
<!-- <artifactId>nexus-staging-maven-plugin</artifactId>--> | ||
<!-- <version>1.7.0</version>--> | ||
<!-- <extensions>true</extensions>--> | ||
<!-- <configuration>--> | ||
<!-- <serverId>ossrh</serverId>--> | ||
<!-- <nexusUrl>https://s01.oss.sonatype.org/</nexusUrl>--> | ||
<!-- <autoReleaseAfterClose>${nexus.staging.autoReleaseAfterClose}</autoReleaseAfterClose>--> | ||
<!-- </configuration>--> | ||
<!-- </plugin>--> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
41 changes: 41 additions & 0 deletions
41
avaje-config-json/src/main/java/io/avaje/config/json/JsonParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package io.avaje.config.json; | ||
|
||
import io.avaje.config.ConfigParser; | ||
import io.avaje.jsonb.Jsonb; | ||
import io.avaje.jsonb.Types; | ||
import org.jspecify.annotations.NullMarked; | ||
|
||
import java.io.InputStream; | ||
import java.io.Reader; | ||
import java.util.Map; | ||
|
||
@NullMarked | ||
final class JsonParser implements ConfigParser { | ||
|
||
private static final String[] extensions = {"json"}; | ||
|
||
private final Jsonb jsonb; | ||
|
||
JsonParser() { | ||
this.jsonb = Jsonb.builder() | ||
.failOnUnknown(false) | ||
.serializeEmpty(true) | ||
.serializeNulls(true) | ||
.build(); | ||
} | ||
|
||
@Override | ||
public String[] supportedExtensions() { | ||
return extensions; | ||
} | ||
|
||
@Override | ||
public Map<String, String> load(Reader reader) { | ||
return (Map<String, String>) this.jsonb.type(Types.mapOf(String.class)).fromJson(reader); | ||
} | ||
|
||
@Override | ||
public Map<String, String> load(InputStream is) { | ||
return (Map<String, String>) this.jsonb.type(Types.mapOf(String.class)).fromJson(is); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module io.avaje.config.json { | ||
|
||
requires io.avaje.config; | ||
requires io.avaje.jsonb; | ||
|
||
exports io.avaje.config.json; | ||
|
||
uses io.avaje.config.ConfigExtension; | ||
|
||
} |
51 changes: 51 additions & 0 deletions
51
avaje-config-json/src/test/java/io/avaje/config/json/JsonParserTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package io.avaje.config.json; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.StringReader; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.Map; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
|
||
public class JsonParserTest { | ||
|
||
@Test | ||
void supportedExtensions() { | ||
var parser = new JsonParser(); | ||
assertThat(parser.supportedExtensions()).isEqualTo(new String[]{"json"}); | ||
} | ||
|
||
private static String input() { | ||
return "{" + | ||
"\"one.key\": \"a\"," + | ||
"\"one.key2\": \"b\"," + | ||
"\"key3\": \"c\"" + | ||
"}"; | ||
} | ||
|
||
@Test | ||
void load_reader() { | ||
var parser = new JsonParser(); | ||
Map<String, String> map = parser.load(new StringReader(input())); | ||
|
||
assertThat(map).hasSize(3); | ||
assertThat(map).containsOnlyKeys("one.key", "one.key2", "key3"); | ||
assertThat(map).containsEntry("one.key", "a"); | ||
assertThat(map).containsEntry("one.key2", "b"); | ||
assertThat(map).containsEntry("key3", "c"); | ||
} | ||
|
||
@Test | ||
void load_inputStream() { | ||
var parser = new JsonParser(); | ||
Map<String, String> map = parser.load(new ByteArrayInputStream(input().getBytes(StandardCharsets.UTF_8))); | ||
|
||
assertThat(map).hasSize(3); | ||
assertThat(map).containsOnlyKeys("one.key", "one.key2", "key3"); | ||
assertThat(map).containsEntry("one.key", "a"); | ||
assertThat(map).containsEntry("one.key2", "b"); | ||
assertThat(map).containsEntry("key3", "c"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters