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 79aaf3e2b5 Marshall module improvements
79aaf3e2b5 is described below
commit 79aaf3e2b5876ad053b3e8d954289433571d4e54
Author: James Bognar <[email protected]>
AuthorDate: Sat Dec 6 09:55:20 2025 -0500
Marshall module improvements
---
.../apache/juneau/commons/reflect/Property.java | 11 +++++---
.../src/main/java/org/apache/juneau/ClassMeta.java | 30 ++++++++++------------
.../org/apache/juneau/parser/ParserSession.java | 4 +--
3 files changed, 23 insertions(+), 22 deletions(-)
diff --git
a/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/reflect/Property.java
b/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/reflect/Property.java
index 6f31dba9ce..864a4a40ce 100644
---
a/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/reflect/Property.java
+++
b/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/reflect/Property.java
@@ -208,8 +208,9 @@ public class Property<T, V> {
public Builder<T, V> field(FieldInfo field) {
assertArgNotNull("field", field);
field.accessible();
- this.producer = obj -> (V)field.get(obj);
- this.consumer = (obj, val) -> field.set(obj, val);
+ boolean isStatic = field.isStatic();
+ this.producer = obj -> (V)field.get(isStatic ? null :
obj);
+ this.consumer = (obj, val) -> field.set(isStatic ? null
: obj, val);
return this;
}
@@ -226,7 +227,8 @@ public class Property<T, V> {
public Builder<T, V> getter(MethodInfo method) {
assertArgNotNull("method", method);
method.accessible();
- this.producer = obj -> (V)method.invoke(obj);
+ boolean isStatic = method.isStatic();
+ this.producer = obj -> (V)method.invoke(isStatic ? null
: obj);
return this;
}
@@ -242,7 +244,8 @@ public class Property<T, V> {
public Builder<T, V> setter(MethodInfo method) {
assertArgNotNull("method", method);
method.accessible();
- this.consumer = (obj, val) -> method.invoke(obj, val);
+ boolean isStatic = method.isStatic();
+ this.consumer = (obj, val) -> method.invoke(isStatic ?
null : obj, val);
return this;
}
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 349f763c69..b3053fc349 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
@@ -162,10 +162,10 @@ public class ClassMeta<T> extends ClassInfoTyped<T> {
private final ClassMeta<?> keyType;
// If MAP, the key class type.
private final SimpleReadWriteLock lock = new SimpleReadWriteLock(false);
private final Supplier<MarshalledFilter> marshalledFilter;
- private final Supplier<Setter> namePropertySetter;
// The method to set the name on an
object (if it has one).
+ private final Supplier<Property<T,String>> namePropertySetter;
// The method to set the name on an object
(if it has one).
private final Supplier<ConstructorInfo> noArgConstructor;
// The no-arg constructor for this
class (if it has one).
private final String notABeanReason;
// If this isn't a bean, the reason why.
- private final Supplier<Setter> parentPropertySetter;
// The method to set the parent on an
object (if it has one).
+ private final Supplier<Property<T,?>> parentPropertySetter;
// The method to set the parent on an object (if
it has one).
private final Map<String,Optional<?>> properties = new
ConcurrentHashMap<>();
private final Mutater<String,T> stringMutater;
private final Supplier<ConstructorInfo> stringConstructor;
// The X(String) constructor (if it has
one).
@@ -742,7 +742,7 @@ public class ClassMeta<T> extends ClassInfoTyped<T> {
* The method or field annotated with {@link NameProperty
@NameProperty} or <jk>null</jk> if method does not
* exist.
*/
- public Setter getNameProperty() { return namePropertySetter.get(); }
+ public Property<T,String> getNameProperty() { return
namePropertySetter.get(); }
/**
* Returns the reason why this class is not a bean, or <jk>null</jk> if
it is a bean.
@@ -772,7 +772,7 @@ public class ClassMeta<T> extends ClassInfoTyped<T> {
* The method or field annotated with {@link ParentProperty
@ParentProperty} or <jk>null</jk> if method does not
* exist.
*/
- public Setter getParentProperty() { return parentPropertySetter.get(); }
+ public Property<T,?> getParentProperty() { return
parentPropertySetter.get(); }
/**
* Returns a calculated property on this context.
@@ -1568,24 +1568,23 @@ public class ClassMeta<T> extends ClassInfoTyped<T> {
return
MarshalledFilter.create(inner()).applyAnnotations(reverse(l.stream().map(AnnotationInfo::inner).toList())).build();
}
- private Setter findNamePropertySetter() {
+ private Property<T,String> findNamePropertySetter() {
var ap = beanContext.getAnnotationProvider();
var s = getAllFields()
.stream()
- .filter(x -> x.isStatic() && ap.has(NameProperty.class,
x))
+ .filter(x -> x.getFieldType().is(String.class) &&
ap.has(NameProperty.class, x))
.map(x -> x.accessible())
- .map(x -> new Setter.FieldSetter(x))
+ .map(x -> Property.<T,String>create().field(x).build())
.findFirst();
if (s.isPresent()) return s.get();
return getAllMethods()
.stream()
- .filter(x -> x.isStatic() || x.hasNumParameters(1))
- .filter(x -> ap.has(NameProperty.class, x))
+ .filter(x -> ap.has(NameProperty.class, x) &&
x.hasNumParameters(1))
.map(x -> x.accessible())
- .map(x -> new Setter.MethodSetter(x))
+ .map(x -> Property.<T,String>create().setter(x).build())
.findFirst()
.orElse(null);
}
@@ -1609,24 +1608,23 @@ public class ClassMeta<T> extends ClassInfoTyped<T> {
.orElse(null);
}
- private Setter findParentPropertySetter() {
+ private Property<T,?> findParentPropertySetter() {
var ap = beanContext.getAnnotationProvider();
var s = getAllFields()
.stream()
- .filter(x -> x.isStatic() &&
ap.has(ParentProperty.class, x))
+ .filter(x -> ap.has(ParentProperty.class, x))
.map(x -> x.accessible())
- .map(x -> new Setter.FieldSetter(x))
+ .map(x -> Property.<T,Object>create().field(x).build())
.findFirst();
if (s.isPresent()) return s.get();
return getAllMethods()
.stream()
- .filter(x -> x.isStatic() || x.hasNumParameters(1))
- .filter(x -> ap.has(ParentProperty.class, x))
+ .filter(x -> ap.has(ParentProperty.class, x) &&
x.hasNumParameters(1))
.map(x -> x.accessible())
- .map(x -> new Setter.MethodSetter(x))
+ .map(x -> Property.<T,Object>create().setter(x).build())
.findFirst()
.orElse(null);
}
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/parser/ParserSession.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/parser/ParserSession.java
index 6928c91973..4f22375eb8 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/parser/ParserSession.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/parser/ParserSession.java
@@ -219,7 +219,7 @@ public class ParserSession extends BeanSession {
*/
protected static final void setName(ClassMeta<?> cm, Object o, Object
name) throws ExecutableException {
if (nn(cm)) {
- Setter m = cm.getNameProperty();
+ Property m = cm.getNameProperty();
if (nn(m))
m.set(o, name);
}
@@ -235,7 +235,7 @@ public class ParserSession extends BeanSession {
* @throws ExecutableException Exception occurred on invoked
constructor/method/field.
*/
protected static final void setParent(ClassMeta<?> cm, Object o, Object
parent) throws ExecutableException {
- Setter m = cm.getParentProperty();
+ Property m = cm.getParentProperty();
if (nn(m))
m.set(o, parent);
}