This is an automated email from the ASF dual-hosted git repository.

jamesbognar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/juneau.git

commit d12179c58dff5fd03115dd7f1ef6432b27dd7861
Author: James Bognar <[email protected]>
AuthorDate: Fri May 8 15:14:22 2026 -0400

    refactor(inject): TODO-15 phase-3 batch 11 — migrate rest-common / 
rest-client http-part creators
    
    Migrate the http-part serializer/parser instantiation sites in rest-common
    and rest-client from legacy BeanCreator to v2 BeanInstantiator.  These all
    follow the same shape: instantiate an HttpPartSerializer / HttpPartParser
    subclass when one is configured on the schema, otherwise fall back to a
    caller-supplied default.
    
    Files migrated:
    - RequestBeanMeta — Builder.serializer / Builder.parser fields retyped to
      BeanInstantiator<...>; .of(...) calls updated; b.serializer.orElse(null)
      rewritten as b.serializer.asOptional().orElse(null) (BeanInstantiator does
      not expose a single-arg .orElse(T) shortcut today).
    - RequestBeanPropertyMeta — type(...) -> beanSubType(...) on the 
per-property
      override path.
    - ResponseBeanPropertyMeta — execute() rewritten as asOptional(); added a
      null-guard on schema.getSerializer() / schema.getParser() (legacy
      BeanCreator.type(null) was tolerant and just yielded an empty Optional via
      silent run; v2 beanSubType(Class) throws on null, so the call site now 
does
      the null check explicitly).
    - RestClient.getPartParser(Class) / getPartSerializer(Class) — simple
      BeanCreator.of(c, beanStore).run() -> BeanInstantiator.of(c, 
beanStore).run().
      RestClient.callHandler memoizer + Builder.beanStore field stay on legacy
      BeanCreator / BasicBeanStore for now (memoizer + builder-pattern migration
      is its own task).
    - RemoteOperationArg — both ctors updated with the same null-guard +
      asOptional() pattern.
    
    Generics:
    - HttpPartSchema.getSerializer() / getParser() return Class<?>, so the
      beanSubType(...) call sites needed an unchecked cast to
      Class<? extends HttpPartSerializer> / Class<? extends HttpPartParser>;
      added @SuppressWarnings("unchecked") on each constructor.
    
    Build clean; juneau-utest passes.
    
    Co-authored-by: Cursor <[email protected]>
---
 .../main/java/org/apache/juneau/rest/client/RestClient.java  |  5 +++--
 .../apache/juneau/rest/client/remote/RemoteOperationArg.java | 12 +++++++++---
 .../org/apache/juneau/httppart/bean/RequestBeanMeta.java     | 10 +++++-----
 .../apache/juneau/httppart/bean/RequestBeanPropertyMeta.java |  7 ++++---
 .../juneau/httppart/bean/ResponseBeanPropertyMeta.java       | 11 ++++++++---
 5 files changed, 29 insertions(+), 16 deletions(-)

diff --git 
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestClient.java
 
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestClient.java
index 11dca8ce06..919977ec44 100644
--- 
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestClient.java
+++ 
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestClient.java
@@ -74,6 +74,7 @@ import org.apache.juneau.commons.annotation.Schema;
 import org.apache.juneau.commons.collections.*;
 import org.apache.juneau.commons.collections.FluentMap;
 import org.apache.juneau.commons.function.*;
+import org.apache.juneau.commons.inject.*;
 import org.apache.juneau.commons.reflect.*;
 import org.apache.juneau.cp.*;
 import org.apache.juneau.html.*;
