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 781511317f Marshall module improvements
781511317f is described below
commit 781511317ff043ba0d645deed514d1d8d3f7d1c3
Author: James Bognar <[email protected]>
AuthorDate: Tue Dec 9 11:20:40 2025 -0500
Marshall module improvements
---
.../src/main/java/org/apache/juneau/BeanMap.java | 26 +++++++++++----------
.../src/main/java/org/apache/juneau/BeanMeta.java | 27 ++++++++++------------
2 files changed, 26 insertions(+), 27 deletions(-)
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanMap.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanMap.java
index 5005c9daf4..73e050a677 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanMap.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanMap.java
@@ -226,9 +226,10 @@ public class BeanMap<T> extends AbstractMap<String,Object>
implements Delegate<T
* @return This object.
*/
public BeanMap<T> forEachProperty(Predicate<BeanPropertyMeta> filter,
Consumer<BeanPropertyMeta> action) {
- for (var bpm : meta.propertyArray)
- if (filter.test(bpm))
- action.accept(bpm);
+
meta.getProperties().values().stream().filter(filter).forEach(action);
+// for (var bpm : meta.propertyArray)
+// if (filter.test(bpm))
+// action.accept(bpm);
return this;
}
@@ -389,16 +390,17 @@ public class BeanMap<T> extends
AbstractMap<String,Object> implements Delegate<T
}
// Initialize any null Optional<X> fields.
- for (var pMeta : this.meta.propertyArray) {
- var cm = pMeta.getClassMeta();
- if (cm.isOptional() && pMeta.get(this, pMeta.getName())
== null)
- pMeta.set(this, pMeta.getName(),
cm.getOptionalDefault());
- }
+ meta.getProperties().forEach((k,v) -> {
+ var cm = v.getClassMeta();
+ if (cm.isOptional() && v.get(this, k) == null)
+ v.set(this, k, cm.getOptionalDefault());
+ });
+
// Do the same for hidden fields.
- this.meta.hiddenProperties.forEach((k, v) -> {
+ meta.getHiddenProperties().forEach((k, v) -> {
var cm = v.getClassMeta();
- if (cm.isOptional() && v.get(this, v.getName()) == null)
- v.set(this, v.getName(),
cm.getOptionalDefault());
+ if (cm.isOptional() && v.get(this, k) == null)
+ v.set(this, k, cm.getOptionalDefault());
});
return b;
@@ -658,7 +660,7 @@ public class BeanMap<T> extends AbstractMap<String,Object>
implements Delegate<T
*
* @return A simple collection of properties for this bean map.
*/
- protected Collection<BeanPropertyMeta> getProperties() { return
l(meta.propertyArray); }
+ protected Collection<BeanPropertyMeta> getProperties() { return
meta.getProperties().values(); }
@SuppressWarnings("unchecked")
void setBean(Object bean) { this.bean = (T)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 d4f43ec3e6..962c61a61c 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
@@ -465,8 +465,6 @@ public class BeanMeta<T> {
/** The properties on the target class. */
protected final Map<String,BeanPropertyMeta> properties;
- /** The properties on the target class. */
- protected final BeanPropertyMeta[] propertyArray;
/** The hidden properties on the target class. */
protected final Map<String,BeanPropertyMeta> hiddenProperties;
/** The getter properties on the target class. */
@@ -879,7 +877,6 @@ public class BeanMeta<T> {
// Assign to final fields
this.notABeanReason = notABeanReason;
this.properties = u(properties.get());
- this.propertyArray = this.properties == null ? EMPTY_PROPERTIES
: array(this.properties.values(), BeanPropertyMeta.class);
this.hiddenProperties = u(hiddenProperties);
this.getterProps = u(getterProps);
this.setterProps = u(setterProps);
@@ -888,12 +885,18 @@ public class BeanMeta<T> {
this.typeProperty = BeanPropertyMeta.builder(this,
typePropertyName).canRead().canWrite().rawMetaType(ctx.string()).beanRegistry(beanRegistry.get()).build();
- if (sortProperties)
- Arrays.sort(propertyArray);
dictionaryName2 = memoize(()->findDictionaryName());
beanProxyInvocationHandler =
memoize(()->ctx.isUseInterfaceProxies() && c.isInterface() ? new
BeanProxyInvocationHandler<>(this) : null);
}
+ protected Map<String,BeanPropertyMeta> getProperties() {
+ return properties;
+ }
+
+ protected Map<String,BeanPropertyMeta> getHiddenProperties() {
+ return hiddenProperties;
+ }
+
protected boolean hasConstructor() {
return beanConstructor.constructor().isPresent();
}
@@ -920,10 +923,7 @@ public class BeanMeta<T> {
* @return The result of the function. Never <jk>null</jk>.
*/
public <T2> Optional<T2> firstProperty(Predicate<BeanPropertyMeta>
filter, Function<BeanPropertyMeta,T2> function) {
- for (var x : propertyArray)
- if (test(filter, x))
- return opt(function.apply(x));
- return opte();
+ return
properties.values().stream().filter(filter).map(function).findFirst();
}
/**
@@ -933,9 +933,7 @@ public class BeanMeta<T> {
* @param action The action to apply.
*/
public void forEachProperty(Predicate<BeanPropertyMeta> filter,
Consumer<BeanPropertyMeta> action) {
- for (var x : propertyArray)
- if (test(filter, x))
- action.accept(x);
+ properties.values().stream().filter(x -> filter == null ? true
: filter.test(x)).forEach(action);
}
/**
@@ -1006,7 +1004,7 @@ public class BeanMeta<T> {
*
* @return Metadata on all properties associated with this bean.
*/
- public Collection<BeanPropertyMeta> getPropertyMetas() { return
u(l(propertyArray)); }
+ public Collection<BeanPropertyMeta> getPropertyMetas() { return
properties.values(); }
/**
* Returns a mock bean property that resolves to the name
<js>"_type"</js> and whose value always resolves to the
@@ -1055,8 +1053,7 @@ public class BeanMeta<T> {
public String toString() {
var sb = new StringBuilder(c.getName());
sb.append(" {\n");
- for (var pm : propertyArray)
- sb.append('\t').append(pm.toString()).append(",\n");
+ properties.values().forEach(x ->
sb.append('\t').append(x.toString()).append(",\n"));
sb.append('}');
return sb.toString();
}