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 4cd4711e3d Marshall module improvements
4cd4711e3d is described below
commit 4cd4711e3d65374788d34f134acf9bfff9148cd9
Author: James Bognar <[email protected]>
AuthorDate: Fri Dec 12 14:03:27 2025 -0500
Marshall module improvements
---
.../juneau/commons/reflect/TypeVariables.java | 2 +-
.../main/java/org/apache/juneau/BeanFilter.java | 96 ++++++++++++++++++++--
.../apache/juneau/html/HtmlBeanPropertyMeta.java | 1 -
3 files changed, 89 insertions(+), 10 deletions(-)
diff --git
a/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/reflect/TypeVariables.java
b/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/reflect/TypeVariables.java
index 04f8832280..c7a9cab40e 100644
---
a/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/reflect/TypeVariables.java
+++
b/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/reflect/TypeVariables.java
@@ -314,7 +314,7 @@ public class TypeVariables {
if (type instanceof TypeVariable<?> tv) {
if (typeVars == null)
return null;
- return typeVars.resolve(type);
+ return typeVars.resolve(tv);
}
return null;
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 2300bafdaf..e821e77d9e 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
@@ -31,14 +31,49 @@ import org.apache.juneau.cp.*;
import org.apache.juneau.swap.*;
/**
- * TODO
+ * Bean filter for customizing bean property handling during serialization and
parsing.
*
* <p>
- * Bean filters are used to control aspects of how beans are handled during
serialization and parsing.
+ * Bean filters provide fine-grained control over how beans are processed,
allowing you to:
+ * <ul>
+ * <li>Specify which properties to include or exclude
+ * <li>Define read-only and write-only properties
+ * <li>Control property ordering and naming
+ * <li>Configure bean dictionaries for polymorphic types
+ * <li>Intercept property getter and setter calls
+ * <li>Define interface classes and stop classes for property filtering
+ * </ul>
*
* <p>
- * Bean filters are created by {@link Builder} which is the programmatic
equivalent to the {@link Bean @Bean}
- * annotation.
+ * Bean filters are created using the {@link Builder} class, which is the
programmatic equivalent to the
+ * {@link Bean @Bean} annotation. Filters can be registered with serializers
and parsers to customize
+ * how specific bean classes are handled.
+ *
+ * <h5 class='section'>Example:</h5>
+ * <p class='bjava'>
+ * <jc>// Define a custom filter for MyBean</jc>
+ * <jk>public class</jk> MyBeanFilter <jk>extends</jk>
BeanFilter.Builder<MyBean> {
+ * <jk>public</jk> MyBeanFilter() {
+ * properties(<js>"id,name,email"</js>); <jc>// Only
include these properties</jc>
+ * excludeProperties(<js>"password"</js>); <jc>// Exclude
sensitive data</jc>
+ * readOnlyProperties(<js>"id"</js>); <jc>// ID is
read-only</jc>
+ * sortProperties(); <jc>// Sort properties
alphabetically</jc>
+ * }
+ * }
+ *
+ * <jc>// Register the filter with a serializer</jc>
+ * WriterSerializer <jv>serializer</jv> = JsonSerializer
+ * .<jsm>create</jsm>()
+ * .beanFilters(MyBeanFilter.<jk>class</jk>)
+ * .build();
+ * </p>
+ *
+ * <h5 class='section'>See Also:</h5>
+ * <ul>
+ * <li class='ja'>{@link Bean @Bean}
+ * <li class='jc'>{@link BeanInterceptor}
+ * <li class='jc'>{@link PropertyNamer}
+ * </ul>
*/
@SuppressWarnings("rawtypes")
public class BeanFilter {
@@ -46,7 +81,7 @@ public class BeanFilter {
/**
* Builder class.
*/
- protected static class Builder {
+ public static class Builder {
private ClassInfoTyped<?> beanClass;
private String typeName, example;
@@ -92,13 +127,13 @@ public class BeanFilter {
if (isNotVoid(x.propertyNamer()))
propertyNamer(x.propertyNamer());
if (isNotVoid(x.interfaceClass()))
-
interfaceClass(info(x.interfaceClass()));
+ interfaceClass(x.interfaceClass());
if (isNotVoid(x.stopClass()))
- stopClass(info(x.stopClass()));
+ stopClass(x.stopClass());
if (isNotVoid(x.interceptor()))
interceptor(x.interceptor());
if (isNotVoid(x.implClass()))
- implClass(info(x.implClass()));
+ implClass(x.implClass());
if (isNotEmptyArray(x.dictionary()))
dictionary(x.dictionary());
if (isNotEmpty(x.example()))
@@ -335,6 +370,28 @@ public class BeanFilter {
return this;
}
+ /**
+ * Bean interceptor.
+ *
+ * <p>
+ * Same as the other interceptor method but accepts a {@link
ClassInfo} object directly instead of a {@link Class} object.
+ *
+ * <p>
+ * The interceptor to use for intercepting and altering getter
and setter calls.
+ *
+ * <h5 class='section'>See Also:</h5><ul>
+ * <li class='ja'>{@link Bean#interceptor()}
+ * <li class='jc'>{@link BeanInterceptor}
+ * </ul>
+ *
+ * @param value The new value for this setting.
+ * @return This object.
+ */
+ public Builder interceptor(ClassInfo value) {
+ this.interceptor.type(value);
+ return this;
+ }
+
/**
* Bean interface class.
*
@@ -491,6 +548,29 @@ public class BeanFilter {
return this;
}
+ /**
+ * Bean property namer.
+ *
+ * <p>
+ * Same as the other propertyNamer method but accepts a {@link
ClassInfoTyped} object directly instead of a {@link Class} object.
+ *
+ * <p>
+ * The class to use for calculating bean property names.
+ *
+ * <h5 class='section'>See Also:</h5><ul>
+ * <li class='ja'>{@link Bean#propertyNamer()}
+ * <li class='jm'>{@link
BeanContext.Builder#propertyNamer(Class)}
+ * <li class='jc'>{@link PropertyNamer}
+ * </ul>
+ *
+ * @param value The new value for this setting.
+ * @return This object.
+ */
+ public Builder propertyNamer(ClassInfoTyped<? extends
PropertyNamer> value) {
+ this.propertyNamer.type(value);
+ return this;
+ }
+
/**
* Read-only bean properties.
*
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/html/HtmlBeanPropertyMeta.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/html/HtmlBeanPropertyMeta.java
index 4223572fda..930f293767 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/html/HtmlBeanPropertyMeta.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/html/HtmlBeanPropertyMeta.java
@@ -16,7 +16,6 @@
*/
package org.apache.juneau.html;
-import static org.apache.juneau.commons.reflect.ReflectionUtils.*;
import static org.apache.juneau.commons.utils.Utils.*;
import org.apache.juneau.*;