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


The following commit(s) were added to refs/heads/master by this push:
     new 2c4dc545d2 Replace Mutaters with BasicConverter
2c4dc545d2 is described below

commit 2c4dc545d26c6c359b274a49750a0e64cb5a90a2
Author: James Bognar <[email protected]>
AuthorDate: Thu Apr 2 18:05:07 2026 -0700

    Replace Mutaters with BasicConverter
---
 .../main/java/org/apache/juneau/BeanContext.java   | 59 ++++++++++++++++++++--
 .../main/java/org/apache/juneau/BeanSession.java   | 13 -----
 2 files changed, 55 insertions(+), 17 deletions(-)

diff --git 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanContext.java 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanContext.java
index efa087b137..022493917a 100644
--- 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanContext.java
+++ 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanContext.java
@@ -168,7 +168,7 @@ import org.apache.juneau.swap.*;
        "java:S115", // Constants use UPPER_snakeCase naming convention
        "java:S1452"  // Wildcard required - ClassMeta<?> for parameter 
resolution and type variables
 })
-public class BeanContext extends Context {
+public class BeanContext extends Context implements ConversionFinder {
 
        // Property name constants
        private static final String PROP_beanClassVisibility = 
"beanClassVisibility";
@@ -258,8 +258,6 @@ public class BeanContext extends Context {
                private Set<ClassInfo> notBeanClasses;
                private Set<String> notBeanPackages;
                
-               private final ConfigurableConverter converter = new 
ConfigurableConverter();
-
                /**
                 * Constructor.
                 *
@@ -3688,7 +3686,6 @@ public class BeanContext extends Context {
                beansRequireSerializable = builder.beansRequireSerializable;
                beansRequireSettersForGetters = 
builder.beansRequireSettersForGetters;
                beansRequireSomeProperties = ! 
builder.disableBeansRequireSomeProperties;
-               converter = builder.converter;
                findFluentSetters = builder.findFluentSetters;
                hashKey = builder.hashKey();
                ignoreInvocationExceptionsOnGetters = 
builder.ignoreInvocationExceptionsOnGetters;
@@ -3735,6 +3732,7 @@ public class BeanContext extends Context {
                        }
                });
                objectSwaps = u(objectSwapsList);
+               converter = new ConfigurableConverter(this);
 
                cmCache = Cache.<Class,ClassMeta>create().supplier(type -> new 
ClassMeta<>(type, this)).build();
                cmString = cmCache.get(String.class);
@@ -3818,6 +3816,59 @@ public class BeanContext extends Context {
         */
        public final ConfigurableConverter getConverter() { return converter; }
 
+       /**
+        * Implements {@link ConversionFinder} by searching the registered 
{@link ObjectSwap} list for a swap
+        * that can convert between the given type pair.
+        *
+        * <p>
+        * For each registered swap:
+        * <ul>
+        *      <li>If the swap class is assignable from {@code inType} and the 
normal class is assignable from {@code outType},
+        *              returns a {@link Conversion} that calls {@link 
ObjectSwap#unswap} using the session.
+        *      <li>If the normal class is assignable from {@code inType} and 
the swap class is assignable from {@code outType},
+        *              returns a {@link Conversion} that calls {@link 
ObjectSwap#swap} using the session.
+        * </ul>
+        *
+        * @param inType The input type class.
+        * @param outType The output type class.
+        * @return A {@link Conversion} backed by a matching swap, or {@code 
null} if no swap applies.
+        */
+       @Override
+       @SuppressWarnings({
+               "unchecked" // Type erasure requires unchecked casts for 
ObjectSwap generic types
+       })
+       public Conversion<?,?> find(Class<?> inType, Class<?> outType) {
+               for (var swap : objectSwaps) {
+                       var nc = swap.getNormalClass().inner();
+                       var fc = swap.getSwapClass().inner();
+                       // Unswap: input is swap class, output is normal class
+                       if (nc.isAssignableFrom(outType) && 
fc.isAssignableFrom(inType)) {
+                               var to = getClassMeta(outType);
+                               return (in, memberOf, session, args) -> {
+                                       try {
+                                               var bs = session instanceof 
BeanSession bs2 ? bs2 : null;
+                                               var resolvedSwap = bs != null ? 
to.getSwap(bs) : null;
+                                               return 
((ObjectSwap<Object,Object>) (resolvedSwap != null ? resolvedSwap : 
swap)).unswap(bs, in, to);
+                                       } catch (Exception e) {
+                                               throw rex(e);
+                                       }
+                               };
+                       }
+                       // Swap: input is normal class, output is swap class
+                       if (nc.isAssignableFrom(inType) && 
fc.isAssignableFrom(outType)) {
+                               return (in, memberOf, session, args) -> {
+                                       try {
+                                               var bs = session instanceof 
BeanSession bs2 ? bs2 : null;
+                                               return 
((ObjectSwap<Object,Object>) swap).swap(bs, in);
+                                       } catch (Exception e) {
+                                               throw rex(e);
+                                       }
+                               };
+                       }
+               }
+               return null;
+       }
+
        /**
         * Returns the {@link BeanMeta} class for the specified class.
         *
diff --git 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanSession.java 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanSession.java
index 32586b4e3a..d128b36d72 100644
--- 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanSession.java
+++ 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanSession.java
@@ -18,18 +18,15 @@ package org.apache.juneau;
 
 import static org.apache.juneau.commons.utils.AssertionUtils.*;
 import static org.apache.juneau.commons.utils.CollectionUtils.*;
-import static org.apache.juneau.commons.utils.IoUtils.*;
 import static org.apache.juneau.commons.utils.StringUtils.*;
 import static org.apache.juneau.commons.utils.ThrowableUtils.*;
 import static org.apache.juneau.commons.utils.Utils.*;
 
 import java.io.*;
 import java.lang.reflect.*;
-import java.nio.charset.*;
 import java.text.*;
 import java.time.*;
 import java.util.*;
-import java.util.concurrent.atomic.*;
 import java.util.function.*;
 import java.util.logging.*;
 
@@ -257,16 +254,6 @@ public class BeanSession extends ContextSession implements 
ConverterSession {
         */
        public static final String NAME_PROPERTY_NAME = "_name";
 
-       private static int getMultiplier(String s) {
-               if (s.endsWith("G"))
-                       return 1024 * 1024 * 1024;
-               if (s.endsWith("M"))
-                       return 1024 * 1024;
-               if (s.endsWith("K"))
-                       return 1024;
-               return 1;
-       }
-
        private boolean hasMutater(ClassMeta<?> from, ClassMeta<?> to) {
                if (to.hasMutaterFrom(from) || from.hasMutaterTo(to))
                        return true;

Reply via email to