Repository: incubator-juneau Updated Branches: refs/heads/master b9a829ba6 -> babb64e46
Continuing work on bean dictionary support. Project: http://git-wip-us.apache.org/repos/asf/incubator-juneau/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-juneau/commit/babb64e4 Tree: http://git-wip-us.apache.org/repos/asf/incubator-juneau/tree/babb64e4 Diff: http://git-wip-us.apache.org/repos/asf/incubator-juneau/diff/babb64e4 Branch: refs/heads/master Commit: babb64e46a1eb3aec385f756125d3bf2e03c89a3 Parents: b9a829b Author: jamesbognar <[email protected]> Authored: Fri Sep 9 12:05:52 2016 -0400 Committer: jamesbognar <[email protected]> Committed: Fri Sep 9 12:05:52 2016 -0400 ---------------------------------------------------------------------- .../java/org/apache/juneau/BeanContext.java | 31 +++-- .../java/org/apache/juneau/BeanDictionary.java | 107 ++++++++++++++++ .../apache/juneau/BeanDictionaryBuilder.java | 83 ++++++++++++ .../main/java/org/apache/juneau/BeanMap.java | 2 +- .../main/java/org/apache/juneau/BeanMeta.java | 46 +++---- .../org/apache/juneau/BeanPropertyMeta.java | 29 +++-- .../main/java/org/apache/juneau/ClassMeta.java | 33 +---- .../main/java/org/apache/juneau/ObjectMap.java | 13 +- .../java/org/apache/juneau/TypeDictionary.java | 125 ------------------- .../java/org/apache/juneau/annotation/Bean.java | 17 +-- .../apache/juneau/annotation/BeanProperty.java | 8 +- .../org/apache/juneau/dto/cognos/DataSet.java | 19 ++- .../java/org/apache/juneau/jena/RdfParser.java | 2 +- .../org/apache/juneau/json/JsonSerializer.java | 2 +- .../juneau/msgpack/MsgPackSerializer.java | 2 +- .../juneau/serializer/SerializerSession.java | 10 +- .../juneau/transform/AnnotationBeanFilter.java | 10 +- .../org/apache/juneau/transform/BeanFilter.java | 32 ++--- .../juneau/urlencoding/UonSerializer.java | 2 +- .../urlencoding/UrlEncodingSerializer.java | 2 +- .../juneau/a/rttests/RoundTripBeanMapsTest.java | 6 +- .../java/org/apache/juneau/xml/XmlTest.java | 61 +-------- 22 files changed, 316 insertions(+), 326 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/babb64e4/juneau-core/src/main/java/org/apache/juneau/BeanContext.java ---------------------------------------------------------------------- diff --git a/juneau-core/src/main/java/org/apache/juneau/BeanContext.java b/juneau-core/src/main/java/org/apache/juneau/BeanContext.java index d90936f..d0e21ce 100644 --- a/juneau-core/src/main/java/org/apache/juneau/BeanContext.java +++ b/juneau-core/src/main/java/org/apache/juneau/BeanContext.java @@ -447,19 +447,26 @@ public class BeanContext extends Context { public static final String BEAN_implClasses_put = "BeanContext.implClasses.map.put"; /** - * Specifies the list of classes that make up the class dictionary for this bean context (<code>List<Class></code>). + * Specifies the list of classes that make up the bean dictionary for this bean context (<code>List<Class></code>). + * <p> + * This list can consist of the following class types: + * <ul> + * <li>Any bean class that specifies a value for {@link Bean#typeName() @Bean.typeName()}; + * <li>Any subclass of {@link BeanDictionaryBuilder} that defines an entire subset of mappings. + * Note that the subclass MUST implement a no-arg constructor so that it can be instantiated. + * </ul> */ - public static final String BEAN_typeDictionary = "BeanContext.typeDictionary.list"; + public static final String BEAN_beanDictionary = "BeanContext.beanDictionary.list"; /** - * Add to the class dictionary list. + * Add to the bean dictionary list. */ - public static final String BEAN_typeDictionary_add = "BeanContext.typeDictionary.list.add"; + public static final String BEAN_beanDictionary_add = "BeanContext.beanDictionary.list.add"; /** - * Remove from the class dictionary list. + * Remove from the bean dictionary list. */ - public static final String BEAN_typeDictionary_remove = "BeanContext.typeDictionary.list.remove"; + public static final String BEAN_beanDictionary_remove = "BeanContext.beanDictionary.list.remove"; /** * The name to use for the type property used to represent a bean type. ({@link String}, default=<js>"_type"</js>). @@ -545,7 +552,7 @@ public class BeanContext extends Context { final String[] notBeanPackageNames, notBeanPackagePrefixes; final BeanFilter<?>[] beanFilters; final PojoSwap<?,?>[] pojoSwaps; - final TypeDictionary typeDictionary; + final BeanDictionary beanDictionary; final Map<Class<?>,Class<?>> implClasses; final Class<?>[] implKeyClasses, implValueClasses; final ClassLoader classLoader; @@ -639,7 +646,7 @@ public class BeanContext extends Context { } pojoSwaps = lpf.toArray(new PojoSwap[0]); - typeDictionary = new TypeDictionary(pm.get(BEAN_typeDictionary, Class[].class, new Class[0])); + beanDictionary = new BeanDictionaryBuilder().add(pm.get(BEAN_beanDictionary, Class[].class, new Class[0])).setBeanContext(this).build(); implClasses = new TreeMap<Class<?>,Class<?>>(new ClassComparator()); Map<Class,Class> m = pm.getMap(BEAN_implClasses, Class.class, Class.class, null); @@ -1492,12 +1499,12 @@ public class BeanContext extends Context { } /** - * Returns the type dictionary defined in this bean context defined by {@link BeanContext#BEAN_typeDictionary}. + * Returns the bean dictionary defined in this bean context defined by {@link BeanContext#BEAN_beanDictionary}. * - * @return The type dictionary defined in this bean context. Never <jk>null</jk>. + * @return The bean dictionary defined in this bean context. Never <jk>null</jk>. */ - protected TypeDictionary getTypeDictionary() { - return typeDictionary; + protected BeanDictionary getBeanDictionary() { + return beanDictionary; } /** http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/babb64e4/juneau-core/src/main/java/org/apache/juneau/BeanDictionary.java ---------------------------------------------------------------------- diff --git a/juneau-core/src/main/java/org/apache/juneau/BeanDictionary.java b/juneau-core/src/main/java/org/apache/juneau/BeanDictionary.java new file mode 100644 index 0000000..750e1d5 --- /dev/null +++ b/juneau-core/src/main/java/org/apache/juneau/BeanDictionary.java @@ -0,0 +1,107 @@ +// *************************************************************************************************************************** +// * 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.*; + +/** + * A lookup table for resolving bean types by name. + * <p> + * In a nutshell, provides a simple mapping of bean class objects to identifying names. + * <p> + * Class names are defined through the {@link Bean#typeName()} annotation. + * <p> + * The dictionary is used by the framework in the following ways: + * <ul> + * <li>If a class type cannot be inferred through reflection during parsing, then a helper <js>"_type"</js> is added to the serialized output + * using the name defined for that class in this dictionary. This helps determine the real class at parse time. + * <li>The dictionary name is used as element names when serialized to XML. + * </ul> + * + * @author james.bognar + */ +public class BeanDictionary { + + private final Map<String,ClassMeta<?>> map; + private final Map<Class<?>,String> reverseMap; + private final BeanContext beanContext; + private final String typePropertyName; + private final BeanDictionary parent; + + BeanDictionary(BeanContext beanContext, BeanDictionary parent, Map<String,Class<?>> map) { + this.beanContext = beanContext; + this.typePropertyName = beanContext.getTypePropertyName(); + this.parent = parent == null ? beanContext.getBeanDictionary() : parent; + Map<String,ClassMeta<?>> m1 = new HashMap<String,ClassMeta<?>>(); + for (Map.Entry<String,Class<?>> e : map.entrySet()) { + ClassMeta<?> cm = beanContext.getClassMeta(e.getValue()); + if (! cm.isBean()) + throw new BeanRuntimeException("Invalid class type passed to dictionary. ''{0}'' is not a bean.", cm); + m1.put(e.getKey(), cm); + } + this.map = Collections.unmodifiableMap(m1); + Map<Class<?>,String> m2 = new HashMap<Class<?>,String>(); + for (Map.Entry<String,Class<?>> e : map.entrySet()) + m2.put(e.getValue(), e.getKey()); + this.reverseMap = Collections.unmodifiableMap(m2); + } + + /** + * Returns the name associated with the specified class. + * + * @param c The class associated with the name. + * @return The name associated with the specified class, or <jk>null</jk> if no association exists. + */ + public String getNameForClass(Class<?> c) { + return reverseMap.get(c); + } + + /** + * Converts the specified object map into a bean if it contains a <js>"_type"</js> entry in it. + * + * @param m The object map to convert to a bean if possible. + * @return The new bean, or the original <code>ObjectMap</code> if no <js>"_type"</js> entry was found. + */ + public Object cast(ObjectMap m) { + Object o = m.get(typePropertyName); + if (o == null) + return m; + String typeName = o.toString(); + ClassMeta<?> cm = findClassMeta(typeName); + BeanMap<?> bm = beanContext.newBeanMap(cm.getInnerClass()); + + // Iterate through all the entries in the map and set the individual field values. + for (Map.Entry<String,Object> e : m.entrySet()) { + String k = e.getKey(); + Object v = e.getValue(); + if (! k.equals(typePropertyName)) { + // Attempt to recursively cast child maps. + if (v instanceof ObjectMap) + v = cast((ObjectMap)v); + bm.put(k, v); + } + } + return bm.getBean(); + } + + private ClassMeta<?> findClassMeta(String typeName) { + ClassMeta<?> cm = map.get(typeName); + if (cm == null && parent != null) + cm = parent.findClassMeta(typeName); + if (cm == null) + throw new BeanRuntimeException("Could not find bean type ''{0}'' in dictionary.", typeName); + return cm; + } +} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/babb64e4/juneau-core/src/main/java/org/apache/juneau/BeanDictionaryBuilder.java ---------------------------------------------------------------------- diff --git a/juneau-core/src/main/java/org/apache/juneau/BeanDictionaryBuilder.java b/juneau-core/src/main/java/org/apache/juneau/BeanDictionaryBuilder.java new file mode 100644 index 0000000..a56dd84 --- /dev/null +++ b/juneau-core/src/main/java/org/apache/juneau/BeanDictionaryBuilder.java @@ -0,0 +1,83 @@ +// *************************************************************************************************************************** +// * 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.*; +import org.apache.juneau.internal.*; + +/** + * Utility class for creating {@link BeanDictionary} objects. + * <p> + * This class is a programmatic equivalent to the {@link BeanProperty#beanDictionary()} annotation and {@link BeanContext#BEAN_beanDictionary} property. + * It allows bean dictionaries to be constructed + * + * @author james.bognar + */ +public class BeanDictionaryBuilder { + + private Map<String,Class<?>> map = new HashMap<String,Class<?>>(); + private BeanDictionary parent; + private BeanContext beanContext; + + /** + * Add the specified classes to this type dictionary. + * <p> + * Classes can be of the following types: + * <ul> + * <li>Bean classes. + * <li>Subclasses of {@link BeanDictionaryBuilder} that identify an entire set of mappings. + * </ul> + * + * @param classes The classes to add to this dictionary builder. + * @return This object (for method chaining). + */ + public BeanDictionaryBuilder add(Class<?>...classes) { + for (Class<?> c : classes) { + if (c != null) { + if (ClassUtils.isParentClass(BeanDictionaryBuilder.class, c)) { + try { + BeanDictionaryBuilder l2 = (BeanDictionaryBuilder)c.newInstance(); + for (Map.Entry<String,Class<?>> e : l2.map.entrySet()) + map.put(e.getKey(), e.getValue()); + } catch (Exception e) { + throw new BeanRuntimeException(e); + } + } else { + Bean b = c.getAnnotation(Bean.class); + if (b == null || b.typeName().isEmpty()) + throw new BeanRuntimeException("Class ''{0}'' was passed to TypeDictionaryBuilder but it doesn't have a @Bean.typeName() annotation defined."); + map.put(b.typeName(), c); + } + } + } + return this; + } + + BeanDictionaryBuilder setParent(BeanDictionary parent) { + this.parent = parent; + return this; + } + + BeanDictionaryBuilder setBeanContext(BeanContext beanContext) { + this.beanContext = beanContext; + return this; + } + + BeanDictionary build() { + if (map.isEmpty()) + return parent; + return new BeanDictionary(beanContext, parent, map); + } +} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/babb64e4/juneau-core/src/main/java/org/apache/juneau/BeanMap.java ---------------------------------------------------------------------- diff --git a/juneau-core/src/main/java/org/apache/juneau/BeanMap.java b/juneau-core/src/main/java/org/apache/juneau/BeanMap.java index ff9eea1..ab3a9c0 100644 --- a/juneau-core/src/main/java/org/apache/juneau/BeanMap.java +++ b/juneau-core/src/main/java/org/apache/juneau/BeanMap.java @@ -202,7 +202,7 @@ public class BeanMap<T> extends AbstractMap<String,Object> implements Delegate<T // If this bean has subtypes, and we haven't set the subtype yet, // store the property in a temporary cache until the bean can be instantiated. // This eliminates the need for requiring that the sub type attribute be provided first. - if (meta.subTypeIdProperty != null) { + if (meta.subTypeProperty != null) { if (propertyCache == null) propertyCache = new TreeMap<String,Object>(); return propertyCache.put(property, value); http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/babb64e4/juneau-core/src/main/java/org/apache/juneau/BeanMeta.java ---------------------------------------------------------------------- diff --git a/juneau-core/src/main/java/org/apache/juneau/BeanMeta.java b/juneau-core/src/main/java/org/apache/juneau/BeanMeta.java index 395c323..2e6ae40 100644 --- a/juneau-core/src/main/java/org/apache/juneau/BeanMeta.java +++ b/juneau-core/src/main/java/org/apache/juneau/BeanMeta.java @@ -93,10 +93,10 @@ public class BeanMeta<T> { private final MetadataMap extMeta; // Extended metadata // Other fields - final BeanPropertyMeta subTypeIdProperty; // The property indentified as the sub type differentiator property (identified by @Bean.subTypeProperty annotation). - private final BeanPropertyMeta classProperty; // "_type" mock bean property. - - final String notABeanReason; + final BeanPropertyMeta subTypeProperty; // The property indentified as the sub type differentiator property (identified by @Bean.subTypeProperty annotation). + private final BeanPropertyMeta typeProperty; // "_type" mock bean property. + private final String dictionaryName; // The @Bean.typeName() annotation defined on this bean class. + final String notABeanReason; // Readable string explaining why this class wasn't a bean. /** * Constructor. @@ -115,6 +115,7 @@ public class BeanMeta<T> { this.notABeanReason = b.init(this); this.beanFilter = beanFilter; + this.dictionaryName = (beanFilter == null ? null : beanFilter.getTypeName()); this.properties = b.properties; this.getterProps = Collections.unmodifiableMap(b.getterProps); this.setterProps = Collections.unmodifiableMap(b.setterProps); @@ -122,8 +123,8 @@ public class BeanMeta<T> { this.constructor = b.constructor; this.constructorArgs = b.constructorArgs; this.extMeta = b.extMeta; - this.subTypeIdProperty = b.subTypeIdProperty; - this.classProperty = new BeanPropertyMeta(this, ctx.getTypePropertyName(), ctx.string()); + this.subTypeProperty = b.subTypeIdProperty; + this.typeProperty = new BeanPropertyMeta(this, ctx.getTypePropertyName(), ctx.string()); } @@ -141,7 +142,6 @@ public class BeanMeta<T> { MetadataMap extMeta = new MetadataMap(); BeanPropertyMeta subTypeIdProperty; PropertyNamer propertyNamer; - TypeDictionary typeDictionary; private Builder(ClassMeta<T> classMeta, BeanContext ctx, BeanFilter<? extends T> beanFilter, String[] pNames) { this.classMeta = classMeta; @@ -224,8 +224,6 @@ public class BeanMeta<T> { if (beanFilter.getPropertyNamer() != null) propertyNamer = beanFilter.getPropertyNamer(); - - typeDictionary = beanFilter.getTypeDictionary(); } if (propertyNamer == null) @@ -337,9 +335,6 @@ public class BeanMeta<T> { properties.put(subTypeProperty, this.subTypeIdProperty); } - if (typeDictionary == null) - typeDictionary = ctx.getTypeDictionary(); - properties.putAll(normalProps); // If a beanFilter is defined, look for inclusion and exclusion lists. @@ -417,14 +412,23 @@ public class BeanMeta<T> { } /** - * Returns the subtype ID property of this bean if it has one. + * Returns the dictionary name for this bean as defined through the {@link Bean#typeName()} annotation. + * + * @return The dictioanry name for this bean, or <jk>null</jk> if it has no dictionary name defined. + */ + public String getDictionaryName() { + return dictionaryName; + } + + /** + * Returns the subtype property of this bean if it has one. * <p> - * The subtype id is specified using the {@link Bean#subTypeProperty()} annotation. + * The subtype is specified using the {@link Bean#subTypeProperty()} annotation. * * @return The meta property for the sub type property, or <jk>null</jk> if no subtype is defined for this bean. */ - public BeanPropertyMeta getSubTypeIdProperty() { - return subTypeIdProperty; + public BeanPropertyMeta getSubTypeProperty() { + return subTypeProperty; } /** @@ -434,17 +438,17 @@ public class BeanMeta<T> { * @return <jk>true</jk> if this bean has subtypes associated with it. */ public boolean isSubTyped() { - return subTypeIdProperty != null; + return subTypeProperty != null; } /** * Returns a mock bean property that resolves to the name <js>"_type"</js> and whose value always resolves - * to the class name of the bean. + * to the dictionary name of the bean. * - * @return The class name property. + * @return The type name property. */ - public BeanPropertyMeta getClassProperty() { - return classProperty; + public BeanPropertyMeta getTypeProperty() { + return typeProperty; } /* http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/babb64e4/juneau-core/src/main/java/org/apache/juneau/BeanPropertyMeta.java ---------------------------------------------------------------------- diff --git a/juneau-core/src/main/java/org/apache/juneau/BeanPropertyMeta.java b/juneau-core/src/main/java/org/apache/juneau/BeanPropertyMeta.java index c5adea6..5a3dc5d 100644 --- a/juneau-core/src/main/java/org/apache/juneau/BeanPropertyMeta.java +++ b/juneau-core/src/main/java/org/apache/juneau/BeanPropertyMeta.java @@ -58,7 +58,7 @@ public class BeanPropertyMeta { private PojoSwap swap; // PojoSwap defined only via @BeanProperty annotation. private MetadataMap extMeta = new MetadataMap(); // Extended metadata - private TypeDictionary typeDictionary; + private BeanDictionary beanDictionary; /** * Constructor. @@ -144,18 +144,17 @@ public class BeanPropertyMeta { } /** - * Returns the class dictionary in use for this bean property. + * Returns the bean dictionary in use for this bean property. * The order of lookup for the dictionary is as follows: * <ol> - * <li>Dictionary defined via {@link BeanProperty#typeDictionary()}. - * <li>Dictionary defined via {@link Bean#typeDictionary()} (or {@link BeanFilter} equivalent). - * <li>Dictionary defined via {@link BeanContext#BEAN_typeDictionary} context property. + * <li>Dictionary defined via {@link BeanProperty#beanDictionary()}. + * <li>Dictionary defined via {@link BeanContext#BEAN_beanDictionary} context property. * </ol> * - * @return The class dictionary in use for this bean property. Never <jk>null</jk>. + * @return The bean dictionary in use for this bean property. Never <jk>null</jk>. */ - public TypeDictionary getTypeDictionary() { - return typeDictionary; + public BeanDictionary getBeanDictionary() { + return beanDictionary; } /** @@ -256,8 +255,8 @@ public class BeanPropertyMeta { swap = getPropertyPojoSwap(p); if (p.properties().length != 0) properties = p.properties(); - if (p.typeDictionary().length > 0) - this.typeDictionary = new TypeDictionary(p.typeDictionary()); + if (p.beanDictionary().length > 0) + this.beanDictionary = new BeanDictionaryBuilder().add(p.beanDictionary()).setBeanContext(this.beanMeta.ctx).build(); } } @@ -271,8 +270,8 @@ public class BeanPropertyMeta { swap = getPropertyPojoSwap(p); if (properties != null && p.properties().length != 0) properties = p.properties(); - if (p.typeDictionary().length > 0) - this.typeDictionary = new TypeDictionary(p.typeDictionary()); + if (p.beanDictionary().length > 0) + this.beanDictionary = new BeanDictionaryBuilder().add(p.beanDictionary()).setBeanContext(this.beanMeta.ctx).build(); } } @@ -286,8 +285,8 @@ public class BeanPropertyMeta { swap = getPropertyPojoSwap(p); if (properties != null && p.properties().length != 0) properties = p.properties(); - if (p.typeDictionary().length > 0) - this.typeDictionary = new TypeDictionary(p.typeDictionary()); + if (p.beanDictionary().length > 0) + this.beanDictionary = new BeanDictionaryBuilder().add(p.beanDictionary()).setBeanContext(this.beanMeta.ctx).build(); } } @@ -398,7 +397,7 @@ public class BeanPropertyMeta { // If this bean has subtypes, and we haven't set the subtype yet, // store the property in a temporary cache until the bean can be instantiated. - if (m.meta.subTypeIdProperty != null && m.propertyCache == null) + if (m.meta.subTypeProperty != null && m.propertyCache == null) m.propertyCache = new TreeMap<String,Object>(); // Read-only beans get their properties stored in a cache. http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/babb64e4/juneau-core/src/main/java/org/apache/juneau/ClassMeta.java ---------------------------------------------------------------------- diff --git a/juneau-core/src/main/java/org/apache/juneau/ClassMeta.java b/juneau-core/src/main/java/org/apache/juneau/ClassMeta.java index d531d0e..06dac33 100644 --- a/juneau-core/src/main/java/org/apache/juneau/ClassMeta.java +++ b/juneau-core/src/main/java/org/apache/juneau/ClassMeta.java @@ -83,9 +83,6 @@ public final class ClassMeta<T> implements Type { isMemberClass; // True if this is a non-static member class. private MetadataMap extMeta = new MetadataMap(); // Extended metadata - private TypeDictionary typeDictionary; // The class dictionary defined on this bean or pojo. - private String name; // The lexical name associated with this bean or pojo. - private Throwable initException; // Any exceptions thrown in the init() method. private boolean hasChildPojoSwaps; // True if this class or any subclass of this class has a PojoSwap associated with it. private Object primitiveDefault; // Default value for primitive type classes. @@ -131,14 +128,6 @@ public final class ClassMeta<T> implements Type { beanFilter = findBeanFilter(beanContext); pojoSwap = findPojoSwap(beanContext); - typeDictionary = beanContext.getTypeDictionary(); - for (Bean b : ReflectionUtils.findAnnotationsParentFirst(Bean.class, innerClass)) { - if (b.typeDictionary().length > 0) - typeDictionary = new TypeDictionary(b.typeDictionary()); - if (! b.typeName().isEmpty()) - name = b.typeName(); - } - serializedClassMeta = (pojoSwap == null ? this : beanContext.getClassMeta(pojoSwap.getSwapClass())); if (serializedClassMeta == null) serializedClassMeta = this; @@ -386,28 +375,16 @@ public final class ClassMeta<T> implements Type { } /** - * Returns the class dictionary in use for this class. - * The order of lookup for the dictionary is as follows: - * <ol> - * <li>Dictionary defined via {@link Bean#typeDictionary()} (or {@link BeanFilter} equivalent). - * <li>Dictionary defined via {@link BeanContext#BEAN_typeDictionary} context property. - * </ol> - * - * @return The class dictionary in use for this class. Never <jk>null</jk>. - */ - public TypeDictionary getDictionary() { - return typeDictionary; - } - - /** - * Returns the lexical name associated with this class. + * Returns the bean dictionary name associated with this class. * <p> * The lexical name is defined by {@link Bean#typeName()}. * - * @return The lexical name associated with this class, or <jk>null</jk> if there is no lexical name defined. + * @return The type name associated with this bean class, or <jk>null</jk> if there is no type name defined or this isn't a bean. */ public String getDictionaryName() { - return name; + if (beanMeta != null) + return beanMeta.getDictionaryName(); + return null; } /** http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/babb64e4/juneau-core/src/main/java/org/apache/juneau/ObjectMap.java ---------------------------------------------------------------------- diff --git a/juneau-core/src/main/java/org/apache/juneau/ObjectMap.java b/juneau-core/src/main/java/org/apache/juneau/ObjectMap.java index 18b2609..67649b3 100644 --- a/juneau-core/src/main/java/org/apache/juneau/ObjectMap.java +++ b/juneau-core/src/main/java/org/apache/juneau/ObjectMap.java @@ -1150,7 +1150,7 @@ public class ObjectMap extends LinkedHashMap<String,Object> { * same object if entry does not exist. */ public Object cast() { - return cast((TypeDictionary)null); + return cast((BeanDictionary)null); } /** @@ -1161,16 +1161,11 @@ public class ObjectMap extends LinkedHashMap<String,Object> { * @return The new Java object of type specified by the <js>"_type"</js> entry value, or this * same object if entry does not exist. */ - public Object cast(TypeDictionary typeDictionary) { + public Object cast(BeanDictionary typeDictionary) { String c = (String)get(beanContext.getTypePropertyName()); if (c == null) { return this; } - if (typeDictionary != null) { - Class<?> c2 = typeDictionary.getClassForName(c); - if (c2 != null) - return cast2(beanContext.getClassMeta(c2)); - } return cast2(beanContext.getClassMetaFromString(c)); } @@ -1264,7 +1259,7 @@ public class ObjectMap extends LinkedHashMap<String,Object> { // Attempt to recursively cast child maps. if (v instanceof ObjectMap) - v = ((ObjectMap)v).cast(beanContext.typeDictionary); + v = ((ObjectMap)v).cast(beanContext.beanDictionary); k = (kType.isString() ? k : beanContext.convertToType(k, kType)); v = (vType.isObject() ? v : beanContext.convertToType(v, vType)); @@ -1285,7 +1280,7 @@ public class ObjectMap extends LinkedHashMap<String,Object> { // Attempt to recursively cast child maps. if (v instanceof ObjectMap) - v = ((ObjectMap)v).cast(beanContext.typeDictionary); + v = ((ObjectMap)v).cast(beanContext.beanDictionary); bm.put(k, v); } http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/babb64e4/juneau-core/src/main/java/org/apache/juneau/TypeDictionary.java ---------------------------------------------------------------------- diff --git a/juneau-core/src/main/java/org/apache/juneau/TypeDictionary.java b/juneau-core/src/main/java/org/apache/juneau/TypeDictionary.java deleted file mode 100644 index 6c31726..0000000 --- a/juneau-core/src/main/java/org/apache/juneau/TypeDictionary.java +++ /dev/null @@ -1,125 +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.*; -import org.apache.juneau.internal.*; - -/** - * A lookup table for resolving classes by name. - * <p> - * In a nutshell, provides a simple mapping of class objects to identifying names by implementing the following two methods: - * <ul> - * <li>{@link #getClassForName(String)} - * <li>{@link #getNameForClass(Class)} - * </ul> - * <p> - * Class names are defined through the {@link Bean#typeName()} annotations when using the {@link TypeDictionary#TypeDictionary(Class...)} - * constructor, but can be defined programmatically by using the {@link TypeDictionary#TypeDictionary(Map)} constructor. - * <p> - * The dictionary is used by the framework in the following ways: - * <ul> - * <li>If a class type cannot be inferred through reflection during parsing, then a helper <js>"_type"</js> is added to the serialized output - * using the name defined for that class in this dictionary. This helps determine the real class at parse time. - * <li>The dictionary name is used as element names when serialized to XML. - * </ul> - * - * @author james.bognar - */ -public class TypeDictionary { - - private final Map<String,Class<?>> map; - private final Map<Class<?>,String> reverseMap; - - /** - * Constructor. - * - * @param classes - * List of classes to add to this dictionary table. - * Each class must be one of the following: - * <ul> - * <li>A bean class that specifies a value for {@link Bean#typeName() @Bean.name()}. - * <li>A subclass of {@link TypeDictionary} whose contents will be added to this list. - * Note that this subclass must implement a no-arg constructor. - * </ul> - */ - public TypeDictionary(Class<?>...classes) { - Map<String,Class<?>> m = new HashMap<String,Class<?>>(); - for (Class<?> c : classes) { - if (c != null) { - if (ClassUtils.isParentClass(TypeDictionary.class, c)) { - try { - TypeDictionary l2 = (TypeDictionary)c.newInstance(); - m.putAll(l2.map); - } catch (Exception e) { - throw new BeanRuntimeException(e); - } - } else { - Bean b = c.getAnnotation(Bean.class); - String name = null; - if (b != null && ! b.typeName().isEmpty()) { - name = b.typeName(); - } else { - name = c.getName(); - } - m.put(name, c); - } - } - } - this.map = Collections.unmodifiableMap(m); - Map<Class<?>,String> m2 = new HashMap<Class<?>,String>(); - for (Map.Entry<String,Class<?>> e : map.entrySet()) - m2.put(e.getValue(), e.getKey()); - this.reverseMap = Collections.unmodifiableMap(m2); - } - - - /** - * Alternate constructor for defining a dictionary through a user-defined name/class map. - * - * @param classMap - * Contains the name/class pairs to add to this lookup table. - */ - public TypeDictionary(Map<String,Class<?>> classMap) { - if (classMap == null) - throw new BeanRuntimeException("Null passed to TypeDictionary(Map) constructor."); - Map<String,Class<?>> m = new HashMap<String,Class<?>>(classMap); - this.map = Collections.unmodifiableMap(m); - Map<Class<?>,String> m2 = new HashMap<Class<?>,String>(); - for (Map.Entry<String,Class<?>> e : map.entrySet()) - m2.put(e.getValue(), e.getKey()); - this.reverseMap = Collections.unmodifiableMap(m2); - } - - /** - * Returns the class associated with the specified name. - * - * @param name The name associated with the class. - * @return The class associated with the specified name, or <jk>null</jk> if no association exists. - */ - public Class<?> getClassForName(String name) { - return map.get(name); - } - - /** - * Returns the name associated with the specified class. - * - * @param c The class associated with the name. - * @return The name associated with the specified class, or <jk>null</jk> if no association exists. - */ - public String getNameForClass(Class<?> c) { - return reverseMap.get(c); - } -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/babb64e4/juneau-core/src/main/java/org/apache/juneau/annotation/Bean.java ---------------------------------------------------------------------- diff --git a/juneau-core/src/main/java/org/apache/juneau/annotation/Bean.java b/juneau-core/src/main/java/org/apache/juneau/annotation/Bean.java index e914e6c..1d12fa1 100644 --- a/juneau-core/src/main/java/org/apache/juneau/annotation/Bean.java +++ b/juneau-core/src/main/java/org/apache/juneau/annotation/Bean.java @@ -49,7 +49,7 @@ public @interface Bean { * output so that the class can be determined during parsing. * It is also used to specify element names in XML. * <p> - * The name is used in combination with the class dictionary defined through {@link #typeDictionary()}. Together, they make up + * The name is used in combination with the bean dictionary defined through {@link BeanProperty#beanDictionary()} or {@link BeanContext#BEAN_beanDictionary}. Together, they make up * a simple name/value mapping of names to classes. * Names do not need to be universally unique. However, they must be unique within a dictionary. * @@ -97,21 +97,6 @@ public @interface Bean { String typeName() default ""; /** - * The list of classes that make up the class dictionary for this class. - * <p> - * The dictionary is a name/class mapping used to find class types during parsing when they cannot be inferred through reflection. - * The names are defined through the {@link #typeName()} annotation defined on the bean or POJO classes. - * <p> - * This list can consist of the following class types: - * <ul> - * <li>Any bean class that specifies a value for {@link Bean#typeName() @Bean.name()}; - * <li>Any subclass of {@link TypeDictionary} that defines an entire set of mappings. - * Note that the subclass MUST implement a no-arg constructor so that it can be instantiated. - * </ul> - */ - Class<?>[] typeDictionary() default {}; - - /** * The set and order of names of properties associated with a bean class. * <p> * The order specified is the same order that the entries will be returned by the {@link BeanMap#entrySet()} and related methods. http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/babb64e4/juneau-core/src/main/java/org/apache/juneau/annotation/BeanProperty.java ---------------------------------------------------------------------- diff --git a/juneau-core/src/main/java/org/apache/juneau/annotation/BeanProperty.java b/juneau-core/src/main/java/org/apache/juneau/annotation/BeanProperty.java index 2db87ca..d5d13c8 100644 --- a/juneau-core/src/main/java/org/apache/juneau/annotation/BeanProperty.java +++ b/juneau-core/src/main/java/org/apache/juneau/annotation/BeanProperty.java @@ -169,18 +169,18 @@ public @interface BeanProperty { String[] properties() default {}; /** - * The list of classes that make up the class dictionary for this bean proeprty. + * The list of classes that make up the bean dictionary for this bean property. * <p> * The dictionary is a name/class mapping used to find class types during parsing when they cannot be inferred through reflection. - * The names are defined through the {@link #name()} annotation defined on the bean or POJO classes. + * The names are defined through the {@link Bean#typeName()} annotation defined on the bean class. * <p> * This list can consist of the following class types: * <ul> * <li>Any bean class that specifies a value for {@link Bean#typeName() @Bean.name()}; - * <li>Any subclass of {@link TypeDictionary} that defines an entire set of mappings. + * <li>Any subclass of {@link BeanDictionaryBuilder} that defines an entire set of mappings. * Note that the subclass MUST implement a no-arg constructor so that it can be instantiated. * </ul> */ - Class<?>[] typeDictionary() default {}; + Class<?>[] beanDictionary() default {}; } http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/babb64e4/juneau-core/src/main/java/org/apache/juneau/dto/cognos/DataSet.java ---------------------------------------------------------------------- diff --git a/juneau-core/src/main/java/org/apache/juneau/dto/cognos/DataSet.java b/juneau-core/src/main/java/org/apache/juneau/dto/cognos/DataSet.java index 0176bcf..115580a 100644 --- a/juneau-core/src/main/java/org/apache/juneau/dto/cognos/DataSet.java +++ b/juneau-core/src/main/java/org/apache/juneau/dto/cognos/DataSet.java @@ -137,9 +137,22 @@ public class DataSet { * @author James Bognar ([email protected]) */ @Bean(typeName="row") - @Xml(childName="value") - public static class Row extends LinkedList<String> { - private static final long serialVersionUID = 1L; + public static class Row { + private List<String> values = new LinkedList<String>(); + + private void add(String value) { + values.add(value); + } + + /** + * Returns the values in this row. + * + * @return The values in this row. + */ + @Xml(format=XmlFormat.COLLAPSED, childName="value") + public List<String> getValues() { + return values; + } } http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/babb64e4/juneau-core/src/main/java/org/apache/juneau/jena/RdfParser.java ---------------------------------------------------------------------- diff --git a/juneau-core/src/main/java/org/apache/juneau/jena/RdfParser.java b/juneau-core/src/main/java/org/apache/juneau/jena/RdfParser.java index fbeda23..a237d0a 100644 --- a/juneau-core/src/main/java/org/apache/juneau/jena/RdfParser.java +++ b/juneau-core/src/main/java/org/apache/juneau/jena/RdfParser.java @@ -187,7 +187,7 @@ public class RdfParser extends ReaderParser { if (rbm.hasBeanUri() && r2.getURI() != null) rbm.getBeanUriProperty().set(m, r2.getURI()); Property subTypeIdProperty = null; - BeanPropertyMeta stp = bm.getSubTypeIdProperty(); + BeanPropertyMeta stp = bm.getSubTypeProperty(); if (stp != null) { subTypeIdProperty = session.getProperty(stp.getName()); Statement st = r2.getProperty(subTypeIdProperty); http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/babb64e4/juneau-core/src/main/java/org/apache/juneau/json/JsonSerializer.java ---------------------------------------------------------------------- diff --git a/juneau-core/src/main/java/org/apache/juneau/json/JsonSerializer.java b/juneau-core/src/main/java/org/apache/juneau/json/JsonSerializer.java index 4f9b5c9..295a076 100644 --- a/juneau-core/src/main/java/org/apache/juneau/json/JsonSerializer.java +++ b/juneau-core/src/main/java/org/apache/juneau/json/JsonSerializer.java @@ -296,7 +296,7 @@ public class JsonSerializer extends WriterSerializer { out.append('{'); boolean addComma = false; - for (BeanPropertyValue p : m.getValues(session.isTrimNulls(), addClassAttr ? session.createBeanClassProperty(m, null) : null)) { + for (BeanPropertyValue p : m.getValues(session.isTrimNulls(), addClassAttr ? session.createBeanTypeNameProperty(m, null) : null)) { BeanPropertyMeta pMeta = p.getMeta(); ClassMeta<?> cMeta = p.getClassMeta(); String key = p.getName(); http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/babb64e4/juneau-core/src/main/java/org/apache/juneau/msgpack/MsgPackSerializer.java ---------------------------------------------------------------------- diff --git a/juneau-core/src/main/java/org/apache/juneau/msgpack/MsgPackSerializer.java b/juneau-core/src/main/java/org/apache/juneau/msgpack/MsgPackSerializer.java index 681b883..cf1e816 100644 --- a/juneau-core/src/main/java/org/apache/juneau/msgpack/MsgPackSerializer.java +++ b/juneau-core/src/main/java/org/apache/juneau/msgpack/MsgPackSerializer.java @@ -162,7 +162,7 @@ public class MsgPackSerializer extends OutputStreamSerializer { private void serializeBeanMap(MsgPackSerializerSession session, MsgPackOutputStream out, final BeanMap<?> m, boolean addClassAttr) throws Exception { - List<BeanPropertyValue> values = m.getValues(session.isTrimNulls(), addClassAttr ? session.createBeanClassProperty(m, null) : null); + List<BeanPropertyValue> values = m.getValues(session.isTrimNulls(), addClassAttr ? session.createBeanTypeNameProperty(m, null) : null); int size = values.size(); for (BeanPropertyValue p : values) http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/babb64e4/juneau-core/src/main/java/org/apache/juneau/serializer/SerializerSession.java ---------------------------------------------------------------------- diff --git a/juneau-core/src/main/java/org/apache/juneau/serializer/SerializerSession.java b/juneau-core/src/main/java/org/apache/juneau/serializer/SerializerSession.java index ede6331..aa28abc 100644 --- a/juneau-core/src/main/java/org/apache/juneau/serializer/SerializerSession.java +++ b/juneau-core/src/main/java/org/apache/juneau/serializer/SerializerSession.java @@ -742,21 +742,21 @@ public class SerializerSession extends Session { } /** - * Create a "_type" property that represents the name of the bean. + * Create a "_type" property that contains the dictionary name of the bean. * * @param m * The bean map to create a class property on. - * @param typeDictionary + * @param beanDictionary * The bean dictionary map to use to resolve the name of the bean class. * @return * A new bean property value. */ - public BeanPropertyValue createBeanClassProperty(BeanMap<?> m, TypeDictionary typeDictionary) { + public BeanPropertyValue createBeanTypeNameProperty(BeanMap<?> m, BeanDictionary beanDictionary) { BeanMeta<?> bm = m.getMeta(); Class<?> c = bm.getClassMeta().getInnerClass(); - String name = (typeDictionary == null ? null : typeDictionary.getNameForClass(c)); + String name = (beanDictionary == null ? null : beanDictionary.getNameForClass(c)); if (name == null) name = c.getName(); - return new BeanPropertyValue(bm.getClassProperty(), name, null); + return new BeanPropertyValue(bm.getTypeProperty(), name, null); } } http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/babb64e4/juneau-core/src/main/java/org/apache/juneau/transform/AnnotationBeanFilter.java ---------------------------------------------------------------------- diff --git a/juneau-core/src/main/java/org/apache/juneau/transform/AnnotationBeanFilter.java b/juneau-core/src/main/java/org/apache/juneau/transform/AnnotationBeanFilter.java index 467a2c3..ae8d649 100644 --- a/juneau-core/src/main/java/org/apache/juneau/transform/AnnotationBeanFilter.java +++ b/juneau-core/src/main/java/org/apache/juneau/transform/AnnotationBeanFilter.java @@ -38,18 +38,18 @@ public final class AnnotationBeanFilter<T> extends BeanFilter<T> { } private AnnotationBeanFilter(Builder<T> b) { - super(b.beanClass, b.properties, b.excludeProperties, b.interfaceClass, b.stopClass, b.sortProperties, b.propertyNamer, b.typeDictionary, b.subTypeProperty, b.subTypes); + super(b.beanClass, b.typeName, b.properties, b.excludeProperties, b.interfaceClass, b.stopClass, b.sortProperties, b.propertyNamer, b.subTypeProperty, b.subTypes); } private static class Builder<T> { Class<T> beanClass; + String typeName; String[] properties; String[] excludeProperties; Class<?> interfaceClass; Class<?> stopClass; boolean sortProperties; PropertyNamer propertyNamer; - TypeDictionary typeDictionary; String subTypeProperty; LinkedHashMap<Class<?>,String> subTypes = new LinkedHashMap<Class<?>,String>(); @@ -62,6 +62,9 @@ public final class AnnotationBeanFilter<T> extends BeanFilter<T> { if (b.properties().length > 0 && properties == null) properties = b.properties(); + if (! b.typeName().isEmpty()) + typeName = b.typeName(); + if (b.sort()) sortProperties = true; @@ -81,9 +84,6 @@ public final class AnnotationBeanFilter<T> extends BeanFilter<T> { if (b.stopClass() != Object.class) stopClass = b.stopClass(); - if (b.typeDictionary().length > 0) - typeDictionary = new TypeDictionary(b.typeDictionary()); - if (b.subTypes().length > 0) { subTypeProperty = b.subTypeProperty(); http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/babb64e4/juneau-core/src/main/java/org/apache/juneau/transform/BeanFilter.java ---------------------------------------------------------------------- diff --git a/juneau-core/src/main/java/org/apache/juneau/transform/BeanFilter.java b/juneau-core/src/main/java/org/apache/juneau/transform/BeanFilter.java index e8b90ed..60c3ad9 100644 --- a/juneau-core/src/main/java/org/apache/juneau/transform/BeanFilter.java +++ b/juneau-core/src/main/java/org/apache/juneau/transform/BeanFilter.java @@ -73,7 +73,7 @@ public abstract class BeanFilter<T> { private final PropertyNamer propertyNamer; private final Class<?> interfaceClass, stopClass; private final boolean sortProperties; - private final TypeDictionary typeDictionary; + private final String typeName; /** * Constructor. @@ -81,6 +81,8 @@ public abstract class BeanFilter<T> { * @param beanClass * The bean class that this filter applies to. * If <jk>null</jk>, then the value is inferred through reflection. + * @param typeName + * The dictionary name associated with this bean. * @param properties * Specifies the set and order of names of properties associated with a bean class. * The order specified is the same order that the entries will be returned by the {@link BeanMap#entrySet()} and related methods. @@ -144,8 +146,6 @@ public abstract class BeanFilter<T> { * Sort properties in alphabetical order. * @param propertyNamer * The property namer to use to name bean properties. - * @param typeDictionary - * The class dictionary to use for resolving class identifier names from classes. * @param subTypeProperty * Defines a virtual property on a superclass that identifies bean subtype classes. * <p> @@ -200,7 +200,7 @@ public abstract class BeanFilter<T> { * @param subTypes */ @SuppressWarnings("unchecked") - public BeanFilter(Class<T> beanClass, String[] properties, String[] excludeProperties, Class<?> interfaceClass, Class<?> stopClass, boolean sortProperties, PropertyNamer propertyNamer, TypeDictionary typeDictionary, String subTypeProperty, Map<Class<?>,String> subTypes) { + public BeanFilter(Class<T> beanClass, String typeName, String[] properties, String[] excludeProperties, Class<?> interfaceClass, Class<?> stopClass, boolean sortProperties, PropertyNamer propertyNamer, String subTypeProperty, Map<Class<?>,String> subTypes) { if (beanClass == null) { Class<?> c = this.getClass().getSuperclass(); @@ -226,13 +226,13 @@ public abstract class BeanFilter<T> { } this.beanClass = beanClass; + this.typeName = typeName; this.properties = StringUtils.split(properties, ','); this.excludeProperties = StringUtils.split(excludeProperties, ','); this.interfaceClass = interfaceClass; this.stopClass = stopClass; this.sortProperties = sortProperties; this.propertyNamer = propertyNamer; - this.typeDictionary = typeDictionary; this.subTypeAttr = subTypeProperty; this.subTypes = subTypes == null ? null : Collections.unmodifiableMap(subTypes); } @@ -244,7 +244,7 @@ public abstract class BeanFilter<T> { */ @SuppressWarnings("unchecked") public BeanFilter(Class<?> interfaceClass) { - this((Class<T>)interfaceClass, null, null, interfaceClass, null, false, null, null, null, null); + this((Class<T>)interfaceClass, null, null, null, interfaceClass, null, false, null, null, null); } /** @@ -253,7 +253,7 @@ public abstract class BeanFilter<T> { * @param properties */ public BeanFilter(String...properties) { - this(null, properties, null, null, null, false, null, null, null, null); + this(null, null, properties, null, null, null, false, null, null, null); } /** @@ -272,6 +272,15 @@ public abstract class BeanFilter<T> { } /** + * Returns the dictionary name associated with this bean. + * + * @return The dictionary name associated with this bean, or <jk>null</jk> if no name is defined. + */ + public String getTypeName() { + return typeName; + } + + /** * Returns the set and order of names of properties associated with a bean class. * @return The name of the properties associated with a bean class, or <jk>null</jk> if all bean properties should be used. */ @@ -319,15 +328,6 @@ public abstract class BeanFilter<T> { } /** - * Returns the class dictionary to use for this bean. - * - * @return The class dictionary to use for this bean. - */ - public TypeDictionary getTypeDictionary() { - return typeDictionary; - } - - /** * Returns the subtypes associated with the bean class. * * @return The set of sub types associated with this bean class, or <jk>null</jk> if bean has no subtypes defined. http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/babb64e4/juneau-core/src/main/java/org/apache/juneau/urlencoding/UonSerializer.java ---------------------------------------------------------------------- diff --git a/juneau-core/src/main/java/org/apache/juneau/urlencoding/UonSerializer.java b/juneau-core/src/main/java/org/apache/juneau/urlencoding/UonSerializer.java index 6edfb93..64550af 100644 --- a/juneau-core/src/main/java/org/apache/juneau/urlencoding/UonSerializer.java +++ b/juneau-core/src/main/java/org/apache/juneau/urlencoding/UonSerializer.java @@ -374,7 +374,7 @@ public class UonSerializer extends WriterSerializer { boolean addComma = false; - for (BeanPropertyValue p : m.getValues(session.isTrimNulls(), addClassAttr ? session.createBeanClassProperty(m, null) : null)) { + for (BeanPropertyValue p : m.getValues(session.isTrimNulls(), addClassAttr ? session.createBeanTypeNameProperty(m, null) : null)) { BeanPropertyMeta pMeta = p.getMeta(); ClassMeta<?> cMeta = p.getClassMeta(); http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/babb64e4/juneau-core/src/main/java/org/apache/juneau/urlencoding/UrlEncodingSerializer.java ---------------------------------------------------------------------- diff --git a/juneau-core/src/main/java/org/apache/juneau/urlencoding/UrlEncodingSerializer.java b/juneau-core/src/main/java/org/apache/juneau/urlencoding/UrlEncodingSerializer.java index 3d809c0..b6d5b7a 100644 --- a/juneau-core/src/main/java/org/apache/juneau/urlencoding/UrlEncodingSerializer.java +++ b/juneau-core/src/main/java/org/apache/juneau/urlencoding/UrlEncodingSerializer.java @@ -326,7 +326,7 @@ public class UrlEncodingSerializer extends UonSerializer { boolean addAmp = false; - for (BeanPropertyValue p : m.getValues(session.isTrimNulls(), addClassAttr ? session.createBeanClassProperty(m, null) : null)) { + for (BeanPropertyValue p : m.getValues(session.isTrimNulls(), addClassAttr ? session.createBeanTypeNameProperty(m, null) : null)) { BeanPropertyMeta pMeta = p.getMeta(); ClassMeta<?> cMeta = p.getClassMeta(); http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/babb64e4/juneau-core/src/test/java/org/apache/juneau/a/rttests/RoundTripBeanMapsTest.java ---------------------------------------------------------------------- diff --git a/juneau-core/src/test/java/org/apache/juneau/a/rttests/RoundTripBeanMapsTest.java b/juneau-core/src/test/java/org/apache/juneau/a/rttests/RoundTripBeanMapsTest.java index f14fe72..3934921 100755 --- a/juneau-core/src/test/java/org/apache/juneau/a/rttests/RoundTripBeanMapsTest.java +++ b/juneau-core/src/test/java/org/apache/juneau/a/rttests/RoundTripBeanMapsTest.java @@ -357,7 +357,7 @@ public class RoundTripBeanMapsTest extends RoundTripTest { public static class CFilter extends BeanFilter<C> { public CFilter() { - super(C.class, null, null, null, null, false, null, null, "subType", createSubTypes()); + super(C.class, null, null, null, null, null, false, null, "subType", createSubTypes()); } private static Map<Class<?>,String> createSubTypes() { @@ -458,7 +458,7 @@ public class RoundTripBeanMapsTest extends RoundTripTest { public static class CAFilter extends BeanFilter<CA> { public CAFilter() { - super(CA.class, null, null, null, null, false, null, null, "subType", + super(CA.class, null, null, null, null, null, false, null, "subType", new HashMap<Class<?>,String>(){{put(CA1.class,"CA1");put(CA2.class,"CA2");}} ); } @@ -588,7 +588,7 @@ public class RoundTripBeanMapsTest extends RoundTripTest { } public static class E2Filter extends BeanFilter<E2> { public E2Filter() { - super(null, null, new String[]{"f2"}, null, null, false, null, null, null, null); + super(null, null, null, new String[]{"f2"}, null, null, false, null, null, null); } } http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/babb64e4/juneau-core/src/test/java/org/apache/juneau/xml/XmlTest.java ---------------------------------------------------------------------- diff --git a/juneau-core/src/test/java/org/apache/juneau/xml/XmlTest.java b/juneau-core/src/test/java/org/apache/juneau/xml/XmlTest.java index 1d6368a..3c8b371 100755 --- a/juneau-core/src/test/java/org/apache/juneau/xml/XmlTest.java +++ b/juneau-core/src/test/java/org/apache/juneau/xml/XmlTest.java @@ -182,25 +182,6 @@ public class XmlTest { } //==================================================================================================== - // Element name on collection. - //==================================================================================================== - @Test - public void testElementNameOnCollection() throws Exception { - XmlSerializer s = XmlSerializer.DEFAULT_SIMPLE_SQ; - XmlParser p = XmlParser.DEFAULT; - F t = new F(); - t.add("bar"); - String r = s.serialize(t); - assertEquals("<foo><string>bar</string></foo>", r); - t = p.parse(r, F.class); - assertEquals("bar", t.get(0)); - validateXml(t); - } - - @Bean(typeName="foo") - public static class F extends LinkedList<String>{} - - //==================================================================================================== // Field of type collection with element name. // Element name should be ignored. //==================================================================================================== @@ -216,50 +197,14 @@ public class XmlTest { validateXml(t); } + @Bean(typeName="foo") + public static class F extends LinkedList<String>{} + @Bean(typeName="bar") public static class G { public F f1 = new F(); } -// //==================================================================================================== -// // Element name on not-a-bean. -// //==================================================================================================== -// @Test -// public void testElementNameOnNotABean() throws Exception { -// XmlSerializer s = XmlSerializer.DEFAULT_SIMPLE_SQ; -// H t = new H(); -// String r = s.serialize(t); -// assertEquals("<foo>bar</foo>", r); -// } -// -// @Pojo(name="foo") -// public static class H { -// @Override /* Object */ -// public String toString() { -// return "bar"; -// } -// } -// -// //==================================================================================================== -// // Fields with element name on not-a-beans. -// // Element name should be used on array field entries, but not regular field. -// //==================================================================================================== -// @Test -// public void testFieldsWithElementNameOnNotABeans() throws Exception { -// XmlSerializer s = XmlSerializer.DEFAULT_SIMPLE_SQ; -// I t = new I(); -// String r = s.serialize(t); -// assertEquals("<object><f1>bar</f1><f2><foo>bar</foo><foo>bar</foo></f2></object>", r); -// } -// -// public static class I { -// public H f1 = new H(); -// public H[] f2 = { -// new H(), -// new H() -// }; -// } - //==================================================================================================== // Element name on beans of a collection. //====================================================================================================
