/impropriety

A parser for Improperties files

Primary LanguageKotlin

Maven Central badge Build and check

Impropriety

A JVM parser for Improperties.

Getting started

Gradle

repositories {
    mavenCentral()
}

dependencies {
    implementation("coffee.cypher.impropriety:impropriety:latest.release")
}

Maven

<dependency>
    <groupId>coffee.cypher.impropriety</groupId>
    <artifactId>impropriety</artifactId>
    <version>RELEASE</version>
</dependency>

Usage examples

Java

//reading from a file
ImpropertiesReader reader = ImpropertiesReader.fromFile("some/file.improperties");

ImpObject tree = reader.toObject();

String value = tree.get("list").get(0).get("value").asValue().get();

//writing to a file
ImpropertiesWriter writer = new ImpropertiesWriter.Builder()
        .indent(2)
        .topLevelSpacing(1)
        .innerSpacing(1)
        .keyValueJoiner(": ")
        .build();

Map<String, Object> data = someDataSource();

writer.writeToFile(data, "some_other/file.improperties")

Kotlin

//reading from a file
val reader = ImpropertiesReader.fromFile("some/file.improperties")
val tree = reader.toObject()
val value = tree["list"][0]["value"].asValue().get()

//writing to a file
val writer = ImpropertiesWriter(
    indent = 2,
    topLevelSpacing = 1,
    innerSpacing = 1,
    keyValueJoiner = ": "
)

val data: Map<String, Any> = someDataSource()
writer.writeToFile(data, "some_other/file.improperties")

Limitations

  • List markers must be followed by whitespace (- element, not -element)

Using test fixtures in other projects

If you wish to use Impropriety's test fixtures in another project using Gradle, you can add them as a test dependency as follows.

dependencies {
    testImplementation(testFixtures("coffee.cypher.impropriety:impropriety:latest.release"))
}