Skip to content

Commit 70d908c

Browse files
authored
Add disableJsonB option to NOT use avaje-jsonb in code generation even if it's in the classpath (#574)
1 parent 7452d4f commit 70d908c

File tree

3 files changed

+59
-25
lines changed

3 files changed

+59
-25
lines changed

http-generator-core/src/main/java/io/avaje/http/generator/core/BaseProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
@GenerateAPContext
2929
@GenerateModuleInfoReader
30-
@SupportedOptions({"useJavax", "useSingleton", "instrumentRequests","disableDirectWrites"})
30+
@SupportedOptions({"useJavax", "useSingleton", "instrumentRequests","disableDirectWrites","disableJsonB"})
3131
public abstract class BaseProcessor extends AbstractProcessor {
3232

3333
protected String contextPathString;

http-generator-core/src/main/java/io/avaje/http/generator/core/ProcessingContext.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ private static final class Ctx {
5454
private final String diAnnotation;
5555
private final boolean instrumentAllMethods;
5656
private final boolean disableDirectWrites;
57+
private final boolean disableJsonB;
5758
private final boolean javalin6;
5859
private final Set<String> clientFQN = new HashSet<>();
5960

@@ -73,6 +74,7 @@ private static final class Ctx {
7374
final var singletonOverride = options.get("useSingleton");
7475
this.instrumentAllMethods = Boolean.parseBoolean(options.get("instrumentRequests"));
7576
this.disableDirectWrites = Boolean.parseBoolean(options.get("disableDirectWrites"));
77+
this.disableJsonB = Boolean.parseBoolean(options.get("disableJsonB"));
7678
if (singletonOverride != null) {
7779
useComponent = !Boolean.parseBoolean(singletonOverride);
7880
} else {
@@ -202,6 +204,10 @@ public static boolean instrumentAllWebMethods() {
202204
}
203205

204206
public static boolean useJsonb() {
207+
return isJsonbInClasspath() && !CTX.get().disableJsonB;
208+
}
209+
210+
private static boolean isJsonbInClasspath() {
205211
try {
206212
return CTX.get().elementUtils.getTypeElement("io.avaje.jsonb.Jsonb") != null
207213
|| Class.forName("io.avaje.jsonb.Jsonb") != null;

tests/test-jex/pom.xml

Lines changed: 52 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -79,31 +79,7 @@
7979

8080
<!-- java annotation processors -->
8181

82-
<dependency>
83-
<groupId>io.avaje</groupId>
84-
<artifactId>avaje-inject-generator</artifactId>
85-
<version>${avaje-inject.version}</version>
86-
<scope>provided</scope>
87-
</dependency>
88-
89-
<dependency>
90-
<groupId>io.avaje</groupId>
91-
<artifactId>avaje-http-jex-generator</artifactId>
92-
<version>${project.version}</version>
93-
<scope>provided</scope>
94-
</dependency>
95-
96-
<dependency>
97-
<groupId>io.avaje</groupId>
98-
<artifactId>avaje-jsonb-generator</artifactId>
99-
<version>3.0</version>
100-
</dependency>
10182

102-
<dependency>
103-
<groupId>io.jstach</groupId>
104-
<artifactId>jstachio-apt</artifactId>
105-
<version>1.3.6</version>
106-
</dependency>
10783

10884
<!-- test dependencies -->
10985
<dependency>
@@ -126,6 +102,44 @@
126102
<finalName>app</finalName>
127103
<plugins>
128104

105+
<plugin>
106+
<groupId>org.apache.maven.plugins</groupId>
107+
<artifactId>maven-compiler-plugin</artifactId>
108+
<version>3.14.0</version>
109+
<configuration>
110+
<!-- <compilerArgs>-->
111+
<!-- <arg>-AdisableJsonB=true</arg>-->
112+
<!-- </compilerArgs>-->
113+
<annotationProcessorPaths>
114+
<path>
115+
<groupId>io.avaje</groupId>
116+
<artifactId>avaje-inject-generator</artifactId>
117+
<version>${avaje-inject.version}</version>
118+
</path>
119+
<path>
120+
<groupId>io.avaje</groupId>
121+
<artifactId>avaje-http-jex-generator</artifactId>
122+
<version>${project.version}</version>
123+
</path>
124+
<path>
125+
<groupId>io.avaje</groupId>
126+
<artifactId>avaje-jsonb-generator</artifactId>
127+
<version>3.0</version>
128+
</path>
129+
<path>
130+
<groupId>io.avaje</groupId>
131+
<artifactId>avaje-validator-generator</artifactId>
132+
<version>2.8</version>
133+
</path>
134+
<path>
135+
<groupId>io.jstach</groupId>
136+
<artifactId>jstachio-apt</artifactId>
137+
<version>1.3.6</version>
138+
</path>
139+
</annotationProcessorPaths>
140+
</configuration>
141+
</plugin>
142+
129143
<plugin>
130144
<groupId>io.avaje</groupId>
131145
<artifactId>openapi-maven-plugin</artifactId>
@@ -153,6 +167,20 @@
153167
</configuration>
154168
</plugin>
155169

170+
<!-- generated by avaje inject -->
171+
<plugin>
172+
<groupId>io.avaje</groupId>
173+
<artifactId>avaje-inject-maven-plugin</artifactId>
174+
<version>11.2</version>
175+
<executions>
176+
<execution>
177+
<phase>process-sources</phase>
178+
<goals>
179+
<goal>provides</goal>
180+
</goals>
181+
</execution>
182+
</executions>
183+
</plugin>
156184
</plugins>
157185
</build>
158186

0 commit comments

Comments
 (0)