Skip to content

Commit 481dea7

Browse files
authored
Compile-time JSON implementation (helidon-io#10961)
Compile-time JSON implementation Signed-off-by: David Kral <david.k.kral@oracle.com>
1 parent 54c5abe commit 481dea7

217 files changed

Lines changed: 25889 additions & 221 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

all/pom.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,6 +1317,14 @@
13171317
<groupId>io.helidon.discovery.providers</groupId>
13181318
<artifactId>helidon-discovery-providers-eureka</artifactId>
13191319
</dependency>
1320+
<dependency>
1321+
<groupId>io.helidon.json</groupId>
1322+
<artifactId>helidon-json</artifactId>
1323+
</dependency>
1324+
<dependency>
1325+
<groupId>io.helidon.json</groupId>
1326+
<artifactId>helidon-json-binding</artifactId>
1327+
</dependency>
13201328
<dependency>
13211329
<groupId>io.helidon.json.schema</groupId>
13221330
<artifactId>helidon-json-schema</artifactId>

bom/pom.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1781,6 +1781,22 @@
17811781
<version>${helidon.version}</version>
17821782
</dependency>
17831783

1784+
<!-- JSON support -->
1785+
<dependency>
1786+
<groupId>io.helidon.json</groupId>
1787+
<artifactId>helidon-json-binding</artifactId>
1788+
<version>${helidon.version}</version>
1789+
</dependency>
1790+
<dependency>
1791+
<groupId>io.helidon.json</groupId>
1792+
<artifactId>helidon-json</artifactId>
1793+
<version>${helidon.version}</version>
1794+
</dependency>
1795+
<dependency>
1796+
<groupId>io.helidon.json</groupId>
1797+
<artifactId>helidon-json-codegen</artifactId>
1798+
<version>${helidon.version}</version>
1799+
</dependency>
17841800

17851801
<dependency>
17861802
<groupId>io.helidon.validation</groupId>

builder/codegen/src/main/java/io/helidon/builder/codegen/FactoryOption.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023, 2025 Oracle and/or its affiliates.
2+
* Copyright (c) 2023, 2026 Oracle and/or its affiliates.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -497,6 +497,7 @@ private static Optional<OptionBuilder> optionBuilder(RoundContext ctx,
497497
.filter(ElementInfoPredicates::isMethod)
498498
.filter(ElementInfoPredicates::isStatic)
499499
.filter(elementName("builder"))
500+
.filter(it -> it.typeName().typeArguments().isEmpty()) //Builders with generics not supported
500501
.filter(ElementInfoPredicates::hasNoArgs)
501502
// Has to have public no-param build method returning right type
502503
.filter(it -> ctx.typeInfo(it.typeName()).stream()

builder/codegen/src/main/java/io/helidon/builder/codegen/GenerateAbstractBuilder.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023, 2025 Oracle and/or its affiliates.
2+
* Copyright (c) 2023, 2026 Oracle and/or its affiliates.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -476,7 +476,7 @@ private static void preBuildPrototypeMethod(List<BuilderCodegenExtension> extens
476476
if (hasProvider || hasRegistryService) {
477477
boolean configured = prototypeInfo.configured().isPresent();
478478

479-
if (configured) {
479+
if (configured && hasConfiguredRegistryServiceOrProvider(options)) {
480480
// need to have a non-null config instance
481481
preBuildBuilder.addContent("var config = config().map(")
482482
.addContent(CONFIG)
@@ -529,6 +529,20 @@ private static void preBuildPrototypeMethod(List<BuilderCodegenExtension> extens
529529
classBuilder.addMethod(preBuildBuilder);
530530
}
531531

532+
private static boolean hasConfiguredRegistryServiceOrProvider(List<OptionHandler> options) {
533+
boolean configured = options.stream()
534+
.map(OptionHandler::option)
535+
.filter(OptionInfo::registryService)
536+
.anyMatch(it -> it.configured().isPresent());
537+
if (configured) {
538+
return true;
539+
}
540+
return options.stream()
541+
.map(OptionHandler::option)
542+
.filter(it -> it.provider().isPresent())
543+
.anyMatch(it -> it.configured().isPresent());
544+
}
545+
532546
private static boolean hasRegistryService(List<OptionHandler> options) {
533547
return options.stream()
534548
.map(OptionHandler::option)

builder/tests/common-types/src/main/java/io/helidon/common/types/TypeNameBlueprint.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023, 2025 Oracle and/or its affiliates.
2+
* Copyright (c) 2023, 2026 Oracle and/or its affiliates.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -149,11 +149,9 @@ default String classNameWithEnclosingNames() {
149149
* if {@link #typeArguments()} exist, this list MUST exist and have the same size and order (it maps the name to the type).
150150
*
151151
* @return type parameter names as declared on this type, or names that represent the {@link #typeArguments()}
152-
* @deprecated the {@link io.helidon.common.types.TypeName#typeArguments()} will contain all required information
153152
*/
154153
@Option.Singular
155154
@Option.Redundant
156-
@Deprecated(forRemoval = true, since = "4.2.0")
157155
List<String> typeParameters();
158156

159157
/**

bundles/apt/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
- Helidon Data
3939
- Helidon JSON Schema
4040
- Helidon LangChain4j
41+
- Helidon JSON
4142
Does not contain:
4243
- Helidon Copyright extension
4344
</description>
@@ -77,6 +78,10 @@
7778
<groupId>io.helidon.integrations.langchain4j</groupId>
7879
<artifactId>helidon-integrations-langchain4j-codegen</artifactId>
7980
</dependency>
81+
<dependency>
82+
<groupId>io.helidon.json</groupId>
83+
<artifactId>helidon-json-codegen</artifactId>
84+
</dependency>
8085
</dependencies>
8186

8287
<profiles>

codegen/class-model/src/main/java/io/helidon/codegen/classmodel/ConcreteType.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023, 2025 Oracle and/or its affiliates.
2+
* Copyright (c) 2023, 2026 Oracle and/or its affiliates.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -90,7 +90,19 @@ void writeComponent(ModelWriter writer, Set<String> declaredTokens, ImportOrgani
9090
writer.write(">");
9191
}
9292
if (isArray()) {
93-
writer.write("[]");
93+
Optional<TypeName> componentType = this.typeName.componentType();
94+
while (componentType.isPresent()) {
95+
TypeName current = componentType.get();
96+
if (current.array()) {
97+
writer.append("[]");
98+
componentType = current.componentType();
99+
} else {
100+
break;
101+
}
102+
}
103+
if (this.typeName.array()) {
104+
writer.append("[]");
105+
}
94106
}
95107
}
96108

common/buffers/src/main/java/io/helidon/common/buffers/Bytes.java

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, 2025 Oracle and/or its affiliates.
2+
* Copyright (c) 2022, 2026 Oracle and/or its affiliates.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -74,10 +74,46 @@ public final class Bytes {
7474
* {@code %} byte.
7575
*/
7676
public static final byte PERCENT_BYTE = (byte) '%';
77+
/**
78+
* {@code ,} byte.
79+
*/
80+
public static final byte COMMA_BYTE = (byte) ',';
81+
/**
82+
* &#123; byte.
83+
*/
84+
public static final byte BRACE_OPEN_BYTE = (byte) '{';
85+
/**
86+
* &#125; byte.
87+
*/
88+
public static final byte BRACE_CLOSE_BYTE = (byte) '}';
89+
/**
90+
* {@code "} byte.
91+
*/
92+
public static final byte DOUBLE_QUOTE_BYTE = (byte) '"';
7793
/**
7894
* Horizontal tabulator byte.
7995
*/
8096
public static final byte TAB_BYTE = (byte) '\t';
97+
/**
98+
* {@code [} byte.
99+
*/
100+
public static final byte SQUARE_BRACKET_OPEN_BYTE = (byte) '[';
101+
/**
102+
* {@code ]} byte.
103+
*/
104+
public static final byte SQUARE_BRACKET_CLOSE_BYTE = (byte) ']';
105+
/**
106+
* {@code \} byte.
107+
*/
108+
public static final byte BACKSLASH_BYTE = (byte) '\\';
109+
/**
110+
* {@code 0} byte.
111+
*/
112+
public static final byte ZERO_DIGIT_BYTE = (byte) '0';
113+
/**
114+
* {@code -} byte.
115+
*/
116+
public static final byte MINUS_SIGN_BYTE = (byte) '-';
81117

82118
private static final boolean BYTE_ORDER_LE = ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN;
83119

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright (c) 2026 Oracle and/or its affiliates.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.helidon.common;
18+
19+
/**
20+
* Accessor styles supported by Helidon modules.
21+
*/
22+
public enum AccessorStyle {
23+
24+
/**
25+
* Accessor are identified without the get/set prefix same as in Java records.
26+
* <p>
27+
* Examples:
28+
* <ul>
29+
* <li>{@code int yearOfBirth()}</li>
30+
* <li>{@code void yearOfBirth(int year}</li>
31+
* <li>{@code boolean enabled()}</li>
32+
* <li>{@code void enabled(boolean enabled)}</li>
33+
* </ul>
34+
*/
35+
RECORD,
36+
37+
/**
38+
* Accessor are identified with the get/set prefix as in Java beans.
39+
* <p>
40+
* Examples:
41+
* <ul>
42+
* <li>{@code int getYearOfBirth()}</li>
43+
* <li>{@code void setYearOfBirth(int year}</li>
44+
* <li>{@code boolean isEnabled()}</li>
45+
* <li>{@code void setEnabled(boolean enabled)}</li>
46+
* </ul>
47+
*/
48+
BEAN,
49+
50+
/**
51+
* The style of accessors is automatically detected.
52+
* First bean and if no accessor is found, record style is tested.
53+
* This enum value is only relevant when "guessing" from an existing type. For cases when we generate code,
54+
* one of the other styles must be chosen.
55+
*/
56+
AUTO
57+
58+
}

0 commit comments

Comments
 (0)