Skip to content

Commit

Permalink
initial version
Browse files Browse the repository at this point in the history
  • Loading branch information
danthe1st committed Apr 15, 2021
1 parent 45af209 commit 7c10166
Show file tree
Hide file tree
Showing 13 changed files with 209 additions and 105 deletions.
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -274,4 +274,10 @@ buildNumber.properties
.mvn/wrapper/maven-wrapper.jar
.flattened-pom.xml

# End of https://www.toptal.com/developers/gitignore/api/java,maven,eclipse,intellij,intellij+all
# End of https://www.toptal.com/developers/gitignore/api/java,maven,eclipse,intellij,intellij+all

# Ignore Gradle project-specific cache directory
.gradle

# Ignore Gradle build output directory
build
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Compile-time JSON-parser
# Compile-time JSON-parser [![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.github.danthe1st/compile-time-json-parser/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.github.danthe1st/compile-time-json-parser)
> generates a JSON-parser for Java-objects at compile-time
Compile-time JSON-parser supports both non-private variables and properties.
Expand All @@ -10,12 +10,12 @@ The generated JSON-parser uses `org.json:json`.
* Download the sources
* Run `mvn clean install` in the directory of Compile-time JSON-parser
* Create a Maven Project in IntelliJ where you want to use Compile-time JSON-parser
* Add the following dependency to the `pom.xml` of the project where you want to use Compile-time JSON-parser
* Add the following dependency to the `pom.xml` of the project where you want to use Compile-time JSON-parser (replace `VERSION` with the version from [![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.github.danthe1st/compile-time-json-parser/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.github.danthe1st/compile-time-json-parser))
```xml
<dependency>
<groupId>io.github.danthe1st</groupId>
<artifactId>compile-time-json-parser</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>VERSION</version>
</dependency>
```
* If you wish to use JPMS, also add the annotation processor to the `maven-compiler-plugin`
Expand All @@ -39,6 +39,7 @@ The generated JSON-parser uses `org.json:json`.

### Usage
* Create a data class and annotate it with `@GenerateJSON` like this:

```java
import io.github.danthe1st.json_compile.api.GenerateJSON;
@GenerateJSON
Expand Down Expand Up @@ -75,6 +76,7 @@ public class TestClass {
```
* When compiling the class, a class suffixed with `JSONLoader` should be automatically generated.<br/>
This class contains a method named `fromJSON` that creates an instance of the data class from a `String`:

```java
String json= String.join("", Files.readAllLines(Path.of("testClass.json")));
TestClass obj = TestClassJSONLoader.fromJSON(json);
Expand Down Expand Up @@ -115,7 +117,6 @@ An example project can be found in the directory `examples/maven-example`.
* Objects annotated with `@GenerateJSON` need to have a no-args-constructor
* Collections need to be initialized in the constructor
* Generic objects are not supported (except generic collections)
* Compile-time JSON-parser is not yet published to maven central, so you will have to build it by yourself.
* Configuration is not supported

### IDE-specific configuration
Expand Down
4 changes: 2 additions & 2 deletions examples/maven-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.github.danthe1st</groupId>
<artifactId>json-parser-maven-example</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>1.0.0</version>
<dependencies>
<dependency>
<groupId>io.github.danthe1st</groupId>
<artifactId>compile-time-json-parser</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>1.0.0-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.danthe1st.json_compile_example;
package io.github.danthe1st.json_compile_example.maven;

import io.github.danthe1st.json_compile.api.GenerateJSON;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.danthe1st.json_compile_example;
package io.github.danthe1st.json_compile_example.maven;

import io.github.danthe1st.json_compile.api.GenerateJSON;

Expand All @@ -14,10 +14,10 @@

@GenerateJSON
public class TestClass {
private int privVal;
private int privVal;//private values without getters/setters-->ignored
public String pubVal;

public int[][] data={{1,2,3},{},{1,2,3,4,5,6}};
public int[][] data={{1,2,3},{},{1,2,3,4,5,6}};//private values without getters/setters-->used

private ReferencedClass otherObject=new ReferencedClass();

Expand Down
2 changes: 1 addition & 1 deletion examples/maven-example/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module example{
module io.github.danthe1st.json_compiler.examples.maven{
requires java.base;
requires io.github.danthe1st.json_compile;
requires org.json;
Expand Down
231 changes: 170 additions & 61 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,63 +1,172 @@
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>io.github.danthe1st</groupId>
<artifactId>compile-time-json-parser</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Compile time JSON parser</name>
<description>prepares converting JSON objects to java objects at compile-time</description>
<dependencies>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20210307</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>11</release>
<proc>none</proc>
</configuration>
<executions>
<execution>
<id>process-test-annotations</id>
<phase>generate-test-sources</phase>
<goals>
<goal>testCompile</goal>
</goals>
<configuration>
<proc>only</proc>
<annotationProcessors>
<annotationProcessor>io.github.danthe1st.json_compile.impl.JSONCreator</annotationProcessor>
</annotationProcessors>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-5</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>jar-with-dependencies</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>io.github.danthe1st</groupId>
<artifactId>compile-time-json-parser</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<name>Compile time JSON parser</name>
<description>prepares converting JSON objects to java objects at compile-time</description>
<url>https://github.com/danthe1st/compile-time-json-parser</url>
<licenses>
<license>
<name>The MIT License</name>
<url>https://opensource.org/licenses/MIT</url>
</license>
</licenses>
<developers>
<developer>
<url>https://github.com/danthe1st/</url>
<name>Daniel</name>
<roles>
<role>Developer</role>
<role>Maintainer</role>
</roles>
<timezone>+1</timezone>
</developer>
</developers>
<scm>
<connection>scm:git:[email protected]:danthe1st/compile-time-json-parser.git</connection>
<developerConnection>scm:git:[email protected]:danthe1st/compile-time-json-parser.git</developerConnection>
<url>https://github.com/danthe1st/compile-time-json-parser</url>
</scm>
<issueManagement>
<url>https://github.com/danthe1st/compile-time-json-parser/issues</url>
<system>GitHub</system>
</issueManagement>
<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/releases</url>
</repository>
</distributionManagement>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20210307</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>11</release>
<proc>none</proc>
</configuration>
<executions>
<execution>
<id>process-test-annotations</id>
<phase>generate-test-sources</phase>
<goals>
<goal>testCompile</goal>
</goals>
<configuration>
<proc>only</proc>
<annotationProcessors>
<annotationProcessor>io.github.danthe1st.json_compile.impl.JSONCreator
</annotationProcessor>
</annotationProcessors>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-5</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>jar-with-dependencies</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>deploy</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.1</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<phase>verify</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.0.1</version>
<configuration>
<javadocVersion>11</javadocVersion>
<doclint>all</doclint>
<source>11</source>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<phase>verify</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.7</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
</plugins>
</build>
</project>
Loading

0 comments on commit 7c10166

Please sign in to comment.