@@ -8022,7 +8023,7 @@ public class RestClient extends BeanContextable 
implements HttpClient, Closeable
                var x = partParsers.get(c);
                if (x == null) {
                        try {
-                               x = BeanCreator.of(c, beanStore).run();
+                               x = BeanInstantiator.of(c, beanStore).run();
                        } catch (ExecutableException e) {
                                throw toRex(e);
                        }
@@ -8048,7 +8049,7 @@ public class RestClient extends BeanContextable 
implements HttpClient, Closeable
                var x = partSerializers.get(c);
                if (x == null) {
                        try {
-                               x = BeanCreator.of(c, beanStore).run();
+                               x = BeanInstantiator.of(c, beanStore).run();
                        } catch (ExecutableException e) {
                                throw toRex(e);
                        }
diff --git 
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/remote/RemoteOperationArg.java
 
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/remote/RemoteOperationArg.java
index 664a7e8454..7f6a5802c4 100644
--- 
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/remote/RemoteOperationArg.java
+++ 
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/remote/RemoteOperationArg.java
@@ -20,8 +20,8 @@ import static 
org.apache.juneau.commons.httppart.HttpPartType.*;
 
 import java.util.*;
 
+import org.apache.juneau.commons.inject.*;
 import org.apache.juneau.commons.reflect.*;
-import org.apache.juneau.cp.*;
 import org.apache.juneau.http.annotation.*;
 import org.apache.juneau.httppart.*;
 import org.apache.juneau.commons.httppart.*;
@@ -65,17 +65,23 @@ public class RemoteOperationArg {
 
        private final HttpPartSchema schema;
 
+       @SuppressWarnings("unchecked")
        RemoteOperationArg(int index, HttpPartType partType, HttpPartSchema 
schema) {
                this.index = index;
                this.partType = partType;
-               this.serializer = 
BeanCreator.of(HttpPartSerializer.class).type(schema.getSerializer()).execute();
+               this.serializer = schema.getSerializer() == null
+                       ? Optional.empty()
+                       : 
BeanInstantiator.of(HttpPartSerializer.class).beanSubType((Class<? extends 
HttpPartSerializer>) schema.getSerializer()).asOptional();
                this.schema = schema;
        }
 
+       @SuppressWarnings("unchecked")
        RemoteOperationArg(int index, HttpPartType partType, HttpPartSchema 
schema, String overrideName) {
                this.index = index;
                this.partType = partType;
-               this.serializer = 
BeanCreator.of(HttpPartSerializer.class).type(schema.getSerializer()).execute();
+               this.serializer = schema.getSerializer() == null
+                       ? Optional.empty()
+                       : 
BeanInstantiator.of(HttpPartSerializer.class).beanSubType((Class<? extends 
HttpPartSerializer>) schema.getSerializer()).asOptional();
                // Create a new schema with the overridden name
                this.schema = 
HttpPartSchema.create().name(overrideName).build();
        }
diff --git 
a/juneau-rest/juneau-rest-common/src/main/java/org/apache/juneau/httppart/bean/RequestBeanMeta.java
 
b/juneau-rest/juneau-rest-common/src/main/java/org/apache/juneau/httppart/bean/RequestBeanMeta.java
index 7c6a505094..24801d6a1e 100644
--- 
a/juneau-rest/juneau-rest-common/src/main/java/org/apache/juneau/httppart/bean/RequestBeanMeta.java
+++ 
b/juneau-rest/juneau-rest-common/src/main/java/org/apache/juneau/httppart/bean/RequestBeanMeta.java
@@ -24,8 +24,8 @@ import static 
org.apache.juneau.httppart.bean.MethodInfoUtils.*;
 import java.util.*;
 
 import org.apache.juneau.*;
+import org.apache.juneau.commons.inject.*;
 import org.apache.juneau.commons.reflect.*;
-import org.apache.juneau.cp.*;
 import org.apache.juneau.http.annotation.*;
 import org.apache.juneau.httppart.*;
 
@@ -43,8 +43,8 @@ public class RequestBeanMeta {
        static class Builder {
                ClassMeta<?> cm;
                AnnotationWorkList annotations;
-               BeanCreator<HttpPartSerializer> serializer = 
BeanCreator.of(HttpPartSerializer.class);
-               BeanCreator<HttpPartParser> parser = 
BeanCreator.of(HttpPartParser.class);
+               BeanInstantiator<HttpPartSerializer> serializer = 
BeanInstantiator.of(HttpPartSerializer.class);
+               BeanInstantiator<HttpPartParser> parser = 
BeanInstantiator.of(HttpPartParser.class);
                Map<String,RequestBeanPropertyMeta.Builder> properties = map();
 
                Builder(AnnotationWorkList annotations) {
@@ -131,8 +131,8 @@ public class RequestBeanMeta {
 
        RequestBeanMeta(Builder b) {
                cm = b.cm;
-               serializer = b.serializer.orElse(null);
-               parser = b.parser.orElse(null);
+               serializer = b.serializer.asOptional().orElse(null);
+               parser = b.parser.asOptional().orElse(null);
                Map<String,RequestBeanPropertyMeta> pm = map();
                b.properties.forEach((k, v) -> pm.put(k, v.build(serializer, 
parser)));
                properties = u(pm);
diff --git 
a/juneau-rest/juneau-rest-common/src/main/java/org/apache/juneau/httppart/bean/RequestBeanPropertyMeta.java
 
b/juneau-rest/juneau-rest-common/src/main/java/org/apache/juneau/httppart/bean/RequestBeanPropertyMeta.java
index 90a164bcfa..dc503170a8 100644
--- 
a/juneau-rest/juneau-rest-common/src/main/java/org/apache/juneau/httppart/bean/RequestBeanPropertyMeta.java
+++ 
b/juneau-rest/juneau-rest-common/src/main/java/org/apache/juneau/httppart/bean/RequestBeanPropertyMeta.java
@@ -24,8 +24,8 @@ import java.lang.reflect.*;
 import java.util.*;
 
 import org.apache.juneau.commons.annotation.*;
+import org.apache.juneau.commons.inject.*;
 import org.apache.juneau.commons.reflect.*;
-import org.apache.juneau.cp.*;
 import org.apache.juneau.http.annotation.*;
 import org.apache.juneau.httppart.*;
 import org.apache.juneau.commons.httppart.*;
@@ -81,12 +81,13 @@ public class RequestBeanPropertyMeta {
 
        private final HttpPartSchema schema;
 
+       @SuppressWarnings("unchecked")
        RequestBeanPropertyMeta(Builder b, HttpPartSerializer serializer, 
HttpPartParser parser) {
                partType = b.partType;
                schema = b.schema;
                getter = b.getter;
-               this.serializer = opt(schema.getSerializer() == null ? 
serializer : 
BeanCreator.of(HttpPartSerializer.class).type(schema.getSerializer()).run());
-               this.parser = schema.getParser() == null ? parser : 
BeanCreator.of(HttpPartParser.class).type(schema.getParser()).run();
+               this.serializer = opt(schema.getSerializer() == null ? 
serializer : BeanInstantiator.of(HttpPartSerializer.class).beanSubType((Class<? 
extends HttpPartSerializer>) schema.getSerializer()).run());
+               this.parser = schema.getParser() == null ? parser : 
BeanInstantiator.of(HttpPartParser.class).beanSubType((Class<? extends 
HttpPartParser>) schema.getParser()).run();
        }
 
        /**
diff --git 
a/juneau-rest/juneau-rest-common/src/main/java/org/apache/juneau/httppart/bean/ResponseBeanPropertyMeta.java
 
b/juneau-rest/juneau-rest-common/src/main/java/org/apache/juneau/httppart/bean/ResponseBeanPropertyMeta.java
index 2e7cf0a89e..b743c9d703 100644
--- 
a/juneau-rest/juneau-rest-common/src/main/java/org/apache/juneau/httppart/bean/ResponseBeanPropertyMeta.java
+++ 
b/juneau-rest/juneau-rest-common/src/main/java/org/apache/juneau/httppart/bean/ResponseBeanPropertyMeta.java
@@ -21,8 +21,8 @@ import static org.apache.juneau.commons.utils.Utils.*;
 import java.lang.reflect.*;
 import java.util.*;
 
+import org.apache.juneau.commons.inject.*;
 import org.apache.juneau.commons.reflect.*;
-import org.apache.juneau.cp.*;
 import org.apache.juneau.http.annotation.*;
 import org.apache.juneau.httppart.*;
 import org.apache.juneau.commons.httppart.*;
@@ -82,12 +82,17 @@ public class ResponseBeanPropertyMeta {
 
        private final HttpPartSchema schema;
 
+       @SuppressWarnings("unchecked")
        ResponseBeanPropertyMeta(Builder b, Optional<HttpPartSerializer> 
serializer, Optional<HttpPartParser> parser) {
                partType = b.partType;
                schema = b.schema;
                getter = b.getter;
-               this.serializer = serializer.isPresent() ? serializer : 
BeanCreator.of(HttpPartSerializer.class).type(schema.getSerializer()).execute();
-               this.parser = parser.isPresent() ? parser : 
BeanCreator.of(HttpPartParser.class).type(schema.getParser()).execute();
+               this.serializer = serializer.isPresent() || 
schema.getSerializer() == null
+                       ? serializer
+                       : 
BeanInstantiator.of(HttpPartSerializer.class).beanSubType((Class<? extends 
HttpPartSerializer>) schema.getSerializer()).asOptional();
+               this.parser = parser.isPresent() || schema.getParser() == null
+                       ? parser
+                       : 
BeanInstantiator.of(HttpPartParser.class).beanSubType((Class<? extends 
HttpPartParser>) schema.getParser()).asOptional();
        }
 
        /**

Reply via email to