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/05/23 19:56:15 UTC
[juneau] branch master updated: JUNEAU-234
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 23a46be JUNEAU-234
23a46be is described below
commit 23a46be19ffcae97cf99b04878a0bf24e76b6ea7
Author: JamesBognar <ja...@salesforce.com>
AuthorDate: Sat May 23 15:55:59 2020 -0400
JUNEAU-234
BEAN_ignoreInvocationExceptionsOnGetters is not working.
---
.../main/java/org/apache/juneau/BeanContext.java | 1 +
.../java/org/apache/juneau/BeanContextBuilder.java | 1 +
.../juneau/serializer/SerializerSession.java | 6 +-
.../apache/juneau/rest/client2/RestClientTest.java | 136 ++++++++++++++-------
4 files changed, 98 insertions(+), 46 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 15db6b3..8309975 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
@@ -2501,6 +2501,7 @@ public class BeanContext extends Context implements MetaProvider {
* <jc>// An interface with a single getter.</jc>
* <jk>public interface</jk> MyBean {
* String getFoo();
+ * <jk>void</jk> setFoo(String foo);
* }
*
* <jc>// Create a parser that uses interface proxies.</jc>
diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanContextBuilder.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanContextBuilder.java
index 51d946f..06cc834 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanContextBuilder.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanContextBuilder.java
@@ -3626,6 +3626,7 @@ public class BeanContextBuilder extends ContextBuilder {
* <jc>// An interface with a single getter.</jc>
* <jk>public interface</jk> MyBean {
* String getFoo();
+ * <jk>void</jk> setFoo(String foo);
* }
*
* <jc>// Create a parser that uses interface proxies.</jc>
diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/serializer/SerializerSession.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/serializer/SerializerSession.java
index 56a18af..6bc7628 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/serializer/SerializerSession.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/serializer/SerializerSession.java
@@ -254,13 +254,17 @@ public abstract class SerializerSession extends BeanTraverseSession {
*
* @param p The bean map entry representing the bean property.
* @param t The throwable that the bean getter threw.
+ * @throws SerializeException Thrown if ignoreInvocationExceptionOnGetters is false.
*/
- protected final void onBeanGetterException(BeanPropertyMeta p, Throwable t) {
+ protected final void onBeanGetterException(BeanPropertyMeta p, Throwable t) throws SerializeException {
if (listener != null)
listener.onBeanGetterException(this, t, p);
String prefix = (isDebug() ? getStack(false) + ": " : "");
addWarning("{0}Could not call getValue() on property ''{1}'' of class ''{2}'', exception = {3}", prefix,
p.getName(), p.getBeanMeta().getClassMeta(), t.getLocalizedMessage());
+ if (! isIgnoreInvocationExceptionsOnGetters())
+ throw new SerializeException(this, "{0}Could not call getValue() on property ''{1}'' of class ''{2}'', exception = {3}", prefix,
+ p.getName(), p.getBeanMeta().getClassMeta(), t.getLocalizedMessage());
}
/**
diff --git a/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/RestClientTest.java b/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/RestClientTest.java
index 6b50ead..1b39ec5 100644
--- a/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/RestClientTest.java
+++ b/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/RestClientTest.java
@@ -3385,51 +3385,97 @@ public class RestClientTest {
}
}
-// @Test
-// public void o0_beanContext_() throws Exception {
-// }
-// @Override /* GENERATED - BeanContextBuilder */
-// public <T> MockRestClient example(Class<T> pojoClass, T o) {
-// super.example(pojoClass, o);
-// return this;
-// }
-//
-// @Test
-// public void o0_beanContext_() throws Exception {
-// }
-// @Override /* GENERATED - BeanContextBuilder */
-// public <T> MockRestClient exampleJson(Class<T> pojoClass, String json) {
-// super.exampleJson(pojoClass, json);
-// return this;
-// }
-//
-// @Test
-// public void o0_beanContext_() throws Exception {
-// }
-// @Override /* GENERATED - BeanContextBuilder */
-// public MockRestClient fluentSetters() {
-// super.fluentSetters();
-// return this;
-// }
-//
-// @Test
-// public void o0_beanContext_() throws Exception {
-// }
-// @Override /* GENERATED - BeanContextBuilder */
-// public MockRestClient fluentSetters(Class<?> on) {
-// super.fluentSetters(on);
-// return this;
-// }
-//
-// @Test
-// public void o0_beanContext_() throws Exception {
-// }
-// @Override /* GENERATED - BeanContextBuilder */
-// public MockRestClient ignoreInvocationExceptionsOnGetters() {
-// super.ignoreInvocationExceptionsOnGetters();
-// return this;
-// }
-//
+ public static class O38 {
+ private String foo;
+ public String getFoo() {
+ return foo;
+ }
+ public O38 foo(String foo) {
+ this.foo = foo;
+ return this;
+ }
+ }
+
+ @Test
+ public void o038_beanContext_fluentSetters() throws Exception {
+ O38 x = MockRestClient
+ .create(A.class)
+ .simpleJson()
+ .fluentSetters()
+ .build()
+ .post("/echoBody", new StringReader("{foo:'1'}"))
+ .run()
+ .cacheBody()
+ .getBody().assertContains("{foo:'1'}")
+ .getBody().as(O38.class);
+ ;
+ assertEquals("1", x.getFoo());
+
+ x = MockRestClient
+ .create(A.class)
+ .simpleJson()
+ .fluentSetters(O38.class)
+ .build()
+ .post("/echoBody", new StringReader("{foo:'1'}"))
+ .run()
+ .cacheBody()
+ .getBody().assertContains("{foo:'1'}")
+ .getBody().as(O38.class);
+ ;
+ assertEquals("1", x.getFoo());
+ }
+
+ public static class O39 {
+ @SuppressWarnings("unused")
+ private String foo,bar;
+ public String getFoo() {
+ return foo;
+ }
+ public void setFoo(String foo) {
+ this.foo = foo;
+ }
+ public String getBar() {
+ throw new RuntimeException("xxx");
+ }
+ public void setBar(String bar) {
+ this.bar = bar;
+ }
+ public O39 init() {
+ this.foo = "1";
+ this.bar = "2";
+ return this;
+ }
+ }
+
+ @Test
+ public void o039_beanContext_ignoreInvocationExceptionsOnGetters() throws Exception {
+ try {
+ MockRestClient
+ .create(A.class)
+ .simpleJson()
+ .build()
+ .post("/echoBody", new O39().init())
+ .run()
+ ;
+ fail("Exception expected.");
+ } catch (RestCallException e) {
+ assertTrue(e.getCause(SerializeException.class).getMessage().contains("Could not call getValue() on property 'bar'"));
+ }
+
+ O39 x = MockRestClient
+ .create(A.class)
+ .simpleJson()
+ .ignoreInvocationExceptionsOnGetters()
+ .build()
+ .post("/echoBody", new O39().init())
+ .run()
+ .cacheBody()
+ .getBody().assertContains("{foo:'1'}")
+ .getBody().as(O39.class);
+ ;
+ assertEquals("1", x.getFoo());
+ }
+
// @Test
// public void o0_beanContext_() throws Exception {
// }