Conversation
# Conflicts: # http-generator-core/src/main/java/io/avaje/http/generator/core/ElementReader.java
… invalid Java identifier
This produces a compilation error on the generated code:
```
var shippingCustomer-info = new ContactForm();
shippingCustomer-info.phone = formParams.contains("shipping.customer-info.phone") ? formParams.get("shipping.customer-info.phone") : null;
shippingCustomer-info.email = formParams.contains("shipping.customer-info.email") ? formParams.get("shipping.customer-info.email") : null;
```
…valid Java identifiers
Uses new BeanParamReader.toJavaIdentifier() to convert required chars to underscore
This now produces the generated code (with valid java identifiers):
```
var shippingCustomer_info = new ContactForm();
shippingCustomer_info.phone = formParams.contains("shipping.customer-info.phone") ? formParams.get("shipping.customer-info.phone") : null;
shippingCustomer_info.email = formParams.contains("shipping.customer-info.email") ? formParams.get("shipping.customer-info.email") : null;
shipping.contact = shippingCustomer_info;
```
|
Hi @ah3nan @SentryMan - I have added some commits with a failing test case for The change to ensure valid java identifier converts unsupported chars like hyphen Please review those last commits and post back if you are happy with those. Thanks, Rob. |
|
FYI: The failed build there was because this PR lost the |
Problem
Form beans (
@Form/@BeanParam) only supported flat form parameters. Nested objects had to be flattened manually, and RESTEasy-style prefixed binding (invoice.street,shipping.street) had no support.Feature
Adds a new
@FormPrefix(String value)annotation (FIELD target) for a field/component on a@Form/@BeanParambean. The nested object is populated from form parameters prefixed with the given value:submitted as
name=bill&invoice.street=Main+St&invoice.zip=12345&invoice.contact.phone=555....Records are supported too — nested
@FormPrefixrecords are built via their canonical constructor and passed into the parent constructor:Changes
avaje-http-api: newio.avaje.http.api.FormPrefixannotation.http-generator-core:ParamType: newFORMNESTED.ElementReader: detect@FormPrefix, apply the dotted prefix to form lookups (formParamName()), recursive imports for nested types, form-beanvar/constructor wiring.BeanParamReader: recursive nested population — constructor-based for records / single-constructor types, no-arg + setter/field for POJOs; unique local variable names so repeated field names under different prefixes don't collide; nested constructor params are built before the parent.Generated code (Helidon, record example)
Verification
test-nima(Helidon),test-javalin,test-jex,test-vertx(each withFormPrefixControllerTest+RecordFormControllerTest), plus explicit assertions intest-sigma'sSigmaProcessorTest.tests/test-vertx/src/test/resources/expectedOpenApi.jsonupdated for the new/formprefixand/recordformroutes.mvn clean package -Ptest→ BUILD SUCCESS across all modules.Notes / future work
telephoneNumbers[0].countryCode,address[INVOICE].street) are a follow-up (needs runtime key enumeration viaParameters.names()).