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 7c112d7d3e Marshall module improvements
7c112d7d3e is described below
commit 7c112d7d3e1a67c97131040632d17f7b4b471472
Author: James Bognar <[email protected]>
AuthorDate: Mon Dec 8 13:20:03 2025 -0500
Marshall module improvements
---
.../main/java/org/apache/juneau/BeanContext.java | 19 -------------
.../src/main/java/org/apache/juneau/BeanMeta.java | 4 +++
.../src/main/java/org/apache/juneau/ClassMeta.java | 31 ++++++++++++++--------
3 files changed, 24 insertions(+), 30 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 0d9029695d..667135d600 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
@@ -4039,25 +4039,6 @@ public class BeanContext extends Context {
return defaultSession.toBeanMap(object);
}
- /**
- * Checks whether a class has a {@link ObjectSwap} associated with it
in this bean context.
- *
- * @param c The class to check.
- * @return <jk>true</jk> if the specified class or one of its
subclasses has a {@link ObjectSwap} associated with it.
- */
- final ObjectSwap[] findChildObjectSwaps(Class<?> c) {
- if (c == null || swapArray.length == 0)
- return null;
- var l = (List<ObjectSwap>)null;
- for (var f : swapArray) {
- if (f.getNormalClass().isChildOf(c)) {
- if (l == null)
- l = list();
- l.add(f);
- }
- }
- return l == null ? null : l.toArray(new ObjectSwap[l.size()]);
- }
/*
* Resolves the 'genericized' class meta at the specified position in
the ClassMeta array.
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanMeta.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanMeta.java
index ccf33cb513..a6a5043453 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanMeta.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanMeta.java
@@ -34,6 +34,7 @@ import java.util.function.*;
import org.apache.juneau.annotation.*;
import org.apache.juneau.commons.collections.*;
import org.apache.juneau.commons.function.*;
+import org.apache.juneau.commons.function.OptionalSupplier;
import org.apache.juneau.commons.reflect.*;
import org.apache.juneau.commons.reflect.Visibility;
import org.apache.juneau.commons.utils.*;
@@ -789,6 +790,8 @@ public class BeanMeta<T> {
private final Supplier<String> dictionaryName2; //
The @Bean(typeName) annotation defined on this bean class.
+ private final OptionalSupplier<InvocationHandler>
beanProxyInvocationHandler; // The invocation handler for this bean (if it's
an interface).
+
final String notABeanReason; // Readable
string explaining why this class wasn't a bean.
final BeanRegistry beanRegistry;
@@ -869,6 +872,7 @@ public class BeanMeta<T> {
if (sortProperties)
Arrays.sort(propertyArray);
dictionaryName2 = memoize(()->findDictionaryName());
+ beanProxyInvocationHandler =
memoize(()->ctx.isUseInterfaceProxies() && c.isInterface() ? new
BeanProxyInvocationHandler<>(this) : null);
}
@Override /* Overridden from Object */
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/ClassMeta.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/ClassMeta.java
index e7afddcc21..dbd83abf92 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/ClassMeta.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/ClassMeta.java
@@ -143,7 +143,7 @@ public class ClassMeta<T> extends ClassInfoTyped<T> {
private final Supplier<BuilderSwap<T,?>> builderSwap;
// The builder swap associated with this bean (if it has one).
private final Categories cat;
// The class category.
private final Cache<Class<?>,ObjectSwap<?,?>> childSwapMap;
// Maps normal subclasses to ObjectSwaps.
- private final List<ObjectSwap<?,?>> childSwaps;
// Any ObjectSwaps where the normal type is a subclass of this class.
+ private final Supplier<List<ObjectSwap<?,?>>> childSwaps;
// Any ObjectSwaps where the normal type is a subclass of this class.
private final Cache<Class<?>,ObjectSwap<?,?>> childUnswapMap;
// Maps swap subclasses to ObjectSwaps.
private final Supplier<String> dictionaryName;
// The dictionary name of this class if it has one.
private final Supplier<ClassMeta<?>> elementType;
// If ARRAY or COLLECTION, the element class type.
@@ -258,8 +258,7 @@ public class ClassMeta<T> extends ClassInfoTyped<T> {
this.proxyInvocationHandler =
()->(nn(beanMeta.get().getA()) && beanContext.isUseInterfaceProxies() &&
isInterface()) ? new BeanProxyInvocationHandler<>(beanMeta.get().getA()) : null;
- var childSwapsArray =
beanContext.findChildObjectSwaps(innerClass);
- this.childSwaps = childSwapsArray == null ? null :
Arrays.asList(childSwapsArray);
+ this.childSwaps = memoize(()->findChildSwaps());
this.childUnswapMap =
Cache.<Class<?>,ObjectSwap<?,?>>create().supplier(x -> findUnswap(x)).build();
this.childSwapMap =
Cache.<Class<?>,ObjectSwap<?,?>>create().supplier(x -> findSwap(x)).build();
@@ -269,15 +268,11 @@ public class ClassMeta<T> extends ClassInfoTyped<T> {
}
protected ObjectSwap<?,?> findSwap(Class<?> c) {
- if (isEmpty(childSwaps))
- return null;
- return childSwaps.stream().filter(x ->
x.getNormalClass().isParentOf(c)).findFirst().orElse(null);
+ return childSwaps.get().stream().filter(x ->
x.getNormalClass().isParentOf(c)).findFirst().orElse(null);
}
protected ObjectSwap<?,?> findUnswap(Class<?> c) {
- if (isEmpty(childSwaps))
- return null;
- return childSwaps.stream().filter(x ->
x.getSwapClass().isParentOf(c)).findFirst().orElse(null);
+ return childSwaps.get().stream().filter(x ->
x.getSwapClass().isParentOf(c)).findFirst().orElse(null);
}
@@ -288,7 +283,7 @@ public class ClassMeta<T> extends ClassInfoTyped<T> {
ClassMeta(List<ClassMeta<?>> args) {
super((Class<T>)Object[].class);
this.args = args;
- this.childSwaps = null;
+ this.childSwaps = memoize(()->findChildSwaps());
this.childSwapMap = null;
this.childUnswapMap = null;
this.cat = new Categories().set(ARGS);
@@ -1404,6 +1399,20 @@ public class ClassMeta<T> extends ClassInfoTyped<T> {
return u(list);
}
+ private List<ObjectSwap<?,?>> findChildSwaps() {
+ if (beanContext == null)
+ return l();
+ var swapArray = beanContext.getSwaps();
+ if (swapArray == null || swapArray.length == 0)
+ return l();
+ var list = new ArrayList<ObjectSwap<?,?>>();
+ var innerClass = inner();
+ for (var f : swapArray)
+ if (f.getNormalClass().isChildOf(innerClass))
+ list.add(f);
+ return u(list);
+ }
+
private BidiMap<Object,String> findEnumValues() {
if (! isEnum())
return null;
@@ -1734,7 +1743,7 @@ public class ClassMeta<T> extends ClassInfoTyped<T> {
* @return <jk>true</jk> if this class or any child classes has a
{@link ObjectSwap} associated with it.
*/
protected boolean hasChildSwaps() {
- return childSwaps != null && ! childSwaps.isEmpty();
+ return ! childSwaps.get().isEmpty();
}
/**