Repository: incubator-juneau Updated Branches: refs/heads/master feaa916d9 -> 1a4670def
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/1a4670de/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/htdocs/mouse.png ---------------------------------------------------------------------- diff --git a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/htdocs/mouse.png b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/htdocs/mouse.png new file mode 100644 index 0000000..5308006 Binary files /dev/null and b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/htdocs/mouse.png differ http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/1a4670de/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/htdocs/rabbit.png ---------------------------------------------------------------------- diff --git a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/htdocs/rabbit.png b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/htdocs/rabbit.png new file mode 100644 index 0000000..f013470 Binary files /dev/null and b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/htdocs/rabbit.png differ http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/1a4670de/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/htdocs/snake.png ---------------------------------------------------------------------- diff --git a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/htdocs/snake.png b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/htdocs/snake.png new file mode 100644 index 0000000..7f17660 Binary files /dev/null and b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/htdocs/snake.png differ http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/1a4670de/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestClientBuilder.java ---------------------------------------------------------------------- diff --git a/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestClientBuilder.java b/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestClientBuilder.java index fd2b66a..ed1d272 100644 --- a/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestClientBuilder.java +++ b/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestClientBuilder.java @@ -1426,6 +1426,42 @@ public class RestClientBuilder extends CoreObjectBuilder { } @Override /* CoreObjectBuilder */ + public RestClientBuilder includeProperties(Map<String,String> values) { + super.includeProperties(values); + return this; + } + + @Override /* CoreObjectBuilder */ + public RestClientBuilder includeProperties(String beanClassName, String properties) { + super.includeProperties(beanClassName, properties); + return this; + } + + @Override /* CoreObjectBuilder */ + public RestClientBuilder includeProperties(Class<?> beanClass, String properties) { + super.includeProperties(beanClass, properties); + return this; + } + + @Override /* CoreObjectBuilder */ + public RestClientBuilder excludeProperties(Map<String,String> values) { + super.excludeProperties(values); + return this; + } + + @Override /* CoreObjectBuilder */ + public RestClientBuilder excludeProperties(String beanClassName, String properties) { + super.excludeProperties(beanClassName, properties); + return this; + } + + @Override /* CoreObjectBuilder */ + public RestClientBuilder excludeProperties(Class<?> beanClass, String properties) { + super.excludeProperties(beanClass, properties); + return this; + } + + @Override /* CoreObjectBuilder */ public RestClientBuilder beanDictionary(Class<?>...values) { super.beanDictionary(values); return this; http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/1a4670de/juneau-rest/src/main/java/org/apache/juneau/rest/CallMethod.java ---------------------------------------------------------------------- diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/CallMethod.java b/juneau-rest/src/main/java/org/apache/juneau/rest/CallMethod.java index aae0586..bcb00db 100644 --- a/juneau-rest/src/main/java/org/apache/juneau/rest/CallMethod.java +++ b/juneau-rest/src/main/java/org/apache/juneau/rest/CallMethod.java @@ -141,6 +141,7 @@ class CallMethod implements Comparable<CallMethod> { private Response[] responses; private Map<String,Widget> widgets; + @SuppressWarnings({ "unchecked", "rawtypes" }) private Builder(Object servlet, java.lang.reflect.Method method, RestContext context) throws RestServletException { try { @@ -194,7 +195,7 @@ class CallMethod implements Comparable<CallMethod> { ParserGroupBuilder pgb = null; UrlEncodingParserBuilder uepb = null; - if (m.serializers().length > 0 || m.parsers().length > 0 || m.properties().length > 0 || m.beanFilters().length > 0 || m.pojoSwaps().length > 0) { + if (m.serializers().length > 0 || m.parsers().length > 0 || m.properties().length > 0 || m.beanFilters().length > 0 || m.pojoSwaps().length > 0 || m.bpIncludes().length() > 0 || m.bpExcludes().length() > 0) { sgb = new SerializerGroupBuilder(); pgb = new ParserGroupBuilder(); uepb = new UrlEncodingParserBuilder(urlEncodingParser.createPropertyStore()); @@ -254,6 +255,10 @@ class CallMethod implements Comparable<CallMethod> { sgb.properties(properties); for (Property p1 : m.properties()) sgb.property(p1.name(), p1.value()); + if (! m.bpIncludes().isEmpty()) + sgb.includeProperties((Map)JsonParser.DEFAULT.parse(m.bpIncludes(), Map.class, String.class, String.class)); + if (! m.bpExcludes().isEmpty()) + sgb.excludeProperties((Map)JsonParser.DEFAULT.parse(m.bpExcludes(), Map.class, String.class, String.class)); sgb.beanFilters(m.beanFilters()); sgb.pojoSwaps(m.pojoSwaps()); } http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/1a4670de/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/RestMethod.java ---------------------------------------------------------------------- diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/RestMethod.java b/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/RestMethod.java index fc770a5..3a9d1bf 100644 --- a/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/RestMethod.java +++ b/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/RestMethod.java @@ -17,6 +17,7 @@ import static java.lang.annotation.RetentionPolicy.*; import java.lang.annotation.*; +import org.apache.juneau.*; import org.apache.juneau.encoders.*; import org.apache.juneau.parser.*; import org.apache.juneau.remoteable.*; @@ -269,6 +270,77 @@ public @interface RestMethod { Class<?>[] pojoSwaps() default {}; /** + * Shortcut for specifying the {@link BeanContext#BEAN_includeProperties} property on all serializers. + * <p> + * The typical use case is when you're rendering summary and details views of the same bean in a resource and + * you want to expose or hide specific properties depending on the level of detail you want. + * <p> + * In the example below, our 'summary' view is a list of beans where we only want to show the ID property, + * and our detail view is a single bean where we want to expose different fields: + * <p class='bcode'> + * <jc>// Our bean</jc> + * <jk>public class</jk> MyBean { + * + * <jc>// Summary properties</jc> + * <ja>@Html</ja>(link=<js>"servlet:/mybeans/{id}"</js>) + * <jk>public</jk> String <jf>id</jf>; + * + * <jc>// Detail properties</jc> + * <jk>public</jk> String <jf>a</jf>, <jf>b</jf>; + * } + * + * <jc>// Only render "id" property.</jc> + * <ja>@RestMethod</ja>(name=<js>"GET"</js>, path=<js>"/mybeans"</js>, bpIncludes=<js>"{MyBean:'id'}"</js>) + * <jk>public</jk> List<MyBean> getBeanSummary(); + * + * <jc>// Only render "a" and "b" properties.</jc> + * <ja>@RestMethod</ja>(name=<js>"GET"</js>, path=<js>"/mybeans/{id}"</js>, bpIncludes=<js>"{MyBean:'a,b'}"</js>) + * <jk>public</jk> MyBean getBeanDetails(<ja>@Path</ja> String id); + * </p> + * <p> + * The format of this value is a lax JSON object. + * <br>Keys can be fully-qualified or short class names or <js>"*"</js> to represent all classes. + * <br>Values are comma-delimited lists of bean property names. + * <br>Properties apply to specified class and all subclasses. + */ + String bpIncludes() default ""; + + /** + * Shortcut for specifying the {@link BeanContext#BEAN_excludeProperties} property on all serializers. + * <p> + * Same as {@link #bpIncludes()} except you specify a list of bean property names that you want to exclude from + * serialization. + * <p> + * In the example below, our 'summary' view is a list of beans where we want to exclude some properties: + * <p class='bcode'> + * <jc>// Our bean</jc> + * <jk>public class</jk> MyBean { + * + * <jc>// Summary properties</jc> + * <ja>@Html</ja>(link=<js>"servlet:/mybeans/{id}"</js>) + * <jk>public</jk> String <jf>id</jf>; + * + * <jc>// Detail properties</jc> + * <jk>public</jk> String <jf>a</jf>, <jf>b</jf>; + * } + * + * <jc>// Don't show "a" and "b" properties.</jc> + * <ja>@RestMethod</ja>(name=<js>"GET"</js>, path=<js>"/mybeans"</js>, bpExcludes=<js>"{MyBean:'a,b'}"</js>) + * <jk>public</jk> List<MyBean> getBeanSummary(); + * + * <jc>// Render all properties.</jc> + * <ja>@RestMethod</ja>(name=<js>"GET"</js>, path=<js>"/mybeans/{id}"</js>) + * <jk>public</jk> MyBean getBeanDetails(<ja>@Path</ja> String id); + * </p> + * <p> + * The format of this value is a lax JSON object. + * <br>Keys can be fully-qualified or short class names or <js>"*"</js> to represent all classes. + * <br>Values are comma-delimited lists of bean property names. + * <br>Properties apply to specified class and all subclasses. + */ + String bpExcludes() default ""; + + /** * Specifies default values for request headers. * <p> * Strings are of the format <js>"Header-Name: header-value"</js>.
