You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@juneau.apache.org by ja...@apache.org on 2019/11/21 01:01:16 UTC

[juneau] branch master updated: JUNEAU-155 Split bpi/bpx into serializer and parser configuration properties.

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


View the commit online:
https://github.com/apache/juneau/commit/6590b96686111a56283e271d541faefecf989362

The following commit(s) were added to refs/heads/master by this push:
     new 6590b96  JUNEAU-155 Split bpi/bpx into serializer and parser configuration properties.
6590b96 is described below

commit 6590b96686111a56283e271d541faefecf989362
Author: JamesBognar <ja...@apache.org>
AuthorDate: Wed Nov 20 20:01:01 2019 -0500

    JUNEAU-155 Split bpi/bpx into serializer and parser configuration
    properties.
---
 .../main/java/org/apache/juneau/BeanContext.java   | 56 +++++++++++++++++++++-
 .../src/main/java/org/apache/juneau/BeanMeta.java  | 25 ++++++----
 .../java/org/apache/juneau/annotation/Bean.java    |  4 ++
 .../java/org/apache/juneau/annotation/Beanp.java   |  3 ++
 .../transform/AnnotationBeanFilterBuilder.java     |  6 +++
 .../org/apache/juneau/transform/BeanFilter.java    | 42 +++++++++-------
 .../apache/juneau/transform/BeanFilterBuilder.java | 12 ++++-
 .../transform/InterfaceBeanFilterBuilder.java      | 18 ++++---
 8 files changed, 132 insertions(+), 34 deletions(-)

diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanContext.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanContext.java
index 7541d8d..1d4d968 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanContext.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanContext.java
@@ -864,6 +864,10 @@ public class BeanContext extends Context {
 	 */
 	public static final String BEAN_bpx = PREFIX + ".bpx.sms";
 
+	public static final String BEAN_bpro = PREFIX + ".bpro.sms";
+
+	public static final String BEAN_bpwo = PREFIX + ".bpwo.sms";
+
 	/**
 	 * Configuration property:  Debug mode.
 	 *
@@ -1957,7 +1961,7 @@ public class BeanContext extends Context {
 	private final Locale locale;
 	private final TimeZone timeZone;
 	private final MediaType mediaType;
-	private final Map<String,String[]> bpi, bpx;
+	private final Map<String,String[]> bpi, bpx, bpro, bpwo;
 	private final PropertyNamer propertyNamer;
 	private final String beanTypePropertyName;
 	private final int beanHashCode;
@@ -2067,6 +2071,16 @@ public class BeanContext extends Context {
 			m2.put(e.getKey(), StringUtils.split(e.getValue()));
 		bpx = unmodifiableMap(m2);
 
+		m2 = new HashMap<>();
+		for (Map.Entry<String,String> e : getMapProperty(BEAN_bpro, String.class).entrySet())
+			m2.put(e.getKey(), StringUtils.split(e.getValue()));
+		bpro = unmodifiableMap(m2);
+
+		m2 = new HashMap<>();
+		for (Map.Entry<String,String> e : getMapProperty(BEAN_bpwo, String.class).entrySet())
+			m2.put(e.getKey(), StringUtils.split(e.getValue()));
+		bpwo = unmodifiableMap(m2);
+
 		locale = getInstanceProperty(BEAN_locale, Locale.class, Locale.getDefault());
 		timeZone = getInstanceProperty(BEAN_timeZone, TimeZone.class, null);
 		mediaType = getInstanceProperty(BEAN_mediaType, MediaType.class, null);
@@ -3017,6 +3031,46 @@ public class BeanContext extends Context {
 		return bpx.get("*");
 	}
 
+	protected final Map<String,String[]> getBpro() {
+		return bpro;
+	}
+
+	protected String[] getBpro(Class<?> c) {
+		if (bpro.isEmpty())
+			return null;
+		String[] s = null;
+		ClassInfo ci = ClassInfo.of(c);
+		for (ClassInfo c2 : ci.getAllParents()) {
+			s = bpro.get(c2.getFullName());
+			if (s != null)
+				return s;
+			s = bpro.get(c2.getSimpleName());
+			if (s != null)
+				return s;
+		}
+		return bpro.get("*");
+	}
+
+	protected final Map<String,String[]> getBpwo() {
+		return bpwo;
+	}
+
+	protected String[] getBpwo(Class<?> c) {
+		if (bpwo.isEmpty())
+			return null;
+		String[] s = null;
+		ClassInfo ci = ClassInfo.of(c);
+		for (ClassInfo c2 : ci.getAllParents()) {
+			s = bpwo.get(c2.getFullName());
+			if (s != null)
+				return s;
+			s = bpwo.get(c2.getSimpleName());
+			if (s != null)
+				return s;
+		}
+		return bpwo.get("*");
+	}
+
 	/**
 	 * Configuration property:  Debug mode.
 	 *
diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanMeta.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanMeta.java
index 2c1eede..d0d9a3e 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanMeta.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanMeta.java
@@ -257,17 +257,19 @@ public class BeanMeta<T> {
 				Set<String> fixedBeanProps = new LinkedHashSet<>();
 				String[] bpi = ctx.getBpi(c);
 				String[] bpx = ctx.getBpx(c);
+				String[] bpro = ctx.getBpro(c);
+				String[] bpwo = ctx.getBpwo(c);
 
 				Set<String> filterProps = new HashSet<>();  // Names of properties defined in @Bean(properties)
 
 				if (beanFilter != null) {
 
-					if (beanFilter.getProperties() != null)
-						filterProps.addAll(Arrays.asList(beanFilter.getProperties()));
+					if (beanFilter.getBpi() != null)
+						filterProps.addAll(Arrays.asList(beanFilter.getBpi()));
 
 					// Get the 'properties' attribute if specified.
-					if (beanFilter.getProperties() != null && bpi == null)
-						for (String p : beanFilter.getProperties())
+					if (beanFilter.getBpi() != null && bpi == null)
+						for (String p : beanFilter.getBpi())
 							fixedBeanProps.add(p);
 
 					if (beanFilter.getPropertyNamer() != null)
@@ -423,17 +425,20 @@ public class BeanMeta<T> {
 				if (beanFilter != null) {
 
 					// Eliminated excluded properties if BeanFilter.excludeKeys is specified.
-					String[] includeKeys = beanFilter.getProperties();
-					String[] excludeKeys = beanFilter.getExcludeProperties();
-					if (excludeKeys != null && bpx == null) {
-						for (String k : excludeKeys)
+					String[] bfbpi = beanFilter.getBpi();
+					String[] bfbpx = beanFilter.getBpx();
+					String[] bfbpro = beanFilter.getBpro();
+					String[] bfbpwo = beanFilter.getBpwo();
+
+					if (bfbpx != null && bpx == null) {
+						for (String k : bfbpx)
 							properties.remove(k);
 
 					// Only include specified properties if BeanFilter.includeKeys is specified.
 					// Note that the order must match includeKeys.
-					} else if (includeKeys != null) {
+					} else if (bfbpi != null) {
 						Map<String,BeanPropertyMeta> properties2 = new LinkedHashMap<>();
-						for (String k : includeKeys) {
+						for (String k : bfbpi) {
 							if (properties.containsKey(k))
 								properties2.put(k, properties.get(k));
 						}
diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/annotation/Bean.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/annotation/Bean.java
index 327aaa0..06ccfdb 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/annotation/Bean.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/annotation/Bean.java
@@ -101,6 +101,10 @@ public @interface Bean {
 	 */
 	String bpx() default "";
 
+	String bpro() default "";
+
+	String bpwo() default "";
+
 	/**
 	 * Bean dictionary.
 	 *
diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/annotation/Beanp.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/annotation/Beanp.java
index ec66cbb..86ef9f4 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/annotation/Beanp.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/annotation/Beanp.java
@@ -330,4 +330,7 @@ public @interface Beanp {
 	 * </p>
 	 */
 	String format() default "";
+
+	boolean ro() default false;
+	boolean wo() default false;
 }
diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/transform/AnnotationBeanFilterBuilder.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/transform/AnnotationBeanFilterBuilder.java
index c79711d..c713998 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/transform/AnnotationBeanFilterBuilder.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/transform/AnnotationBeanFilterBuilder.java
@@ -66,6 +66,12 @@ public final class AnnotationBeanFilterBuilder<T> extends BeanFilterBuilder<T> {
 			if (! b.bpx().isEmpty())
 				bpx(split(b.bpx()));
 
+			if (! b.bpro().isEmpty())
+				bpro(split(b.bpro()));
+
+			if (! b.bpwo().isEmpty())
+				bpwo(split(b.bpwo()));
+
 			if (b.propertyNamer() != PropertyNamerDefault.class)
 				propertyNamer(b.propertyNamer());
 
diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/transform/BeanFilter.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/transform/BeanFilter.java
index fdb7e55..bac9b4d 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/transform/BeanFilter.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/transform/BeanFilter.java
@@ -35,7 +35,7 @@ import org.apache.juneau.annotation.*;
 public final class BeanFilter {
 
 	private final Class<?> beanClass;
-	private final String[] bpi, bpx;
+	private final String[] bpi, bpx, bpro, bpwo;
 	private final PropertyNamer propertyNamer;
 	private final Class<?> interfaceClass, stopClass;
 	private final boolean sortProperties, fluentSetters;
@@ -51,6 +51,8 @@ public final class BeanFilter {
 		this.typeName = builder.typeName;
 		this.bpi = split(builder.bpi, ',');
 		this.bpx = split(builder.bpx, ',');
+		this.bpro = split(builder.bpro, ',');
+		this.bpwo = split(builder.bpwo, ',');
 		this.interfaceClass = builder.interfaceClass;
 		this.stopClass = builder.stopClass;
 		this.sortProperties = builder.sortProperties;
@@ -85,30 +87,47 @@ public final class BeanFilter {
 	}
 
 	/**
+	 * Returns the bean dictionary defined on this bean.
+	 *
+	 * @return The bean dictionary defined on this bean, or <jk>null</jk> if no bean dictionary is defined.
+	 */
+	public Class<?>[] getBeanDictionary() {
+		return beanDictionary;
+	}
+
+	/**
 	 * 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.
 	 */
-	public String[] getProperties() {
+	public String[] getBpi() {
 		return bpi;
 	}
 
 	/**
-	 * Returns the bean dictionary defined on this bean.
+	 * Returns the list of properties to ignore on a bean.
 	 *
-	 * @return The bean dictionary defined on this bean, or <jk>null</jk> if no bean dictionary is defined.
+	 * @return The name of the properties to ignore on a bean, or <jk>null</jk> to not ignore any properties.
 	 */
-	public Class<?>[] getBeanDictionary() {
-		return beanDictionary;
+	public String[] getBpx() {
+		return bpx;
+	}
+
+	public String[] getBpro() {
+		return bpro;
+	}
+
+	public String[] getBpwo() {
+		return bpwo;
 	}
 
 	/**
 	 * Returns <jk>true</jk> if the properties defined on this bean class should be ordered alphabetically.
 	 *
 	 * <p>
-	 * This method is only used when the {@link #getProperties()} method returns <jk>null</jk>.
+	 * This method is only used when the {@link #getBpi()} method returns <jk>null</jk>.
 	 * Otherwise, the ordering of the properties in the returned value is used.
 	 *
 	 * @return <jk>true</jk> if bean properties should be sorted.
@@ -127,15 +146,6 @@ public final class BeanFilter {
 	}
 
 	/**
-	 * Returns the list of properties to ignore on a bean.
-	 *
-	 * @return The name of the properties to ignore on a bean, or <jk>null</jk> to not ignore any properties.
-	 */
-	public String[] getExcludeProperties() {
-		return bpx;
-	}
-
-	/**
 	 * Returns the {@link PropertyNamer} associated with the bean to tailor the names of bean properties.
 	 *
 	 * @return The property namer class, or <jk>null</jk> if no property namer is associated with this bean property.
diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/transform/BeanFilterBuilder.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/transform/BeanFilterBuilder.java
index 56c059c..f6ab71f 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/transform/BeanFilterBuilder.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/transform/BeanFilterBuilder.java
@@ -58,7 +58,7 @@ public class BeanFilterBuilder<T> {
 
 	Class<?> beanClass;
 	String typeName;
-	String[] bpi, bpx;
+	String[] bpi, bpx, bpro, bpwo;
 	Class<?> interfaceClass, stopClass;
 	boolean sortProperties, fluentSetters;
 	Object propertyNamer;
@@ -541,6 +541,16 @@ public class BeanFilterBuilder<T> {
 		return this;
 	}
 
+	public BeanFilterBuilder<T> bpro(String...value) {
+		this.bpro = value;
+		return this;
+	}
+
+	public BeanFilterBuilder<T> bpwo(String...value) {
+		this.bpwo = value;
+		return this;
+	}
+
 	/**
 	 * Configuration property:  Bean dictionary.
 	 *
diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/transform/InterfaceBeanFilterBuilder.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/transform/InterfaceBeanFilterBuilder.java
index dc9080e..a4ea82f 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/transform/InterfaceBeanFilterBuilder.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/transform/InterfaceBeanFilterBuilder.java
@@ -63,9 +63,21 @@ public class InterfaceBeanFilterBuilder<T> extends BeanFilterBuilder<T> {
 			if (! b.properties().isEmpty())
 				bpi(split(b.properties()));
 
+			if (! b.excludeProperties().isEmpty())
+				bpx(split(b.excludeProperties()));
+
 			if (! b.bpi().isEmpty())
 				bpi(split(b.bpi()));
 
+			if (! b.bpx().isEmpty())
+				bpx(split(b.bpx()));
+
+			if (! b.bpro().isEmpty())
+				bpro(split(b.bpro()));
+
+			if (! b.bpwo().isEmpty())
+				bpwo(split(b.bpwo()));
+
 			if (! b.typeName().isEmpty())
 				typeName(b.typeName());
 
@@ -75,12 +87,6 @@ public class InterfaceBeanFilterBuilder<T> extends BeanFilterBuilder<T> {
 			if (b.fluentSetters())
 				fluentSetters(true);
 
-			if (! b.excludeProperties().isEmpty())
-				bpx(split(b.excludeProperties()));
-
-			if (! b.bpx().isEmpty())
-				bpx(split(b.bpx()));
-
 			try {
 				if (b.propertyNamer() != PropertyNamerDefault.class)
 					propertyNamer(b.propertyNamer());