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 ed683ced57 Marshall module improvements
ed683ced57 is described below
commit ed683ced57697e7e414a958989c044795dca7fd4
Author: James Bognar <[email protected]>
AuthorDate: Wed Dec 10 11:44:23 2025 -0500
Marshall module improvements
---
.../main/java/org/apache/juneau/BeanFilter.java | 62 ++++++++++++++++++----
.../src/main/java/org/apache/juneau/BeanMeta.java | 19 ++++---
2 files changed, 61 insertions(+), 20 deletions(-)
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanFilter.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanFilter.java
index 7f208822cb..2300bafdaf 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanFilter.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanFilter.java
@@ -51,7 +51,7 @@ public class BeanFilter {
private ClassInfoTyped<?> beanClass;
private String typeName, example;
private Set<String> properties = set(), excludeProperties =
set(), readOnlyProperties = set(), writeOnlyProperties = set();
- private Class<?> implClass, interfaceClass, stopClass;
+ private ClassInfo implClass, interfaceClass, stopClass;
private boolean sortProperties, fluentSetters;
private BeanCreator<PropertyNamer> propertyNamer =
BeanCreator.of(PropertyNamer.class);
private List<ClassInfo> dictionary;
@@ -92,13 +92,13 @@ public class BeanFilter {
if (isNotVoid(x.propertyNamer()))
propertyNamer(x.propertyNamer());
if (isNotVoid(x.interfaceClass()))
- interfaceClass(x.interfaceClass());
+
interfaceClass(info(x.interfaceClass()));
if (isNotVoid(x.stopClass()))
- stopClass(x.stopClass());
+ stopClass(info(x.stopClass()));
if (isNotVoid(x.interceptor()))
interceptor(x.interceptor());
if (isNotVoid(x.implClass()))
- implClass(x.implClass());
+ implClass(info(x.implClass()));
if (isNotEmptyArray(x.dictionary()))
dictionary(x.dictionary());
if (isNotEmpty(x.example()))
@@ -279,6 +279,20 @@ public class BeanFilter {
* @return This object.
*/
public Builder implClass(Class<?> value) {
+ this.implClass = value == null ? null : info(value);
+ return this;
+ }
+
+ /**
+ * Implementation class.
+ *
+ * <p>
+ * Same as the other implClass method but accepts a {@link
ClassInfo} object directly instead of a {@link Class} object.
+ *
+ * @param value The new value for this setting.
+ * @return This object.
+ */
+ public Builder implClass(ClassInfo value) {
this.implClass = value;
return this;
}
@@ -372,6 +386,20 @@ public class BeanFilter {
* @return This object.
*/
public Builder interfaceClass(Class<?> value) {
+ this.interfaceClass = value == null ? null :
info(value);
+ return this;
+ }
+
+ /**
+ * Interface class.
+ *
+ * <p>
+ * Same as the other interfaceClass method but accepts a {@link
ClassInfo} object directly instead of a {@link Class} object.
+ *
+ * @param value The new value for this setting.
+ * @return This object.
+ */
+ public Builder interfaceClass(ClassInfo value) {
this.interfaceClass = value;
return this;
}
@@ -621,6 +649,20 @@ public class BeanFilter {
* @return This object.
*/
public Builder stopClass(Class<?> value) {
+ this.stopClass = value == null ? null : info(value);
+ return this;
+ }
+
+ /**
+ * Stop class.
+ *
+ * <p>
+ * Same as the other stopClass method but accepts a {@link
ClassInfo} object directly instead of a {@link Class} object.
+ *
+ * @param value The new value for this setting.
+ * @return This object.
+ */
+ public Builder stopClass(ClassInfo value) {
this.stopClass = value;
return this;
}
@@ -725,14 +767,14 @@ public class BeanFilter {
private final String example;
private final Set<String> excludeProperties;
private final boolean fluentSetters;
- private final Class<?> implClass;
- private final Class<?> interfaceClass;
+ private final ClassInfo implClass;
+ private final ClassInfo interfaceClass;
private final BeanInterceptor interceptor;
private final Set<String> properties;
private final PropertyNamer propertyNamer;
private final Set<String> readOnlyProperties;
private final boolean sortProperties;
- private final Class<?> stopClass;
+ private final ClassInfo stopClass;
private final String typeName;
private final Set<String> writeOnlyProperties;
@@ -790,14 +832,14 @@ public class BeanFilter {
*
* @return The implementation class associated with this class, or
<jk>null</jk> if no implementation class is associated.
*/
- public Class<?> getImplClass() { return implClass; }
+ public ClassInfo getImplClass() { return implClass; }
/**
* Returns the interface class associated with this class.
*
* @return The interface class associated with this class, or
<jk>null</jk> if no interface class is associated.
*/
- public Class<?> getInterfaceClass() { return interfaceClass; }
+ public ClassInfo getInterfaceClass() { return interfaceClass; }
/**
* Returns the set and order of names of properties associated with a
bean class.
@@ -827,7 +869,7 @@ public class BeanFilter {
*
* @return The stop class associated with this class, or <jk>null</jk>
if no stop class is associated.
*/
- public Class<?> getStopClass() { return stopClass; }
+ public ClassInfo getStopClass() { return stopClass; }
/**
* Returns the dictionary name associated with this bean.
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 fdbde1f55a..eba30e0626 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
@@ -358,7 +358,7 @@ public class BeanMeta<T> {
private final Map<String,BeanPropertyMeta> properties;
// The properties on the target class.
private final Map<Method,String> setterProps;
// The setter properties on the target class.
private final boolean sortProperties;
// Whether properties should be sorted.
- private final Class<?> stopClass;
// The stop class for hierarchy traversal.
+ private final ClassInfo stopClass;
// The stop class for hierarchy traversal.
private final BeanPropertyMeta typeProperty;
// "_type" mock bean property.
private final String typePropertyName;
// "_type" property actual name.
@@ -385,14 +385,13 @@ public class BeanMeta<T> {
* @param pNames Explicit list of property names and order. If
<jk>null</jk>, properties are determined automatically.
* @param implClass Optional implementation class constructor to use if
one cannot be found. Can be <jk>null</jk>.
*/
- @SuppressWarnings("rawtypes")
protected BeanMeta(ClassMeta<T> cm, BeanFilter bf, String[] pNames,
ClassInfo implClass) {
classMeta = cm;
beanContext = cm.getBeanContext();
beanFilter = bf;
implClassConstructor = opt(implClass).map(x ->
x.getPublicConstructor(x2 -> x2.hasNumParameters(0)).orElse(null)).orElse(null);
fluentSetters = beanContext.isFindFluentSetters() || (nn(bf) &&
bf.isFluentSetters());
- stopClass = opt(bf).map(x ->
(Class)x.getStopClass()).orElse(Object.class);
+ stopClass = opt(bf).map(x ->
x.getStopClass()).orElse(info(Object.class));
beanRegistry = memoize(()->findBeanRegistry());
classHierarchy = memoize(()->findClassHierarchy());
beanConstructor = findBeanConstructor();
@@ -428,12 +427,12 @@ public class BeanMeta<T> {
fixedBeanProps.forEach(x -> normalProps.put(x,
BeanPropertyMeta.builder(this, x)));
if (beanContext.isUseJavaBeanIntrospector()) {
- var c2 = bfo.map(x ->
(Class)x.getInterfaceClass()).filter(Objects::nonNull).orElse(c);
+ var c2 = bfo.map(x ->
x.getInterfaceClass()).filter(Objects::nonNull).orElse(classMeta);
var bi = (BeanInfo)null;
if (! c2.isInterface())
- bi = Introspector.getBeanInfo(c2,
stopClass);
+ bi =
Introspector.getBeanInfo(c2.inner(), stopClass.inner());
else
- bi = Introspector.getBeanInfo(c2, null);
+ bi =
Introspector.getBeanInfo(c2.inner(), null);
if (nn(bi)) {
for (var pd :
bi.getPropertyDescriptors()) {
normalProps.computeIfAbsent(pd.getName(), n -> BeanPropertyMeta.builder(this,
n)).setGetter(pd.getReadMethod()).setSetter(pd.getWriteMethod());
@@ -1228,8 +1227,8 @@ public class BeanMeta<T> {
var result = new LinkedList<ClassInfo>();
// If @Bean.interfaceClass is specified on the parent class,
then we want
// to use the properties defined on that class, not the
subclass.
- var c2 = (nn(beanFilter) && nn(beanFilter.getInterfaceClass())
? beanFilter.getInterfaceClass() : classMeta.inner());
- findClassHierarchy(info(c2), stopClass, result::add);
+ var c2 = (nn(beanFilter) && nn(beanFilter.getInterfaceClass())
? beanFilter.getInterfaceClass() : classMeta);
+ findClassHierarchy(c2, stopClass, result::add);
return u(result);
}
@@ -1251,9 +1250,9 @@ public class BeanMeta<T> {
* @param stopClass The class to stop traversal at (exclusive).
Traversal will not proceed beyond this class.
* @param consumer The consumer to invoke for each class in the
hierarchy.
*/
- private void findClassHierarchy(ClassInfo c, Class<?> stopClass,
Consumer<ClassInfo> consumer) {
+ private void findClassHierarchy(ClassInfo c, ClassInfo stopClass,
Consumer<ClassInfo> consumer) {
var sc = c.getSuperclass();
- if (nn(sc) && ! sc.is(stopClass))
+ if (nn(sc) && ! sc.is(stopClass.inner()))
findClassHierarchy(sc, stopClass, consumer);
c.getInterfaces().forEach(x -> findClassHierarchy(x, stopClass,
consumer));
consumer.accept(c);