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 2020/09/25 14:00:56 UTC

[juneau] branch master updated: JUNEAU-241 withX method support.

This is an automated email from the ASF dual-hosted git repository.

jamesbognar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/juneau.git


The following commit(s) were added to refs/heads/master by this push:
     new 61a3358  JUNEAU-241 withX method support.
61a3358 is described below

commit 61a335873fe5848da35f43c175f9259f3e40c287
Author: JamesBognar <ja...@salesforce.com>
AuthorDate: Fri Sep 25 10:00:51 2020 -0400

    JUNEAU-241 withX method support.
---
 .../org/apache/juneau/a/rttests/RoundTripBeanMapsTest.java   |  3 ++-
 .../src/main/java/org/apache/juneau/BeanMeta.java            |  3 +++
 juneau-doc/docs/ReleaseNotes/8.1.4.html                      | 12 ++++++++++++
 3 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/a/rttests/RoundTripBeanMapsTest.java b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/a/rttests/RoundTripBeanMapsTest.java
index a648463..78f3ef6 100755
--- a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/a/rttests/RoundTripBeanMapsTest.java
+++ b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/a/rttests/RoundTripBeanMapsTest.java
@@ -204,8 +204,9 @@ public class RoundTripBeanMapsTest extends RoundTripTest {
 		public int getF6() {
 			return f6;
 		}
-		public void setF6(int f6) {
+		public A withF6(int f6) {
 			this.f6 = f6;
+			return this;
 		}
 
 		public A() {}
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 2e39f83..350978c 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
@@ -755,6 +755,9 @@ public class BeanMeta<T> {
 					} else if (n.startsWith("set") && (rt.isParentOf(c) || rt.is(Void.TYPE))) {
 						methodType = SETTER;
 						n = n.substring(3);
+					} else if (n.startsWith("with") && (rt.isParentOf(c))) {
+						methodType = SETTER;
+						n = n.substring(4);
 					} else if (bpName != null) {
 						methodType = SETTER;
 						if (bpName.isEmpty()) {
diff --git a/juneau-doc/docs/ReleaseNotes/8.1.4.html b/juneau-doc/docs/ReleaseNotes/8.1.4.html
index 7330b58..ef3f802 100644
--- a/juneau-doc/docs/ReleaseNotes/8.1.4.html
+++ b/juneau-doc/docs/ReleaseNotes/8.1.4.html
@@ -248,6 +248,18 @@
 			<li class='ja'>{@link oaj.annotation.Bean#interceptor Bean(interceptor)}
 			<li class='jm'>{@link oaj.BeanContextBuilder#beanInterceptor(Class,Class)}
 		</ul>
+	<li>
+		Fluent setters that follow the <c>withX</c> convention are now automatically detected by all parsers.
+		<p class='bpcode w800'>
+	<jc>// A bean with a fluent setter.</jc>
+	<jk>public class</jk> MyBean {
+		<jk>public</jk> MyBean withFoo(String <jv>foo</jv>) {
+			<jk>this</jk>.<jf>foo</jf> = <jv>foo</jv>;
+			<jk>return this</jk>;
+		}
+	}
+		</p>
+		Note you could previously use the <ja>@BeanProperty</ja> annotation to identify these setters.
 </ul>
 
 <h5 class='topic w800'>juneau-rest-server</h5>