The Json to Yaml to Json Converter Maven Plugin allows to convert files from json to yaml and vice versa. It makes use of the Apache Maven Filtering component which provides filtering functionality.
This plugin copies the files specified by Resource elements, to an output directory and then converts them to the specified format. Filtering is applied before files are converted. This plugin has two goals:
- json-2-yaml converts json files to yaml
- yaml-2-json converts yaml files to json
You can help yourself getting started by checking the integration test in src/it and unit tests in src/test/resources/projects-to-test. Nevertheless the tables below describe the configuration parameters.
Two projects have been implemented for unit testing, you can run them in your system console via mvn clean test
within the project root directory.
Another to projects have been implemented fot integraiont testing, to run them in your system console, use mvn clean verify -Prun-its
Parameter | Required | Type | Default | Description |
---|---|---|---|---|
overwrite | No | boolean | true | When true and then converted file already exists, it is overwritten, it can also be specified via system property convert.overwrite. |
prettyPrintJson | No | boolean | true | When true, json is pretty printed, can also be specified via system property convert.json.pettyPrint. |
indentSpaces | No | int | 4 | Specifies the number of spaces to use for indentation. prettyPrintJson has to be true to take effect, it can also be set via system property convert.json.indentSpaces. |
escapeString | No | String | \ | Used to escape filtering tokens, it can also be specified via system property convert.escapeString. |
outputDirectory | Yes | String (File path) | ${project.build.directory} | Directory where converted files are to be copied to, it can also be specified via system property convert.outputDirectory. |
resources | Yes | List of Resource | List of resources to include/exclude in the conversion. | |
encoding | No | String | ${project.build.sourceEncoding} | Specifies the resources encoding, is uses file.encoding if project.build.sourceEncoding is not set. |
outputExtension | No | String | json | Specifies the extension to use in converted files, it can be specified via system property convert.json.outputExtension |
escapeWindowsPaths | No | boolean | true | When true, it escapes backslashes and colons in windows-style paths, it can be specified via system property convert.escapeWindowsPaths |
Parameter | Required | Type | Default | Description |
---|---|---|---|---|
overwrite | No | boolean | true | When true and then converted file already exists, it is overwritten, it can also be specified via system property convert.overwrite. |
escapeString | No | String | \ | Used to escape filtering tokens, it can also be specified via system property convert.escapeString. |
outputDirectory | Yes | String (File path) | ${project.build.directory} | Directory where converted files are to be copied to, it can also be specified via system property convert.outputDirectory. |
resources | Yes | List of Resource | List of resources to include/exclude in the conversion. | |
encoding | No | String | ${project.build.sourceEncoding} | Specifies the resources encoding, is uses file.encoding if project.build.sourceEncoding is not set. |
outputExtension | No | String | yaml | Specifies the extension to use in converted files, it can be specified via system property convert.yml.outputExtension |
escapeWindowsPaths | No | boolean | true | When true, it escapes backslashes and colons in windows-style paths, it can be specified via system property convert.escapeWindowsPaths |
Resource element is better expained in Apache Maven Resources Plugin project, follow the links below for detailed information.
<plugin>
<groupId>com.github.iarellano</groupId>
<artifactId>iad-j2y2j-converter-maven-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<id>json-2-yaml</id>
<phase>process-resources</phase>
<goals>
<goal>json-2-yaml</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>${project.basedir}/src/main</directory>
<filtering>true</filtering>
<includes>
<include>resources/*.json</include>
</includes>
</resource>
</resources>
<outputExtension>yml</outputExtension>
<outputDirectory>${project.build.directory}/resources</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.github.iarellano</groupId>
<artifactId>iad-j2y2j-converter-maven-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<id>yaml-2-json</id>
<phase>process-resources</phase>
<goals>
<goal>yaml-2-json</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>${project.basedir}/src/main</directory>
<filtering>true</filtering>
<includes>
<include>resources/*.yaml</include>
</includes>
</resource>
</resources>
<outputExtension>yml</outputExtension>
<outputDirectory>${project.build.directory}/resources</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>