Skip to content

Commit 8e1e700

Browse files
committed
jigsaw
1 parent ff1b801 commit 8e1e700

File tree

9 files changed

+187
-76
lines changed

9 files changed

+187
-76
lines changed

examples/maven-example/pom.xml

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,35 @@
1919
<version>3.8.1</version>
2020
<configuration>
2121
<release>11</release>
22-
<!--<proc>none</proc>
22+
<proc>none</proc>
2323
<annotationProcessorPaths>
2424
<annotationProcessorPath>
2525
<groupId>io.github.danthe1st</groupId>
2626
<artifactId>compile-time-json-parser</artifactId>
2727
<version>0.0.1-SNAPSHOT</version>
2828
</annotationProcessorPath>
29-
</annotationProcessorPaths>-->
29+
</annotationProcessorPaths>
3030
</configuration>
31+
<executions>
32+
<execution>
33+
<id>run-processor</id>
34+
<phase>generate-sources</phase>
35+
<goals>
36+
<goal>compile</goal>
37+
</goals>
38+
<configuration>
39+
<release>11</release>
40+
<proc>only</proc>
41+
<annotationProcessorPaths>
42+
<annotationProcessorPath>
43+
<groupId>io.github.danthe1st</groupId>
44+
<artifactId>compile-time-json-parser</artifactId>
45+
<version>0.0.1-SNAPSHOT</version>
46+
</annotationProcessorPath>
47+
</annotationProcessorPaths>
48+
</configuration>
49+
</execution>
50+
</executions>
3151
</plugin>
3252
</plugins>
3353
</build>

examples/maven-example/src/main/java/io/github/danthe1st/json_compile/test/TestClass.java

Lines changed: 0 additions & 54 deletions
This file was deleted.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package io.github.danthe1st.json_compile_example;
2+
3+
import io.github.danthe1st.json_compile.api.GenerateJSON;
4+
5+
@GenerateJSON
6+
public class ReferencedClass {
7+
private Long i;
8+
9+
public Long getI() {
10+
return i;
11+
}
12+
13+
public void setI(Long i) {
14+
this.i = i;
15+
}
16+
17+
@Override
18+
public String toString() {
19+
return "ReferencedClass{" +
20+
"i=" + i +
21+
'}';
22+
}
23+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
package io.github.danthe1st.json_compile_example;
2+
3+
import io.github.danthe1st.json_compile.api.GenerateJSON;
4+
5+
import java.io.BufferedReader;
6+
import java.io.IOException;
7+
import java.io.InputStreamReader;
8+
import java.nio.charset.StandardCharsets;
9+
import java.util.ArrayList;
10+
import java.util.Arrays;
11+
import java.util.List;
12+
import java.util.Objects;
13+
import java.util.stream.Collectors;
14+
15+
@GenerateJSON
16+
public class TestClass {
17+
private int privVal;
18+
public String pubVal;
19+
20+
public int[][] data={{1,2,3},{},{1,2,3,4,5,6}};
21+
22+
private ReferencedClass otherObject=new ReferencedClass();
23+
24+
private List<ReferencedClass[]> list=new ArrayList<>();
25+
26+
private TestEnum someEnum;
27+
28+
public int getProp() {
29+
return privVal;
30+
}
31+
public void setProp(int i) {
32+
this.privVal=i;
33+
}
34+
35+
public ReferencedClass getOtherObject() {
36+
return otherObject;
37+
}
38+
39+
public void setOtherObject(ReferencedClass otherObject) {
40+
this.otherObject = otherObject;
41+
}
42+
43+
public List <ReferencedClass[]> getList() {
44+
return list;
45+
}
46+
47+
public void setList(List <ReferencedClass[]> list) {
48+
this.list = list;
49+
}
50+
51+
public TestEnum getSomeEnum() {
52+
return someEnum;
53+
}
54+
55+
public void setSomeEnum(TestEnum someEnum) {
56+
this.someEnum = someEnum;
57+
}
58+
59+
@Override
60+
public String toString() {
61+
return "TestClass{" +
62+
"privVal=" + privVal +
63+
", pubVal='" + pubVal + '\'' +
64+
", data=" + Arrays.deepToString(data) +
65+
", otherObject=" + otherObject +
66+
", list=[" + list.stream().map(Arrays::toString).collect(Collectors.joining(", "))+"]" +
67+
", someEnum=" + someEnum +
68+
'}';
69+
}
70+
71+
public static void main(String[] args) throws IOException {
72+
try(BufferedReader br=new BufferedReader(new InputStreamReader(Objects.requireNonNull(Thread.currentThread().getContextClassLoader().getResourceAsStream("testClass.json")), StandardCharsets.UTF_8))){
73+
String json= String.join("", br.lines().collect(Collectors.joining()));
74+
TestClass obj = TestClassJSONLoader.fromJSON(json);
75+
System.out.println(obj);
76+
}
77+
TestClass testObj=new TestClass();
78+
testObj.setProp(12345);
79+
testObj.pubVal="test";
80+
81+
ReferencedClass listElem=new ReferencedClass();
82+
listElem.setI(100L);
83+
testObj.list.add(new ReferencedClass[]{new ReferencedClass(),listElem,null});
84+
testObj.list.add(null);
85+
86+
testObj.list.add(new ReferencedClass[0]);
87+
88+
testObj.someEnum=TestEnum.C;
89+
90+
System.out.println(TestClassJSONLoader.toJSON(testObj));
91+
}
92+
public enum TestEnum{
93+
A,B,C
94+
}
95+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module example{
2+
requires java.base;
3+
requires io.github.danthe1st.json_compile;
4+
requires org.json;
5+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"privVal": 123,
3+
"pubVal": "Hello World",
4+
"data": [
5+
[
6+
1,
7+
2,
8+
3
9+
],
10+
[],
11+
null,
12+
[
13+
-1,
14+
-1000,
15+
1
16+
]
17+
],
18+
"otherObject": {
19+
"i": 1337
20+
},
21+
"list": [
22+
[
23+
{
24+
"i": 1024
25+
},
26+
null,
27+
{
28+
"i": -1
29+
}
30+
],
31+
[],
32+
null
33+
],
34+
"someEnum": "B"
35+
}

examples/maven-example/testClass.json

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/main/java/module-info.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module io.github.danthe1st.json_compile{
2+
requires java.base;
3+
requires java.compiler;
4+
requires org.json;
5+
exports io.github.danthe1st.json_compile.api;
6+
provides javax.annotation.processing.Processor with io.github.danthe1st.json_compile.impl.JSONCreator;
7+
}

testClass.json

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)