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
commit 98b9f272a151d2df92cf562a080af15738a102b5 Author: James Bognar <[email protected]> AuthorDate: Wed May 13 09:09:00 2026 -0400 refactor: remove @MarshalledProp(properties) feature and BeanMetaFiltered class (breaking) Simplifies the remaining bean-runtime move by eliminating the child-properties filter machinery: applyChildPropertiesFilter, swapAndFilterProperty filter logic, the properties field/getter/builder, BeanMetaFiltered class, and one of the remaining MarshallingContext casts. Co-authored-by: Cursor <[email protected]> --- .../java/org/apache/juneau/BeanMetaFiltered.java | 50 --------- .../java/org/apache/juneau/BeanPropertyMeta.java | 105 ++---------------- .../juneau/MarshalledPropertyPostProcessor.java | 8 -- .../apache/juneau/annotation/MarshalledProp.java | 37 +------ .../annotation/MarshalledPropAnnotation.java | 19 ---- .../apache/juneau/internal/DelegateBeanMap.java | 3 - .../jsonschema/JsonSchemaGeneratorSession.java | 24 ++--- .../annotation/MarshalledPropAnnotation_Test.java | 8 +- .../java/org/apache/juneau/html/Common_Test.java | 119 --------------------- .../java/org/apache/juneau/json/Common_Test.java | 45 -------- .../java/org/apache/juneau/json5/Common_Test.java | 45 -------- .../java/org/apache/juneau/uon/Common_UonTest.java | 41 ------- .../juneau/urlencoding/Common_UrlEncodingTest.java | 44 -------- .../java/org/apache/juneau/xml/Common_Test.java | 54 ---------- .../test/java/org/apache/juneau/xml/Xml_Test.java | 21 ---- todo/TODO-5-bean-runtime-types-to-commons.md | 34 ++++++ 16 files changed, 57 insertions(+), 600 deletions(-) diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanMetaFiltered.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanMetaFiltered.java deleted file mode 100644 index 0112e90c82..0000000000 --- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanMetaFiltered.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.juneau; - -import java.util.*; - -import org.apache.juneau.annotation.*; - -/** - * Same as {@link BeanMeta}, except the list of bean properties are limited by a {@link MarshalledProp#properties() @MarshalledProp(properties)} annotation. - * - * - * @param <T> The class type that this metadata applies to. - */ -public class BeanMetaFiltered<T> extends BeanMeta<T> { - - /** - * Wrapper constructor. - * - * @param innerMeta The untransformed bean meta of the bean property. - * @param pNames The list of transformed property names. - */ - public BeanMetaFiltered(BeanMeta<T> innerMeta, Collection<String> pNames) { - this(innerMeta, pNames.toArray(new String[pNames.size()])); - } - - /** - * Wrapper constructor. - * - * @param innerMeta The untransformed bean meta of the bean property. - * @param pNames The list of transformed property names. - */ - public BeanMetaFiltered(BeanMeta<T> innerMeta, String[] pNames) { - super(innerMeta.getClassMeta(), innerMeta.getMarshalledFilter(), pNames, null); - } -} \ No newline at end of file diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanPropertyMeta.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanPropertyMeta.java index 81cda3d4ad..1eb2c56926 100644 --- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanPropertyMeta.java +++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanPropertyMeta.java @@ -39,7 +39,6 @@ import org.apache.juneau.commons.lang.*; import org.apache.juneau.commons.reflect.*; import org.apache.juneau.commons.reflect.ReflectionUtils; import org.apache.juneau.commons.inject.*; -import org.apache.juneau.internal.*; import org.apache.juneau.parser.*; import org.apache.juneau.serializer.*; import org.apache.juneau.swap.*; @@ -101,7 +100,6 @@ public class BeanPropertyMeta implements Comparable<BeanPropertyMeta> { private boolean isDyna; private boolean isDynaGetterMap; BeanTypeInfo<?> typeMeta; // Package-private so the marshalling-side post-processor can override after @Swap/@MarshalledProp detection. Concrete instances are always {@link ClassMeta}; typed against the bean-modeling SPI seam. - List<String> properties; // Package-private so the marshalling-side post-processor can install @MarshalledProp(properties) override list. private Object overrideValue; private BeanPropertyMeta delegateFor; private boolean canRead; @@ -516,7 +514,6 @@ public class BeanPropertyMeta implements Comparable<BeanPropertyMeta> { private final boolean isUri; // True if this is a URL/URI or annotated with @URI. private final String name; // The name of the property. private final Object overrideValue; // The bean property value (if it's an overridden delegate). - private final List<String> properties; // The value of the @MarshalledProp(properties) annotation (unmodifiable). private final BeanTypeInfo<?> rawTypeMeta; // The real class type of the bean property. Concrete instances are always {@link ClassMeta}; typed against the bean-modeling SPI seam for the eventual move to commons.bean. private final BiFunction<MarshallingSession,Object,Object> readTransform; // Applied to raw getter result; identity by default. private final boolean readOnly; // True if this property is read-only. @@ -548,7 +545,6 @@ public class BeanPropertyMeta implements Comparable<BeanPropertyMeta> { isUri = b.isUri; name = b.name; overrideValue = b.overrideValue; - properties = u(b.properties); rawTypeMeta = b.rawTypeMeta; readOnly = b.readOnly; setter = b.setter; @@ -975,14 +971,6 @@ public class BeanPropertyMeta implements Comparable<BeanPropertyMeta> { */ public String getName() { return name; } - /** - * Returns the override list of properties defined through a {@link MarshalledProp#properties() @MarshalledProp(properties)} annotation - * on this property. - * - * @return An unmodifiable list of override properties, or <jk>null</jk> if annotation not specified. - */ - public List<String> getProperties() { return properties; } - /** * Equivalent to calling {@link BeanMap#getRaw(Object)}, but is faster since it avoids looking up the property meta. * @@ -1300,53 +1288,6 @@ public class BeanPropertyMeta implements Comparable<BeanPropertyMeta> { return r(properties()); } - /** - * Applies the {@link MarshalledProp#properties() @MarshalledProp(properties)} child-property filter to a value. - * - * <p> - * <b>Marshalling-only.</b> The signature itself takes a {@link ClassMeta} and {@link MarshallingSession}, - * which are marshalling-side types; this helper is only reachable from {@link #swapAndFilterProperty}, - * which short-circuits when the owning {@link BeanMeta} was built via - * {@link BeanMeta#of(Class, BeanConfigContext)} (no {@link MarshallingContext} on the property, - * therefore no {@code rawTypeMeta}). - * - * @throws UnsupportedOperationException If invoked on a property built via the bean-modeling-only path. - */ - private Object applyChildPropertiesFilter(MarshallingSession session, ClassMeta cm, Object o) { - if (bc == null) - throw unsupportedOp("Property ''{0}'' was built via the bean-modeling-only path; child-properties filtering requires a marshalling context.", name); - if (o == null) - return null; - if (cm.isBean()) - return newBeanMap(session, o, new BeanMetaFiltered(cm.getBeanMeta(), properties)); - if (cm.isMap()) { - var propsArray = properties == null ? null : properties.toArray(new String[0]); - return new FilteredKeyMap(cm, (Map)o, propsArray); - } - if (cm.isObject()) { - if (o instanceof Map o2) { - var propsArray = properties == null ? null : properties.toArray(new String[0]); - return new FilteredKeyMap(cm, o2, propsArray); - } - var bm = ((MarshallingContext) bc).getBeanMeta(o.getClass()); - if (nn(bm)) - return newBeanMap(session, o, new BeanMetaFiltered(cm.getBeanMeta(), properties)); - } - return o; - } - - @SuppressWarnings({ - "unchecked" // Type erasure requires unchecked cast for filtered bean map construction - }) - private static BeanMap newBeanMap(MarshallingSession session, Object o, BeanMetaFiltered meta) { - var bm = new BeanMap(o, meta); - bm.setMarshallingSession(session); - return bm; - } - - @SuppressWarnings({ - "java:S3776" // Cognitive complexity acceptable for inner property getter with delegate/swap handling - }) private Object getInner(BeanMap<?> m, String pName) { try { @@ -1361,47 +1302,19 @@ public class BeanPropertyMeta implements Comparable<BeanPropertyMeta> { if (bean == null) return m.propertyCache.get(name); - var session = m.getMarshallingSession(); - var o = getRaw(m, pName); + var session = m.getMarshallingSession(); + var o = getRaw(m, pName); - return swapAndFilterProperty(session, o); + return readTransform.apply(session, o); - } catch (Exception e) { - if (config.isIgnoreInvocationExceptionsOnGetters()) { - if (nn(rawTypeMeta) && rawTypeMeta.isPrimitive()) - return rawTypeMeta.getPrimitiveDefault(); - return null; - } - throw bex(e, beanMeta.getClassInfo(), "Exception occurred while getting property ''{0}''", name); - } - } - - private Object swapAndFilterProperty(MarshallingSession session, Object o) { - o = readTransform.apply(session, o); - if (o == null) - return null; - // rawTypeMeta is null on the bean-modeling-only path — child-properties filtering is a marshalling - // concern (it builds DelegateList / FilteredKeyMap / nested BeanMetaFiltered instances). Skip it and - // return the raw value. - if (nn(properties) && nn(rawTypeMeta)) { - if (rawTypeMeta.isArray()) { - var a = (Object[])o; - var l1 = new DelegateList((ClassMeta<?>) rawTypeMeta); - var childType1 = (ClassMeta<?>) rawTypeMeta.getElementType(); - for (var c1 : a) - l1.add(applyChildPropertiesFilter(session, childType1, c1)); - return l1; - } else if (rawTypeMeta.isCollection()) { - var c = (Collection)o; - var l = listOfSize(c.size()); - var childType = (ClassMeta<?>) rawTypeMeta.getElementType(); - c.forEach(x -> l.add(applyChildPropertiesFilter(session, childType, x))); - return l; - } else { - return applyChildPropertiesFilter(session, (ClassMeta<?>) rawTypeMeta, o); + } catch (Exception e) { + if (config.isIgnoreInvocationExceptionsOnGetters()) { + if (nn(rawTypeMeta) && rawTypeMeta.isPrimitive()) + return rawTypeMeta.getPrimitiveDefault(); + return null; } + throw bex(e, beanMeta.getClassInfo(), "Exception occurred while getting property ''{0}''", name); } - return o; } private Object invokeGetter(Object bean, String pName) throws IllegalArgumentException { diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/MarshalledPropertyPostProcessor.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/MarshalledPropertyPostProcessor.java index 7f6defe51b..d7638d1591 100644 --- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/MarshalledPropertyPostProcessor.java +++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/MarshalledPropertyPostProcessor.java @@ -19,7 +19,6 @@ package org.apache.juneau; import static org.apache.juneau.commons.reflect.ReflectionUtils.*; import static org.apache.juneau.commons.utils.ClassUtils.*; import static org.apache.juneau.commons.utils.CollectionUtils.*; -import static org.apache.juneau.commons.utils.StringUtils.*; import static org.apache.juneau.commons.utils.ThrowableUtils.*; import static org.apache.juneau.commons.utils.Utils.*; @@ -48,7 +47,6 @@ import org.apache.juneau.swaps.*; * <ul> * <li>{@code swap} — set to a {@link StringFormatSwap} (from {@link MarshalledProp#format()}) or a custom * {@link ObjectSwap} (from {@link Swap}). - * <li>{@code properties} — set to the property-override list from {@link MarshalledProp#properties()}. * <li>{@code dictionaryClasses} — appended with the {@link MarshalledProp#dictionary()} entries. * <li>{@code typeMeta} — refreshed to the swap class meta when a swap is installed. * </ul> @@ -79,8 +77,6 @@ final class MarshalledPropertyPostProcessor { var mp = x.inner(); if (b.swap == null) b.swap = marshalledPropSwap(x); - if (ne(mp.properties())) - b.properties = split(mp.properties()); bdClasses.addAll(l(mp.dictionary())); }); ap.find(Swap.class, b.innerField).stream().findFirst().ifPresent(x -> b.swap = swapSwap(x)); @@ -91,8 +87,6 @@ final class MarshalledPropertyPostProcessor { var mp = x.inner(); if (b.swap == null) b.swap = marshalledPropSwap(x); - if (nn(b.properties) && ne(mp.properties())) - b.properties = split(mp.properties()); bdClasses.addAll(l(mp.dictionary())); }); ap.find(Swap.class, b.getter).stream().forEach(x -> b.swap = swapSwap(x)); @@ -103,8 +97,6 @@ final class MarshalledPropertyPostProcessor { var mp = x.inner(); if (b.swap == null) b.swap = marshalledPropSwap(x); - if (nn(b.properties) && ne(mp.properties())) - b.properties = split(mp.properties()); bdClasses.addAll(l(mp.dictionary())); }); ap.find(Swap.class, b.setter).stream().forEach(x -> b.swap = swapSwap(x)); diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/annotation/MarshalledProp.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/annotation/MarshalledProp.java index a4ebfbf1d1..1870d871de 100644 --- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/annotation/MarshalledProp.java +++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/annotation/MarshalledProp.java @@ -30,8 +30,7 @@ import org.apache.juneau.commons.bean.BeanProp; * Where {@code @BeanProp} (in <c>juneau-commons</c>) carries the bean-modeling attributes * (such as {@code name}, {@code ro}, {@code wo}, {@code type}, {@code params}, {@code elementType}, * and {@code factory}), this annotation carries the wire-format-specific attributes used by serializers - * and parsers: a per-property format string, a bean dictionary for polymorphic types, and a list of - * child properties to render. + * and parsers: a per-property format string and a bean dictionary for polymorphic types. * * <p> * Can be used in the following locations: @@ -115,38 +114,4 @@ public @interface MarshalledProp { * @return The annotation value. */ String format() default ""; - - /** - * Used to limit which child properties are rendered by the serializers. - * - * <p> - * Can be used on any of the following bean property types: - * <ul class='spaced-list'> - * <li>Beans - Only render the specified properties of the bean. - * <li>Maps - Only render the specified entries in the map. - * <li>Bean/Map arrays - Same, but applied to each element in the array. - * <li>Bean/Map collections - Same, but applied to each element in the collection. - * </ul> - * - * <h5 class='section'>Example:</h5> - * <p class='bjava'> - * <jk>public class</jk> MyClass { - * - * <jc>// Only render 'f1' when serializing this bean property.</jc> - * <ja>@MarshalledProp</ja>(properties=<js>"f1"</js>) - * <jk>public</jk> MyChildClass <jf>x1</jf> = <jk>new</jk> MyChildClass(); - * } - * - * <jk>public class</jk> MyChildClass { - * <jk>public int</jk> <jf>f1</jf> = 1; - * <jk>public int</jk> <jf>f2</jf> = 2; - * } - * - * <jc>// Renders "{x1:{f1:1}}"</jc> - * String <jv>json</jv> = JsonSerializer.<jsf>DEFAULT</jsf>.serialize(<jk>new</jk> MyClass()); - * </p> - * - * @return The annotation value. - */ - String properties() default ""; } diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/annotation/MarshalledPropAnnotation.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/annotation/MarshalledPropAnnotation.java index ff6ec00815..c181a68af3 100644 --- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/annotation/MarshalledPropAnnotation.java +++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/annotation/MarshalledPropAnnotation.java @@ -45,7 +45,6 @@ public class MarshalledPropAnnotation { private String[] description = {}; private Class<?>[] dictionary = new Class[0]; private String format = ""; - private String properties = ""; /** * Constructor. @@ -96,17 +95,6 @@ public class MarshalledPropAnnotation { return this; } - /** - * Sets the {@link MarshalledProp#properties()} property on this annotation. - * - * @param value The new value for this property. - * @return This object. - */ - public Builder properties(String value) { - properties = value; - return this; - } - } @SuppressWarnings({ @@ -117,14 +105,12 @@ public class MarshalledPropAnnotation { private final String[] description; private final Class<?>[] dictionary; private final String format; - private final String properties; Object(MarshalledPropAnnotation.Builder b) { super(b); description = copyOf(b.description); dictionary = copyOf(b.dictionary); format = b.format; - properties = b.properties; } @Override /* Overridden from MarshalledProp */ @@ -137,11 +123,6 @@ public class MarshalledPropAnnotation { return format; } - @Override /* Overridden from MarshalledProp */ - public String properties() { - return properties; - } - @Override /* Overridden from annotation */ public String[] description() { return description; diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/DelegateBeanMap.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/DelegateBeanMap.java index 4f2e776ff1..92a9d8e054 100644 --- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/DelegateBeanMap.java +++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/DelegateBeanMap.java @@ -124,9 +124,6 @@ public class DelegateBeanMap<T> extends BeanMap<T> { return super.get(key); } - @Override /* Overridden from BeanMap */ - public BeanMeta<T> getMeta() { return new BeanMetaFiltered<>(super.getMeta(), keys); } - @Override /* Overridden from BeanMap */ public Collection<BeanPropertyMeta> getProperties() { var l = new ArrayList<BeanPropertyMeta>(keys.size()); diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/jsonschema/JsonSchemaGeneratorSession.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/jsonschema/JsonSchemaGeneratorSession.java index 394207feaf..d62d04d3ec 100644 --- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/jsonschema/JsonSchemaGeneratorSession.java +++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/jsonschema/JsonSchemaGeneratorSession.java @@ -266,7 +266,7 @@ public class JsonSchemaGeneratorSession extends MarshallingTraverseSession { * @throws SerializeException Error occurred. */ public JsonMap getSchema(ClassMeta<?> cm) throws MarshallingRecursionException, SerializeException { - return getSchema(cm, "root", null, false, false, null); + return getSchema(cm, "root", false, false, null); } /** @@ -280,7 +280,7 @@ public class JsonSchemaGeneratorSession extends MarshallingTraverseSession { * @throws SerializeException Error occurred. */ public JsonMap getSchema(Object o) throws MarshallingRecursionException, SerializeException { - return getSchema(toClassMeta(o), "root", null, false, false, null); + return getSchema(toClassMeta(o), "root", false, false, null); } /** @@ -292,7 +292,7 @@ public class JsonSchemaGeneratorSession extends MarshallingTraverseSession { * @throws SerializeException Error occurred. */ public JsonMap getSchema(Type type) throws MarshallingRecursionException, SerializeException { - return getSchema(getClassMeta(type), "root", null, false, false, null); + return getSchema(getClassMeta(type), "root", false, false, null); } private Object getDescription(ClassMeta<?> sType, TypeCategory t, boolean descriptionAdded) { @@ -334,7 +334,7 @@ public class JsonSchemaGeneratorSession extends MarshallingTraverseSession { "rawtypes", // Raw types necessary for generic type handling "unchecked", // Type erasure requires unchecked casts }) - private JsonMap getSchema(ClassMeta<?> eType, String attrName, List<String> pNames, boolean exampleAdded, boolean descriptionAdded, JsonSchemaBeanPropertyMeta jsbpm) + private JsonMap getSchema(ClassMeta<?> eType, String attrName, boolean exampleAdded, boolean descriptionAdded, JsonSchemaBeanPropertyMeta jsbpm) throws MarshallingRecursionException, SerializeException { if (ctx.isIgnoredType(eType)) @@ -358,7 +358,7 @@ public class JsonSchemaGeneratorSession extends MarshallingTraverseSession { Object example = null; Object description = null; - boolean useDef = isUseBeanDefs() && sType.isBean() && pNames == null; + boolean useDef = isUseBeanDefs() && sType.isBean(); if (useDef) { exampleAdded = false; @@ -444,14 +444,10 @@ public class JsonSchemaGeneratorSession extends MarshallingTraverseSession { if (tc == BEAN) { var properties = new JsonMap(); BeanMeta bm = getBeanMeta(sType.inner()); - if (nn(pNames)) - bm = new BeanMetaFiltered(bm, pNames); for (Iterator<BeanPropertyMeta> i = bm.getProperties().values().iterator(); i.hasNext();) { BeanPropertyMeta p = i.next(); - if (p.canRead()) { - var pProps = p.getProperties(); - properties.put(p.getName(), getSchema((ClassMeta<?>) p.getClassMeta(), p.getName(), pProps, exampleAdded, descriptionAdded, getJsonSchemaBeanPropertyMeta(p))); - } + if (p.canRead()) + properties.put(p.getName(), getSchema((ClassMeta<?>) p.getClassMeta(), p.getName(), exampleAdded, descriptionAdded, getJsonSchemaBeanPropertyMeta(p))); } out.put(PROP_properties, properties); @@ -459,19 +455,19 @@ public class JsonSchemaGeneratorSession extends MarshallingTraverseSession { ClassMeta et = sType.getElementType(); if (sType.isCollection() && sType.isAssignableTo(Set.class)) out.put(PROP_uniqueItems, true); - out.put(PROP_items, getSchema(et, PROP_items, pNames, exampleAdded, descriptionAdded, null)); + out.put(PROP_items, getSchema(et, PROP_items, exampleAdded, descriptionAdded, null)); } else if (tc == ARRAY) { ClassMeta et = sType.getElementType(); if (sType.isCollection() && sType.isAssignableTo(Set.class)) out.put(PROP_uniqueItems, true); - out.put(PROP_items, getSchema(et, PROP_items, pNames, exampleAdded, descriptionAdded, null)); + out.put(PROP_items, getSchema(et, PROP_items, exampleAdded, descriptionAdded, null)); } else if (tc == ENUM) { out.put(PROP_enum, getEnums(sType)); } else if (tc == MAP) { - var om = getSchema(sType.getValueType(), PROP_additionalProperties, null, exampleAdded, descriptionAdded, null); + var om = getSchema(sType.getValueType(), PROP_additionalProperties, exampleAdded, descriptionAdded, null); if (! om.isEmpty()) out.put(PROP_additionalProperties, om); diff --git a/juneau-utest/src/test/java/org/apache/juneau/annotation/MarshalledPropAnnotation_Test.java b/juneau-utest/src/test/java/org/apache/juneau/annotation/MarshalledPropAnnotation_Test.java index 01246caa43..775c992ef5 100644 --- a/juneau-utest/src/test/java/org/apache/juneau/annotation/MarshalledPropAnnotation_Test.java +++ b/juneau-utest/src/test/java/org/apache/juneau/annotation/MarshalledPropAnnotation_Test.java @@ -38,18 +38,16 @@ class MarshalledPropAnnotation_Test extends TestBase { .description("a") .dictionary(X1.class) .format("b") - .properties("e") .build(); MarshalledProp a2 = MarshalledPropAnnotation.create() .description("a") .dictionary(X1.class) .format("b") - .properties("e") .build(); @Test void a01_basic() { - assertBean(a1, "description,dictionary,format,properties", "[a],[X1],b,e"); + assertBean(a1, "description,dictionary,format", "[a],[X1],b"); } @Test void a02_testEquivalency() { @@ -73,12 +71,12 @@ class MarshalledPropAnnotation_Test extends TestBase { //------------------------------------------------------------------------------------------------------------------ public static class D1 { - @MarshalledProp(description={ "a" }, dictionary=X1.class, format="b", properties="e") + @MarshalledProp(description={ "a" }, dictionary=X1.class, format="b") public int f; } public static class D2 { - @MarshalledProp(description={ "a" }, dictionary=X1.class, format="b", properties="e") + @MarshalledProp(description={ "a" }, dictionary=X1.class, format="b") public int f; } diff --git a/juneau-utest/src/test/java/org/apache/juneau/html/Common_Test.java b/juneau-utest/src/test/java/org/apache/juneau/html/Common_Test.java index 14af10fe1d..ebe1364b83 100755 --- a/juneau-utest/src/test/java/org/apache/juneau/html/Common_Test.java +++ b/juneau-utest/src/test/java/org/apache/juneau/html/Common_Test.java @@ -187,125 +187,6 @@ class Common_Test extends TestBase { } } - //==================================================================================================== - // @MarshalledProp.bpi annotation. - //==================================================================================================== - @Test void a05_beanPropertyProperties() throws Exception { - var s = HtmlSerializer.create().sq().addKeyValueTableHeaders().build(); - var t = new E1(); - var r = s.serialize(t); - - assertEquals( - "<table>" - +"<tr>" - +"<th>key</th>" - +"<th>value</th>" - +"</tr>" - +"<tr>" - +"<td>x1</td>" - +"<td>" - +"<table>" - +"<tr><th>key</th><th>value</th></tr>" - +"<tr><td>f1</td><td>1</td></tr>" - +"</table>" - +"</td>" - +"</tr>" - +"<tr>" - +"<td>x2</td>" - +"<td>" - +"<table>" - +"<tr><th>key</th><th>value</th></tr>" - +"<tr><td>f1</td><td>3</td></tr>" - +"</table>" - +"</td>" - +"</tr>" - +"<tr>" - +"<td>x3</td>" - +"<td>" - +"<table _type='array'>" - +"<tr><th>f1</th></tr>" - +"<tr><td>1</td></tr>" - +"</table>" - +"</td>" - +"</tr>" - +"<tr>" - +"<td>x4</td>" - +"<td>" - +"<table _type='array'>" - +"<tr><th>f1</th></tr>" - +"<tr><td>1</td></tr>" - +"</table>" - +"</td>" - +"</tr>" - +"<tr>" - +"<td>x5</td>" - +"<td>" - +"<table _type='array'>" - +"<tr><th>f1</th></tr>" - +"<tr><td><number>5</number></td></tr>" - +"</table>" - +"</td>" - +"</tr>" - +"<tr>" - +"<td>x6</td>" - +"<td>" - +"<table _type='array'>" - +"<tr><th>f1</th></tr>" - +"<tr><td><number>7</number></td></tr>" - +"</table>" - +"</td>" - +"</tr>" - +"</table>", - r); - r = s.getSchemaSerializer().serialize(new E1()); - assertEquals(r.indexOf("f2"), -1); - } - - public static class E1 { - @MarshalledProp(properties="f1") public E2 x1 = new E2(); - @MarshalledProp(properties="f1") public Map<String,Integer> x2 = m("f1",3,"f2",4); - @MarshalledProp(properties="f1") public E2[] x3 = {new E2()}; - @MarshalledProp(properties="f1") public List<E2> x4 = l(new E2()); - @MarshalledProp(properties="f1") public JsonMap[] x5 = {JsonMap.of("f1",5,"f2",6)}; - @MarshalledProp(properties="f1") public List<JsonMap> x6 = l(JsonMap.of("f1",7,"f2",8)); - } - - public static class E2 { - public int f1 = 1; - public int f2 = 2; - } - - //==================================================================================================== - // @MarshalledProp.bpi annotation on list of beans. - //==================================================================================================== - @Test void a06_beanPropertyPropertiesOnListOfBeans() throws Exception { - var s = HtmlSerializer.DEFAULT_SQ; - var l = new LinkedList<>(); - var t = new F(); - t.x1.add(new F()); - l.add(t); - var html = s.serialize(l); - assertEquals( - "<table _type='array'>" - +"<tr><th>x1</th><th>x2</th></tr>" - +"<tr>" - +"<td>" - +"<table _type='array'>" - +"<tr><th>x2</th></tr>" - +"<tr><td>2</td></tr>" - +"</table>" - +"</td>" - +"<td>2</td>" - +"</tr>" - +"</table>", html); - - } - - public static class F { - @MarshalledProp(properties="x2") public List<F> x1 = new LinkedList<>(); - public int x2 = 2; - } - //==================================================================================================== // Test that URLs and URIs are serialized and parsed correctly. //==================================================================================================== diff --git a/juneau-utest/src/test/java/org/apache/juneau/json/Common_Test.java b/juneau-utest/src/test/java/org/apache/juneau/json/Common_Test.java index b299a4740d..775aef613c 100755 --- a/juneau-utest/src/test/java/org/apache/juneau/json/Common_Test.java +++ b/juneau-utest/src/test/java/org/apache/juneau/json/Common_Test.java @@ -153,51 +153,6 @@ class Common_Test extends TestBase { } } - //==================================================================================================== - // @MarshalledProp.bpi annotation. - //==================================================================================================== - @Test void a05_beanPropertyProperies() throws Exception { - var s = JsonSerializer.DEFAULT; - var t = new E1(); - var r = s.serialize(t); - - assertEquals("{\"x1\":{\"f1\":1},\"x2\":{\"f1\":1},\"x3\":[{\"f1\":1}],\"x4\":[{\"f1\":1}],\"x5\":[{\"f1\":1}],\"x6\":[{\"f1\":1}]}", r); - r = s.getSchemaSerializer().serialize(t); - assertEquals(r.indexOf("f2"), -1); - } - - public static class E1 { - @MarshalledProp(properties="f1") public E2 x1 = new E2(); - @MarshalledProp(properties="f1") public Map<String,Integer> x2 = m("f1",1,"f2",2); - @MarshalledProp(properties="f1") public E2[] x3 = {new E2()}; - @MarshalledProp(properties="f1") public List<E2> x4 = l(new E2()); - @MarshalledProp(properties="f1") public JsonMap[] x5 = {JsonMap.of("f1",1,"f2",2)}; - @MarshalledProp(properties="f1") public List<JsonMap> x6 = l(JsonMap.of("f1",1,"f2",2)); - } - - public static class E2 { - public int f1 = 1; - public int f2 = 2; - } - - //==================================================================================================== - // @MarshalledProp.bpi annotation on list of beans. - //==================================================================================================== - @Test void a06_beanPropertyProperiesOnListOfBeans() throws Exception { - var s = JsonSerializer.DEFAULT; - var l = new LinkedList<>(); - var t = new F(); - t.x1.add(new F()); - l.add(t); - var json = s.serialize(l); - assertEquals("[{\"x1\":[{\"x2\":2}],\"x2\":2}]", json); - } - - public static class F { - @MarshalledProp(properties="x2") public List<F> x1 = new LinkedList<>(); - public int x2 = 2; - } - //==================================================================================================== // Test that URLs and URIs are serialized and parsed correctly. //==================================================================================================== diff --git a/juneau-utest/src/test/java/org/apache/juneau/json5/Common_Test.java b/juneau-utest/src/test/java/org/apache/juneau/json5/Common_Test.java index 77d9f46278..85c6d5abf8 100644 --- a/juneau-utest/src/test/java/org/apache/juneau/json5/Common_Test.java +++ b/juneau-utest/src/test/java/org/apache/juneau/json5/Common_Test.java @@ -153,51 +153,6 @@ class Common_Test extends TestBase { } } - //==================================================================================================== - // @MarshalledProp.bpi annotation. - //==================================================================================================== - @Test void a05_beanPropertyProperies() throws Exception { - var s = Json5Serializer.DEFAULT; - var t = new E1(); - var r = s.serialize(t); - - assertEquals("{x1:{f1:1},x2:{f1:1},x3:[{f1:1}],x4:[{f1:1}],x5:[{f1:1}],x6:[{f1:1}]}", r); - r = s.getSchemaSerializer().serialize(t); - assertEquals(r.indexOf("f2"), -1); - } - - public static class E1 { - @MarshalledProp(properties="f1") public E2 x1 = new E2(); - @MarshalledProp(properties="f1") public Map<String,Integer> x2 = m("f1",1,"f2",2); - @MarshalledProp(properties="f1") public E2[] x3 = {new E2()}; - @MarshalledProp(properties="f1") public List<E2> x4 = l(new E2()); - @MarshalledProp(properties="f1") public JsonMap[] x5 = {JsonMap.of("f1",1,"f2",2)}; - @MarshalledProp(properties="f1") public List<JsonMap> x6 = l(JsonMap.of("f1",1,"f2",2)); - } - - public static class E2 { - public int f1 = 1; - public int f2 = 2; - } - - //==================================================================================================== - // @MarshalledProp.bpi annotation on list of beans. - //==================================================================================================== - @Test void a06_beanPropertyProperiesOnListOfBeans() throws Exception { - var s = Json5Serializer.DEFAULT; - var l = new LinkedList<>(); - var t = new F(); - t.x1.add(new F()); - l.add(t); - var json = s.serialize(l); - assertEquals("[{x1:[{x2:2}],x2:2}]", json); - } - - public static class F { - @MarshalledProp(properties="x2") public List<F> x1 = new LinkedList<>(); - public int x2 = 2; - } - //==================================================================================================== // Test that URLs and URIs are serialized and parsed correctly. //==================================================================================================== diff --git a/juneau-utest/src/test/java/org/apache/juneau/uon/Common_UonTest.java b/juneau-utest/src/test/java/org/apache/juneau/uon/Common_UonTest.java index f759589aed..5d642afe5f 100755 --- a/juneau-utest/src/test/java/org/apache/juneau/uon/Common_UonTest.java +++ b/juneau-utest/src/test/java/org/apache/juneau/uon/Common_UonTest.java @@ -151,47 +151,6 @@ class Common_UonTest extends TestBase { } } - //==================================================================================================== - // @MarshalledProp.bpi annotation. - //==================================================================================================== - @Test void a05_beanPropertyProperies() throws Exception { - var s = UonSerializer.DEFAULT; - var ue = s.serialize(new E1()); - assertEquals("(x1=(f1=1),x2=(f1=1),x3=@((f1=1)),x4=@((f1=1)),x5=@((f1=1)),x6=@((f1=1)))", ue); - } - - public static class E1 { - @MarshalledProp(properties="f1") public E2 x1 = new E2(); - @MarshalledProp(properties="f1") public Map<String,Integer> x2 = m("f1",1,"f2",2); - @MarshalledProp(properties="f1") public E2[] x3 = {new E2()}; - @MarshalledProp(properties="f1") public List<E2> x4 = l(new E2()); - @MarshalledProp(properties="f1") public JsonMap[] x5 = {JsonMap.of("f1",1,"f2",2)}; - @MarshalledProp(properties="f1") public List<JsonMap> x6 = l(JsonMap.of("f1",1,"f2",2)); - } - - public static class E2 { - public int f1 = 1; - public int f2 = 2; - } - - //==================================================================================================== - // @MarshalledProp.bpi annotation on list of beans. - //==================================================================================================== - @Test void a06_beanPropertyPropertiesOnListOfBeans() throws Exception { - var s = UonSerializer.DEFAULT; - var l = new LinkedList<>(); - var t = new F(); - t.x1.add(new F()); - l.add(t); - var xml = s.serialize(l); - assertEquals("@((x1=@((x2=2)),x2=2))", xml); - } - - public static class F { - @MarshalledProp(properties="x2") public List<F> x1 = new LinkedList<>(); - public int x2 = 2; - } - //==================================================================================================== // Test URIAttr - Test that URLs and URIs are serialized and parsed correctly. //==================================================================================================== diff --git a/juneau-utest/src/test/java/org/apache/juneau/urlencoding/Common_UrlEncodingTest.java b/juneau-utest/src/test/java/org/apache/juneau/urlencoding/Common_UrlEncodingTest.java index 4a03c7697d..f18236c102 100755 --- a/juneau-utest/src/test/java/org/apache/juneau/urlencoding/Common_UrlEncodingTest.java +++ b/juneau-utest/src/test/java/org/apache/juneau/urlencoding/Common_UrlEncodingTest.java @@ -150,50 +150,6 @@ class Common_UrlEncodingTest extends TestBase { } } - //==================================================================================================== - // @MarshalledProp.bpi annotation. - //==================================================================================================== - @Test void a05_beanPropertyProperies() throws Exception { - var s = UrlEncodingSerializer.DEFAULT; - var ue = s.serialize(new E1()); - assertEquals("x1=(f1=1)&x2=(f1=1)&x3=@((f1=1))&x4=@((f1=1))&x5=@((f1=1))&x6=@((f1=1))", ue); - } - - public static class E1 { - @MarshalledProp(properties="f1") public E2 x1 = new E2(); - @MarshalledProp(properties="f1") public Map<String,Integer> x2 = m("f1",1,"f2",2); - @MarshalledProp(properties="f1") public E2[] x3 = {new E2()}; - @MarshalledProp(properties="f1") public List<E2> x4 = l(new E2()); - @MarshalledProp(properties="f1") public JsonMap[] x5 = {JsonMap.of("f1",1,"f2",2)}; - @MarshalledProp(properties="f1") public List<JsonMap> x6 = l(JsonMap.of("f1",1,"f2",2)); - } - - public static class E2 { - public int f1 = 1; - public int f2 = 2; - } - - //==================================================================================================== - // @MarshalledProp.bpi annotation on list of beans. - //==================================================================================================== - @Test void a06_beanPropertyPropertiesOnListOfBeans() throws Exception { - var s = UrlEncodingSerializer.DEFAULT; - var l = new LinkedList<>(); - var t = new F(); - t.x1.add(new F()); - l.add(t); - var m = JsonMap.of("t", l); - var xml = s.serialize(m); - assertEquals("t=@((x1=@((x2=2)),x2=2))", xml); - xml = s.serialize(l); - assertEquals("0=(x1=@((x2=2)),x2=2)", xml); - } - - public static class F { - @MarshalledProp(properties="x2") public List<F> x1 = new LinkedList<>(); - public int x2 = 2; - } - //==================================================================================================== // Test URIAttr - Test that URLs and URIs are serialized and parsed correctly. //==================================================================================================== diff --git a/juneau-utest/src/test/java/org/apache/juneau/xml/Common_Test.java b/juneau-utest/src/test/java/org/apache/juneau/xml/Common_Test.java index 50a4381b2f..6c3d9d0d4e 100755 --- a/juneau-utest/src/test/java/org/apache/juneau/xml/Common_Test.java +++ b/juneau-utest/src/test/java/org/apache/juneau/xml/Common_Test.java @@ -154,60 +154,6 @@ class Common_Test extends TestBase { } } - //==================================================================================================== - // @MarshalledProp.bpi annotation. - //==================================================================================================== - @Test void a05_beanPropertyProperties() throws Exception { - var s = XmlSerializer.DEFAULT_SQ; - var t = new E1(); - var r = s.serialize(t); - assertEquals( - "<object>" - +"<x1 f2='2'><f1>1</f1></x1>" - +"<x2><f1>1</f1></x2>" - +"<x3><object f2='2'><f1>1</f1></object></x3>" - +"<x4><object f2='2'><f1>1</f1></object></x4>" - +"<x5><object><f1 _type='number'>1</f1></object></x5>" - +"<x6><object><f1 _type='number'>1</f1></object></x6>" - +"</object>", - r); - validateXml(t); - } - - public static class E1 { - @MarshalledProp(properties="f1,f2") public E2 x1 = new E2(); - @MarshalledProp(properties="f1,f2") public Map<String,Integer> x2 = m("f1",1,"f3",3); - @MarshalledProp(properties="f1,f2") public E2[] x3 = {new E2()}; - @MarshalledProp(properties="f1,f2") public List<E2> x4 = l(new E2()); - @MarshalledProp(properties="f1") public JsonMap[] x5 = {JsonMap.of("f1",1,"f3",3)}; - @MarshalledProp(properties="f1") public List<JsonMap> x6 = l(JsonMap.of("f1",1,"f3",3)); - } - - public static class E2 { - public int f1 = 1; - @Xml(format=ATTR) public int f2 = 2; - public int f3 = 3; - @Xml(format=ATTR) public int f4 = 4; - } - - //==================================================================================================== - // @MarshalledProp.bpi annotation on list of beans. - //==================================================================================================== - @Test void a06_beanPropertyPropertiesOnListOfBeans() throws Exception { - var s = XmlSerializer.DEFAULT_SQ; - var l = new LinkedList<>(); - var t = new Test7b(); - t.x1.add(new Test7b()); - l.add(t); - var xml = s.serialize(l); - assertEquals("<array><object><x1><object><x2>2</x2></object></x1><x2>2</x2></object></array>", xml); - } - - public static class Test7b { - @MarshalledProp(properties="x2") public List<Test7b> x1 = new LinkedList<>(); - public int x2 = 2; - } - //==================================================================================================== // Recursion //==================================================================================================== diff --git a/juneau-utest/src/test/java/org/apache/juneau/xml/Xml_Test.java b/juneau-utest/src/test/java/org/apache/juneau/xml/Xml_Test.java index 98574e4393..f36a98fe24 100755 --- a/juneau-utest/src/test/java/org/apache/juneau/xml/Xml_Test.java +++ b/juneau-utest/src/test/java/org/apache/juneau/xml/Xml_Test.java @@ -280,27 +280,6 @@ class Xml_Test extends TestBase { public F f1 = new F(); } - //==================================================================================================== - // Element name on beans of a collection. - //==================================================================================================== - @Test void a10_elementNameOnBeansOfCollection() throws Exception { - var s = XmlSerializer.DEFAULT_SQ; - var o = new J1(); - var r = s.serialize(o); - assertEquals("<foo><f1><bar><f2>2</f2></bar></f1></foo>", r); - } - - @Marshalled(typeName="foo") - public static class J1 { - @MarshalledProp(properties="f2") public List<J2> f1 = l(new J2()); - } - - @Marshalled(typeName="bar") - public static class J2 { - public int f2 = 2; - public int f3 = 3; - } - //==================================================================================================== // @Xml.ns without matching nsUri. //==================================================================================================== diff --git a/todo/TODO-5-bean-runtime-types-to-commons.md b/todo/TODO-5-bean-runtime-types-to-commons.md index b7c19d95ed..eb62da62cb 100644 --- a/todo/TODO-5-bean-runtime-types-to-commons.md +++ b/todo/TODO-5-bean-runtime-types-to-commons.md @@ -4,6 +4,40 @@ This is the remaining work from **Phase 5 of the bean-layer split**. Phase 5a (t --- +## Status (as of `@MarshalledProp(properties)` removal, uncommitted) + +**`@MarshalledProp(properties=...)` dropped per user direction (breaking change, v9.5).** With breaking changes authorized throughout TODO-5, the per-property child-property filter feature has been removed entirely. This shrinks the Phase C Task 5 surface meaningfully: + +- `BeanPropertyMeta.applyChildPropertiesFilter(MarshallingSession, ClassMeta, Object)` — **gone**. The `MarshallingSession` + `ClassMeta` parameters that blocked the physical move are no longer present. +- `BeanPropertyMeta.swapAndFilterProperty(...)` — **inlined** into `getInner(...)` as a single `readTransform.apply(session, o)` call. +- `BeanPropertyMeta.newBeanMap(MarshallingSession, Object, BeanMetaFiltered)` private static helper — **gone**. +- `BeanPropertyMeta.properties` field + `getProperties()` accessor + `Builder.properties` field — **gone**. +- `BeanMetaFiltered` class — **deleted** (file removed). Its sole consumer (`DelegateBeanMap.getMeta()`) had its override removed too; `super.getMeta()` (raw `BeanMeta`) is what `entrySet()`/`keySet()` were already filtering against. +- `JsonSchemaGeneratorSession.getSchema(...)` — `pNames` parameter and the `BeanMetaFiltered` wrap-and-iterate path removed; the recursive nested-bean schema generation no longer carries an override-list. +- `MarshalledPropertyPostProcessor` — `ne(mp.properties()) → b.properties = split(...)` reads stripped from all three `(innerField, getter, setter)` annotation walks. +- `MarshalledProp.properties()` annotation attribute + `MarshalledPropAnnotation.Builder.properties(...)` setter + corresponding `Object#properties()` impl — **gone**. + +**Phase C Task 5 gap inventory now shrunk (compared to the previous checkpoint):** + +- One of the three `((MarshallingContext) bc).X()` casts in `BeanPropertyMeta` is gone (the `getBeanMeta(o.getClass())` cast inside `applyChildPropertiesFilter`). Two casts remain: `Builder.rawMetaType(Class<?>)` → `getClassMeta(value)`, and the constructor `ap` initialization → `getAnnotationProvider()`. +- The `BiFunction<MarshallingSession,Object,Object>` field types still need retyping to `BiFunction<BeanSession,Object,Object>` (or `BiFunction<Object,Object,Object>`), but with `applyChildPropertiesFilter` gone the only remaining `MarshallingSession`-typed parameter is on `setPropertyValue` — and that's the only place inside `BeanPropertyMeta` that still needs a marshalling-side session. The `swapAndFilterProperty` indirection is gone. +- `BeanMetaFiltered` is no longer one of the 8 target types; the cluster shrinks to **7**: `BeanMap`, `BeanMapEntry`, `BeanMeta`, `BeanPropertyMeta`, `BeanPropertyValue`, `BeanPropertyConsumer`, `BeanProxyInvocationHandler`. + +Test changes: +- `MarshalledPropAnnotation_Test` — `.properties(...)` setter calls and `properties="e"` annotation attributes removed from `a1`/`a2`/`D1`/`D2`; `assertBean` field list trimmed from `description,dictionary,format,properties` to `description,dictionary,format`. +- `juneau-utest/src/test/java/org/apache/juneau/{json,json5,xml,html,uon,urlencoding}/Common_*Test.java` — all `a05_beanPropertyProperies` / `a06_beanPropertyPropertiesOnListOfBeans` tests and their `E1`/`E2`/`F`/`Test7b` helper classes deleted. 7 test files, 12 test methods deleted. +- `juneau-utest/src/test/java/org/apache/juneau/xml/Xml_Test.java` — `a10_elementNameOnBeansOfCollection` and its `J1`/`J2` helper classes deleted. + +Docs: +- `juneau-docs/pages/topics/02.04.04.BeanpAnnotation.md` — `@MarshalledProp(properties)` paragraph + example removed. +- `juneau-docs/pages/release-notes/9.5.0.md` — new "Removed `@MarshalledProp(properties)` Attribute (breaking)" section under the `juneau-marshall` heading. + +Build + full test green (`scripts/test.py --full`). + +**Recommended next checkpoint:** resume Phase C Task 5 (physical `git mv` + reference sweep) with the simplified surface. The remaining work is still substantial (~20 annotation-read lifts, two `((MarshallingContext) bc).X()` casts, `BiFunction` retypes, `BeanProxyInvocationHandler` SPI routing, Javadoc cleanup), but the most awkward seam — `applyChildPropertiesFilter` with its `MarshallingSession`+`ClassMeta` parameters and the `BeanMetaFiltered` wrapper class — is gone. + +--- + ## Status (as of Phase C Tasks 1-2-3-4-4-deferred checkpoint, uncommitted) **Phase C Tasks 1, 2, 3, 4, 4-deferred LANDED (working tree, uncommitted).** Build + full test green. See "Phase C status" block under Step 8b-ii for full detail. Summary:
