001// *************************************************************************************************************************** 002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * 003// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * 004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * 005// * with the License. You may obtain a copy of the License at * 006// * * 007// * http://www.apache.org/licenses/LICENSE-2.0 * 008// * * 009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * 010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * 011// * specific language governing permissions and limitations under the License. * 012// *************************************************************************************************************************** 013package org.apache.juneau; 014 015import static org.apache.juneau.BeanContext.*; 016 017import java.io.*; 018import java.lang.reflect.*; 019import java.util.*; 020 021import org.apache.juneau.annotation.*; 022import org.apache.juneau.http.*; 023import org.apache.juneau.serializer.*; 024import org.apache.juneau.transform.*; 025 026/** 027 * Builder class for building instances of serializers, parsers, and bean contexts. 028 * 029 * <p> 030 * All serializers and parsers extend from this class. 031 * 032 * <p> 033 * Provides a base set of common config property setters that allow you to build up serializers and parsers. 034 * 035 * <p class='bcode'> 036 * WriterSerializer s = JsonSerializer 037 * .<jsm>create</jsm>() 038 * .set(<jsf>JSON_simpleMode</jsf>, <jk>true</jk>) 039 * .set(<jsf>SERIALIZER_useWhitespace</jsf>, <jk>true</jk>) 040 * .set(<jsf>SERIALIZER_quoteChar</jsf>, <js>"'"</js>) 041 * .build(); 042 * </p> 043 * 044 * <p> 045 * Additional convenience methods are provided for setting properties using reduced syntax. 046 * 047 * <p class='bcode'> 048 * WriterSerializer s = JsonSerializer 049 * .<jsm>create</jsm>() <jc>// Create a JsonSerializerBuilder</jc> 050 * .simple() <jc>// Simple mode</jc> 051 * .ws() <jc>// Use whitespace</jc> 052 * .sq() <jc>// Use single quotes </jc> 053 * .build(); <jc>// Create a JsonSerializer</jc> 054 * </p> 055 * 056 * <h5 class='section'>See Also:</h5> 057 * <ul> 058 * <li class='link'><a class="doclink" href="../../../overview-summary.html#juneau-marshall.ConfigurableProperties">Overview > juneau-marshall > Configurable Properties</a> 059 * </ul> 060 */ 061public class BeanContextBuilder extends ContextBuilder { 062 063 /** 064 * Constructor. 065 * 066 * All default settings. 067 */ 068 public BeanContextBuilder() { 069 super(); 070 } 071 072 /** 073 * Constructor. 074 * 075 * @param ps The initial configuration settings for this builder. 076 */ 077 public BeanContextBuilder(PropertyStore ps) { 078 super(ps); 079 } 080 081 @Override /* ContextBuilder */ 082 public BeanContext build() { 083 return build(BeanContext.class); 084 } 085 086 //-------------------------------------------------------------------------------- 087 // Properties 088 //-------------------------------------------------------------------------------- 089 090 /** 091 * Configuration property: Minimum bean class visibility. 092 * 093 * <p> 094 * Classes are not considered beans unless they meet the minimum visibility requirements. 095 * 096 * <p> 097 * For example, if the visibility is <code>PUBLIC</code> and the bean class is <jk>protected</jk>, then the class 098 * will not be interpreted as a bean class and will be treated as a string. 099 * 100 * <h5 class='section'>See Also:</h5> 101 * <ul> 102 * <li class='jf'>{@link BeanContext#BEAN_beanClassVisibility} 103 * </ul> 104 * 105 * @param value 106 * The new value for this property. 107 * <br>The default is {@link Visibility#PUBLIC}. 108 * @return This object (for method chaining). 109 */ 110 public BeanContextBuilder beanClassVisibility(Visibility value) { 111 return set(BEAN_beanClassVisibility, value); 112 } 113 114 /** 115 * Configuration property: Minimum bean constructor visibility. 116 * 117 * <p> 118 * Only look for constructors with the specified minimum visibility. 119 * 120 * <h5 class='section'>See Also:</h5> 121 * <ul> 122 * <li class='jf'>{@link BeanContext#BEAN_beanConstructorVisibility} 123 * </ul> 124 * 125 * @param value 126 * The new value for this property. 127 * <br>The default is {@link Visibility#PUBLIC}. 128 * @return This object (for method chaining). 129 */ 130 public BeanContextBuilder beanConstructorVisibility(Visibility value) { 131 return set(BEAN_beanConstructorVisibility, value); 132 } 133 134 /** 135 * Configuration property: Bean dictionary. 136 * 137 * <p> 138 * Adds to the list of classes that make up the bean dictionary in this bean context. 139 * 140 * <h5 class='section'>See Also:</h5> 141 * <ul> 142 * <li class='jf'>{@link BeanContext#BEAN_beanDictionary} 143 * </ul> 144 * 145 * @param values 146 * The values to add to this property. 147 * @return This object (for method chaining). 148 */ 149 public BeanContextBuilder beanDictionary(Object...values) { 150 return addTo(BEAN_beanDictionary, values); 151 } 152 153 /** 154 * Configuration property: Bean dictionary. 155 * 156 * <p> 157 * Same as {@link #beanDictionary(Object...)} but takes in an array of classes. 158 * 159 * <h5 class='section'>See Also:</h5> 160 * <ul> 161 * <li class='jf'>{@link BeanContext#BEAN_beanDictionary} 162 * </ul> 163 * 164 * @param values 165 * The values to add to this property. 166 * @return This object (for method chaining). 167 */ 168 public BeanContextBuilder beanDictionary(Class<?>...values) { 169 return addTo(BEAN_beanDictionary, values); 170 } 171 172 /** 173 * Configuration property: Bean dictionary. 174 * 175 * <p> 176 * Same as {@link #beanDictionary(Object...)} but allows you to optionally overwrite the previous value. 177 * 178 * <h5 class='section'>See Also:</h5> 179 * <ul> 180 * <li class='jf'>{@link BeanContext#BEAN_beanDictionary} 181 * </ul> 182 * 183 * @param append 184 * If <jk>true</jk>, the previous value is appended to. Otherwise, the previous value is replaced. 185 * @param values 186 * The new values for this property. 187 * @return This object (for method chaining). 188 */ 189 public BeanContextBuilder beanDictionary(boolean append, Object...values) { 190 return set(append, BEAN_beanDictionary, values); 191 } 192 193 /** 194 * Configuration property: Bean dictionary. 195 * 196 * <p> 197 * Removes from the list of classes that make up the bean dictionary in this bean context. 198 * 199 * <h5 class='section'>See Also:</h5> 200 * <ul> 201 * <li class='jf'>{@link BeanContext#BEAN_beanDictionary} 202 * </ul> 203 * 204 * @param values 205 * The values to remove from this property. 206 * @return This object (for method chaining). 207 */ 208 public BeanContextBuilder beanDictionaryRemove(Object...values) { 209 return removeFrom(BEAN_beanDictionary, values); 210 } 211 212 /** 213 * Configuration property: Minimum bean field visibility. 214 * 215 * <p> 216 * Only look for bean fields with the specified minimum visibility. 217 * 218 * <h5 class='section'>See Also:</h5> 219 * <ul> 220 * <li class='jf'>{@link BeanContext#BEAN_beanFieldVisibility} 221 * </ul> 222 * 223 * @param value 224 * The new value for this property. 225 * <br>The default is {@link Visibility#PUBLIC}. 226 * @return This object (for method chaining). 227 */ 228 public BeanContextBuilder beanFieldVisibility(Visibility value) { 229 return set(BEAN_beanFieldVisibility, value); 230 } 231 232 /** 233 * Configuration property: Bean filters. 234 * 235 * <p> 236 * This is a programmatic equivalent to the {@link Bean @Bean} annotation. 237 * <br>It's useful when you want to use the Bean annotation functionality, but you don't have the ability to alter 238 * the bean classes. 239 * 240 * <h5 class='section'>See Also:</h5> 241 * <ul> 242 * <li class='jf'>{@link BeanContext#BEAN_beanFilters} 243 * </ul> 244 * 245 * @param values 246 * The values to add to this property. 247 * <br>Values can consist of any of the following types: 248 * <ul> 249 * <li>Any bean class that specifies a value for {@link Bean#typeName() @Bean.typeName()}. 250 * <li>Any subclass of {@link BeanDictionaryList} containing a collection of bean classes with type name annotations. 251 * <li>Any subclass of {@link BeanDictionaryMap} containing a mapping of type names to classes without type name annotations. 252 * <li>Any array or collection of the objects above. 253 * </ul> 254 * @return This object (for method chaining). 255 */ 256 public BeanContextBuilder beanFilters(Object...values) { 257 return addTo(BEAN_beanFilters, values); 258 } 259 260 /** 261 * Configuration property: Bean filters. 262 * 263 * <p> 264 * Same as {@link #beanFilters(Object...)} but takes in an array of classes. 265 * 266 * <h5 class='section'>See Also:</h5> 267 * <ul> 268 * <li class='jf'>{@link BeanContext#BEAN_beanFilters} 269 * </ul> 270 * 271 * @param values 272 * The values to add to this property. 273 * @return This object (for method chaining). 274 */ 275 public BeanContextBuilder beanFilters(Class<?>...values) { 276 return addTo(BEAN_beanFilters, values); 277 } 278 279 /** 280 * Configuration property: Bean filters. 281 * 282 * <p> 283 * Same as {@link #beanFilters(Object...)} but allows you to optionally overwrite the previous value. 284 * 285 * <h5 class='section'>See Also:</h5> 286 * <ul> 287 * <li class='jf'>{@link BeanContext#BEAN_beanFilters} 288 * </ul> 289 * 290 * @param append 291 * If <jk>true</jk>, the previous value is appended to. Otherwise, the previous value is replaced. 292 * @param values 293 * The new values for this property. 294 * <br>Values can consist of any of the following types: 295 * <ul> 296 * <li>Any bean class that specifies a value for {@link Bean#typeName() @Bean.typeName()}. 297 * <li>Any subclass of {@link BeanDictionaryList} containing a collection of bean classes with type name annotations. 298 * <li>Any subclass of {@link BeanDictionaryMap} containing a mapping of type names to classes without type name annotations. 299 * <li>Any array or collection of the objects above. 300 * </ul> 301 * @return This object (for method chaining). 302 */ 303 public BeanContextBuilder beanFilters(boolean append, Object...values) { 304 return set(append, BEAN_beanFilters, values); 305 } 306 307 /** 308 * Configuration property: Bean filters. 309 * 310 * <p> 311 * Removes from the list of classes that make up the bean filters in this bean context. 312 * 313 * <h5 class='section'>See Also:</h5> 314 * <ul> 315 * <li class='jf'>{@link BeanContext#BEAN_beanFilters} 316 * </ul> 317 * 318 * @param values 319 * The values to remove from this property. 320 * <br>Values can consist of any of the following types: 321 * <ul> 322 * <li>Any bean class that specifies a value for {@link Bean#typeName() @Bean.typeName()}. 323 * <li>Any subclass of {@link BeanDictionaryList} containing a collection of bean classes with type name annotations. 324 * <li>Any subclass of {@link BeanDictionaryMap} containing a mapping of type names to classes without type name annotations. 325 * <li>Any array or collection of the objects above. 326 * </ul> 327 * @return This object (for method chaining). 328 */ 329 public BeanContextBuilder beanFiltersRemove(Object...values) { 330 return removeFrom(BEAN_beanFilters, values); 331 } 332 333 /** 334 * Configuration property: BeanMap.put() returns old property value. 335 * 336 * <p> 337 * If <jk>true</jk>, then the {@link BeanMap#put(String,Object) BeanMap.put()} method will return old property 338 * values. 339 * <br>Otherwise, it returns <jk>null</jk>. 340 * 341 * <h5 class='section'>See Also:</h5> 342 * <ul> 343 * <li class='jf'>{@link BeanContext#BEAN_beanMapPutReturnsOldValue} 344 * </ul> 345 * 346 * @param value 347 * The new value for this property. 348 * <br>The default is <jk>false</jk>. 349 * @return This object (for method chaining). 350 */ 351 public BeanContextBuilder beanMapPutReturnsOldValue(boolean value) { 352 return set(BEAN_beanMapPutReturnsOldValue, value); 353 } 354 355 /** 356 * Configuration property: BeanMap.put() returns old property value. 357 * 358 * <p> 359 * Shortcut for calling <code>beanMapPutReturnsOldValue(<jk>true</jk>)</code>. 360 * 361 * <h5 class='section'>See Also:</h5> 362 * <ul> 363 * <li class='jf'>{@link BeanContext#BEAN_beanMapPutReturnsOldValue} 364 * </ul> 365 * 366 * @return This object (for method chaining). 367 */ 368 public BeanContextBuilder beanMapPutReturnsOldValue() { 369 return set(BEAN_beanMapPutReturnsOldValue, true); 370 } 371 372 /** 373 * Configuration property: Minimum bean method visibility. 374 * 375 * <p> 376 * Only look for bean methods with the specified minimum visibility. 377 * 378 * <h5 class='section'>See Also:</h5> 379 * <ul> 380 * <li class='jf'>{@link BeanContext#BEAN_beanMethodVisibility} 381 * </ul> 382 * 383 * @param value 384 * The new value for this property. 385 * <br>The default is {@link Visibility#PUBLIC} 386 * @return This object (for method chaining). 387 */ 388 public BeanContextBuilder beanMethodVisibility(Visibility value) { 389 return set(BEAN_beanMethodVisibility, value); 390 } 391 392 /** 393 * Configuration property: Beans require no-arg constructors. 394 * 395 * <p> 396 * If <jk>true</jk>, a Java class must implement a default no-arg constructor to be considered a bean. 397 * <br>Otherwise, the bean will be serialized as a string using the {@link Object#toString()} method. 398 * 399 * <h5 class='section'>See Also:</h5> 400 * <ul> 401 * <li class='jf'>{@link BeanContext#BEAN_beansRequireDefaultConstructor} 402 * </ul> 403 * 404 * @param value 405 * The new value for this property. 406 * <br>The default is <jk>false</jk>. 407 * @return This object (for method chaining). 408 */ 409 public BeanContextBuilder beansRequireDefaultConstructor(boolean value) { 410 return set(BEAN_beansRequireDefaultConstructor, value); 411 } 412 413 /** 414 * Configuration property: Beans require no-arg constructors. 415 * 416 * <p> 417 * Shortcut for calling <code>beansRequireDefaultConstructor(<jk>true</jk>)</code>. 418 * 419 * <h5 class='section'>See Also:</h5> 420 * <ul> 421 * <li class='jf'>{@link BeanContext#BEAN_beansRequireDefaultConstructor} 422 * </ul> 423 * 424 * @return This object (for method chaining). 425 */ 426 public BeanContextBuilder beansRequireDefaultConstructor() { 427 return set(BEAN_beansRequireDefaultConstructor, true); 428 } 429 430 /** 431 * Configuration property: Beans require Serializable interface. 432 * 433 * <p> 434 * If <jk>true</jk>, a Java class must implement the {@link Serializable} interface to be considered a bean. 435 * <br>Otherwise, the bean will be serialized as a string using the {@link Object#toString()} method. 436 * 437 * <h5 class='section'>See Also:</h5> 438 * <ul> 439 * <li class='jf'>{@link BeanContext#BEAN_beansRequireSerializable} 440 * </ul> 441 * 442 * @param value 443 * The new value for this property. 444 * <br>The default is <jk>false</jk>. 445 * @return This object (for method chaining). 446 */ 447 public BeanContextBuilder beansRequireSerializable(boolean value) { 448 return set(BEAN_beansRequireSerializable, value); 449 } 450 451 /** 452 * Configuration property: Beans require Serializable interface. 453 * 454 * <p> 455 * Shortcut for calling <code>beansRequireSerializable(<jk>true</jk>)</code>. 456 * 457 * <h5 class='section'>See Also:</h5> 458 * <ul> 459 * <li class='jf'>{@link BeanContext#BEAN_beansRequireSerializable} 460 * </ul> 461 * 462 * @return This object (for method chaining). 463 */ 464 public BeanContextBuilder beansRequireSerializable() { 465 return set(BEAN_beansRequireSerializable, true); 466 } 467 468 /** 469 * Configuration property: Beans require setters for getters. 470 * 471 * <p> 472 * If <jk>true</jk>, only getters that have equivalent setters will be considered as properties on a bean. 473 * <br>Otherwise, they will be ignored. 474 * 475 * <h5 class='section'>See Also:</h5> 476 * <ul> 477 * <li class='jf'>{@link BeanContext#BEAN_beansRequireSettersForGetters} 478 * </ul> 479 * 480 * @param value 481 * The new value for this property. 482 * <br>The default is <jk>false</jk>. 483 * @return This object (for method chaining). 484 */ 485 public BeanContextBuilder beansRequireSettersForGetters(boolean value) { 486 return set(BEAN_beansRequireSettersForGetters, value); 487 } 488 489 /** 490 * Configuration property: Beans require setters for getters. 491 * 492 * <p> 493 * Shortcut for calling <code>beansRequireSettersForGetters(<jk>true</jk>)</code>. 494 * 495 * <h5 class='section'>See Also:</h5> 496 * <ul> 497 * <li class='jf'>{@link BeanContext#BEAN_beansRequireSettersForGetters} 498 * </ul> 499 * 500 * @return This object (for method chaining). 501 */ 502 public BeanContextBuilder beansRequireSettersForGetters() { 503 return set(BEAN_beansRequireSettersForGetters, true); 504 } 505 506 /** 507 * Configuration property: Beans require at least one property. 508 * 509 * <p> 510 * If <jk>true</jk>, then a Java class must contain at least 1 property to be considered a bean. 511 * <br>Otherwise, the bean will be serialized as a string using the {@link Object#toString()} method. 512 * 513 * <h5 class='section'>See Also:</h5> 514 * <ul> 515 * <li class='jf'>{@link BeanContext#BEAN_beansRequireSomeProperties} 516 * </ul> 517 * 518 * @param value 519 * The new value for this property. 520 * <br>The default is <jk>true</jk>. 521 * @return This object (for method chaining). 522 */ 523 public BeanContextBuilder beansRequireSomeProperties(boolean value) { 524 return set(BEAN_beansRequireSomeProperties, value); 525 } 526 527 /** 528 * Configuration property: Bean type property name. 529 * 530 * <p> 531 * This specifies the name of the bean property used to store the dictionary name of a bean type so that the 532 * parser knows the data type to reconstruct. 533 * 534 * <h5 class='section'>See Also:</h5> 535 * <ul> 536 * <li class='jf'>{@link BeanContext#BEAN_beanTypePropertyName} 537 * </ul> 538 * 539 * @param value 540 * The new value for this property. 541 * <br>The default is <js>"_type"</js>. 542 * @return This object (for method chaining). 543 */ 544 public BeanContextBuilder beanTypePropertyName(String value) { 545 return set(BEAN_beanTypePropertyName, value); 546 } 547 548 /** 549 * Configuration property: Debug mode. 550 * 551 * <p> 552 * Enables the following additional information during serialization: 553 * <ul class='spaced-list'> 554 * <li> 555 * When bean getters throws exceptions, the exception includes the object stack information 556 * in order to determine how that method was invoked. 557 * <li> 558 * Enables {@link Serializer#SERIALIZER_detectRecursions}. 559 * </ul> 560 * 561 * <h5 class='section'>See Also:</h5> 562 * <ul> 563 * <li class='jf'>{@link BeanContext#BEAN_debug} 564 * </ul> 565 * 566 * @param value 567 * The new value for this property. 568 * <br>The default is <jk>false</jk>. 569 * @return This object (for method chaining). 570 */ 571 public BeanContextBuilder debug(boolean value) { 572 return set(BEAN_debug, value); 573 } 574 575 /** 576 * Configuration property: Debug mode. 577 * 578 * <p> 579 * Shortcut for calling <code>debug(<jk>true</jk>)</code>. 580 * 581 * <h5 class='section'>See Also:</h5> 582 * <ul> 583 * <li class='jf'>{@link BeanContext#BEAN_debug} 584 * </ul> 585 * 586 * @return This object (for method chaining). 587 */ 588 public BeanContextBuilder debug() { 589 return set(BEAN_debug, true); 590 } 591 592 /** 593 * Configuration property: Bean property excludes. 594 * 595 * <p> 596 * Specifies to exclude the specified list of properties for the specified bean class. 597 * 598 * <h5 class='section'>See Also:</h5> 599 * <ul> 600 * <li class='jf'>{@link BeanContext#BEAN_excludeProperties} 601 * </ul> 602 * 603 * @param beanClass The bean class. 604 * @param properties Comma-delimited list of property names. 605 * @return This object (for method chaining). 606 */ 607 public BeanContextBuilder excludeProperties(Class<?> beanClass, String properties) { 608 return addTo(BEAN_excludeProperties, beanClass.getName(), properties); 609 } 610 611 /** 612 * Configuration property: Bean property excludes. 613 * 614 * <p> 615 * Specifies to exclude the specified list of properties for the specified bean classes. 616 * 617 * <h5 class='section'>See Also:</h5> 618 * <ul> 619 * <li class='jf'>{@link BeanContext#BEAN_excludeProperties} 620 * </ul> 621 * 622 * @param values 623 * The new value for this property. 624 * @return This object (for method chaining). 625 */ 626 public BeanContextBuilder excludeProperties(Map<String,String> values) { 627 return set(BEAN_excludeProperties, values); 628 } 629 630 /** 631 * Configuration property: Bean property excludes. 632 * 633 * <h5 class='section'>See Also:</h5> 634 * <ul> 635 * <li class='jf'>{@link BeanContext#BEAN_excludeProperties} 636 * </ul> 637 * 638 * @param beanClassName 639 * The bean class name. 640 * <br>Can be a simple name, fully-qualified name, or <js>"*"</js> for all bean classes. 641 * @param value Comma-delimited list of property names. 642 * @return This object (for method chaining). 643 */ 644 public BeanContextBuilder excludeProperties(String beanClassName, String value) { 645 return addTo(BEAN_excludeProperties, beanClassName, value); 646 } 647 648 /** 649 * Configuration property: Ignore invocation errors on getters. 650 * 651 * <p> 652 * If <jk>true</jk>, errors thrown when calling bean getter methods will silently be ignored. 653 * Otherwise, a {@code BeanRuntimeException} is thrown. 654 * 655 * <h5 class='section'>See Also:</h5> 656 * <ul> 657 * <li class='jf'>{@link BeanContext#BEAN_ignoreInvocationExceptionsOnGetters} 658 * </ul> 659 * 660 * @param value 661 * The new value for this property. 662 * <br>The default is <jk>false</jk>. 663 * @return This object (for method chaining). 664 */ 665 public BeanContextBuilder ignoreInvocationExceptionsOnGetters(boolean value) { 666 return set(BEAN_ignoreInvocationExceptionsOnGetters, value); 667 } 668 669 /** 670 * Configuration property: Ignore invocation errors on getters. 671 * 672 * <p> 673 * Shortcut for calling <code>ignoreInvocationExceptionsOnGetters(<jk>true</jk>)</code>. 674 * 675 * <h5 class='section'>See Also:</h5> 676 * <ul> 677 * <li class='jf'>{@link BeanContext#BEAN_ignoreInvocationExceptionsOnGetters} 678 * </ul> 679 * 680 * @return This object (for method chaining). 681 */ 682 public BeanContextBuilder ignoreInvocationExceptionsOnGetters() { 683 return set(BEAN_ignoreInvocationExceptionsOnGetters, true); 684 } 685 686 /** 687 * Configuration property: Ignore invocation errors on setters. 688 * 689 * <p> 690 * If <jk>true</jk>, errors thrown when calling bean setter methods will silently be ignored. 691 * <br>Otherwise, a {@code BeanRuntimeException} is thrown. 692 * 693 * <h5 class='section'>See Also:</h5> 694 * <ul> 695 * <li class='jf'>{@link BeanContext#BEAN_ignoreInvocationExceptionsOnSetters} 696 * </ul> 697 * 698 * @param value 699 * The new value for this property. 700 * <br>The default is <jk>false</jk>. 701 * @return This object (for method chaining). 702 */ 703 public BeanContextBuilder ignoreInvocationExceptionsOnSetters(boolean value) { 704 return set(BEAN_ignoreInvocationExceptionsOnSetters, value); 705 } 706 707 /** 708 * Configuration property: Ignore invocation errors on setters. 709 * 710 * <p> 711 * Shortcut for calling <code>ignoreInvocationExceptionsOnSetters(<jk>true</jk>)</code>. 712 * 713 * <h5 class='section'>See Also:</h5> 714 * <ul> 715 * <li class='jf'>{@link BeanContext#BEAN_ignoreInvocationExceptionsOnSetters} 716 * </ul> 717 * 718 * @return This object (for method chaining). 719 */ 720 public BeanContextBuilder ignoreInvocationExceptionsOnSetters() { 721 return set(BEAN_ignoreInvocationExceptionsOnSetters, true); 722 } 723 724 /** 725 * Configuration property: Ignore properties without setters. 726 * 727 * <p> 728 * If <jk>true</jk>, trying to set a value on a bean property without a setter will silently be ignored. 729 * <br>Otherwise, a {@code BeanRuntimeException} is thrown. 730 * 731 * <h5 class='section'>See Also:</h5> 732 * <ul> 733 * <li class='jf'>{@link BeanContext#BEAN_ignorePropertiesWithoutSetters} 734 * </ul> 735 * 736 * @param value 737 * The new value for this property. 738 * <br>The default is <jk>true</jk>. 739 * @return This object (for method chaining). 740 */ 741 public BeanContextBuilder ignorePropertiesWithoutSetters(boolean value) { 742 return set(BEAN_ignorePropertiesWithoutSetters, value); 743 } 744 745 /** 746 * Configuration property: Ignore unknown properties. 747 * 748 * <p> 749 * If <jk>true</jk>, trying to set a value on a non-existent bean property will silently be ignored. 750 * <br>Otherwise, a {@code BeanRuntimeException} is thrown. 751 * 752 * <h5 class='section'>See Also:</h5> 753 * <ul> 754 * <li class='jf'>{@link BeanContext#BEAN_ignoreUnknownBeanProperties} 755 * </ul> 756 * 757 * @param value 758 * The new value for this property. 759 * <br>The default is <jk>false</jk>. 760 * @return This object (for method chaining). 761 */ 762 public BeanContextBuilder ignoreUnknownBeanProperties(boolean value) { 763 return set(BEAN_ignoreUnknownBeanProperties, value); 764 } 765 766 /** 767 * Configuration property: Ignore unknown properties. 768 * 769 * <p> 770 * Shortcut for calling <code>ignoreUnknownBeanProperties(<jk>true</jk>)</code>. 771 * 772 * <h5 class='section'>See Also:</h5> 773 * <ul> 774 * <li class='jf'>{@link BeanContext#BEAN_ignoreUnknownBeanProperties} 775 * </ul> 776 * 777 * @return This object (for method chaining). 778 */ 779 public BeanContextBuilder ignoreUnknownBeanProperties() { 780 return set(BEAN_ignoreUnknownBeanProperties, true); 781 } 782 783 /** 784 * Configuration property: Ignore unknown properties with null values. 785 * 786 * <p> 787 * If <jk>true</jk>, trying to set a <jk>null</jk> value on a non-existent bean property will silently be ignored. 788 * <br>Otherwise, a {@code BeanRuntimeException} is thrown. 789 * 790 * <h5 class='section'>See Also:</h5> 791 * <ul> 792 * <li class='jf'>{@link BeanContext#BEAN_ignoreUnknownNullBeanProperties} 793 * </ul> 794 * 795 * @param value 796 * The new value for this property. 797 * <br>The default is <jk>true</jk>. 798 * @return This object (for method chaining). 799 */ 800 public BeanContextBuilder ignoreUnknownNullBeanProperties(boolean value) { 801 return set(BEAN_ignoreUnknownNullBeanProperties, value); 802 } 803 804 /** 805 * Configuration property: Implementation classes. 806 * 807 * <h5 class='section'>See Also:</h5> 808 * <ul> 809 * <li class='jf'>{@link BeanContext#BEAN_implClasses} 810 * </ul> 811 * 812 * @param interfaceClass The interface class. 813 * @param implClass The implementation class. 814 * @param <I> The class type of the interface. 815 * @return This object (for method chaining). 816 */ 817 public <I> BeanContextBuilder implClass(Class<I> interfaceClass, Class<? extends I> implClass) { 818 return addTo(BEAN_implClasses, interfaceClass.getName(), implClass); 819 } 820 821 /** 822 * Configuration property: Implementation classes. 823 * 824 * <p> 825 * For interfaces and abstract classes this method can be used to specify an implementation class for the 826 * interface/abstract class so that instances of the implementation class are used when instantiated (e.g. during a 827 * parse). 828 * 829 * <h5 class='section'>See Also:</h5> 830 * <ul> 831 * <li class='jf'>{@link BeanContext#BEAN_implClasses} 832 * </ul> 833 * 834 * @param values The new value for this property. 835 * @return This object (for method chaining). 836 */ 837 public BeanContextBuilder implClasses(Map<String,Class<?>> values) { 838 return set(BEAN_implClasses, values); 839 } 840 841 /** 842 * Configuration property: Bean property includes. 843 * 844 * <p> 845 * Specifies the set and order of names of properties associated with the bean class. 846 * 847 * <h5 class='section'>See Also:</h5> 848 * <ul> 849 * <li class='jf'>{@link BeanContext#BEAN_includeProperties} 850 * </ul> 851 * 852 * @param beanClass The bean class. 853 * @param value Comma-delimited list of property names. 854 * @return This object (for method chaining). 855 */ 856 public BeanContextBuilder includeProperties(Class<?> beanClass, String value) { 857 return addTo(BEAN_includeProperties, beanClass.getName(), value); 858 } 859 860 /** 861 * Configuration property: Bean property includes. 862 * 863 * <p> 864 * Specifies the set and order of names of properties associated with the bean class. 865 * 866 * <h5 class='section'>See Also:</h5> 867 * <ul> 868 * <li class='jf'>{@link BeanContext#BEAN_includeProperties} 869 * </ul> 870 * 871 * @param values The new value for this property. 872 * @return This object (for method chaining). 873 */ 874 public BeanContextBuilder includeProperties(Map<String,String> values) { 875 return set(BEAN_includeProperties, values); 876 } 877 878 /** 879 * Configuration property: Bean property includes. 880 * 881 * <p> 882 * Specifies the set and order of names of properties associated with the bean class. 883 * 884 * <h5 class='section'>See Also:</h5> 885 * <ul> 886 * <li class='jf'>{@link BeanContext#BEAN_includeProperties} 887 * </ul> 888 * 889 * @param beanClassName 890 * The bean class name. 891 * <br>Can be a simple name, fully-qualified name, or <js>"*"</js> for all beans. 892 * @param value Comma-delimited list of property names. 893 * @return This object (for method chaining). 894 */ 895 public BeanContextBuilder includeProperties(String beanClassName, String value) { 896 return addTo(BEAN_includeProperties, beanClassName, value); 897 } 898 899 /** 900 * Configuration property: Locale. 901 * 902 * <p> 903 * Specifies a default locale for serializer and parser sessions. 904 * 905 * <h5 class='section'>See Also:</h5> 906 * <ul> 907 * <li class='jf'>{@link BeanContext#BEAN_locale} 908 * </ul> 909 * 910 * @param value The new value for this property. 911 * @return This object (for method chaining). 912 */ 913 public BeanContextBuilder locale(Locale value) { 914 return set(BEAN_locale, value); 915 } 916 917 /** 918 * Configuration property: Media type. 919 * 920 * <p> 921 * Specifies a default media type value for serializer and parser sessions. 922 * 923 * <h5 class='section'>See Also:</h5> 924 * <ul> 925 * <li class='jf'>{@link BeanContext#BEAN_mediaType} 926 * </ul> 927 * 928 * @param value The new value for this property. 929 * @return This object (for method chaining). 930 */ 931 public BeanContextBuilder mediaType(MediaType value) { 932 return set(BEAN_mediaType, value); 933 } 934 935 /** 936 * Configuration property: Bean class exclusions. 937 * 938 * <p> 939 * Not-bean classes are converted to <code>Strings</code> during serialization even if they appear to be 940 * bean-like. 941 * 942 * <h5 class='section'>See Also:</h5> 943 * <ul> 944 * <li class='jf'>{@link BeanContext#BEAN_notBeanClasses} 945 * </ul> 946 * 947 * @param append 948 * If <jk>true</jk>, the previous value is appended to. 949 * <br>Otherwise, the previous value is replaced. 950 * @param values 951 * The new value for this property. 952 * <br>Values can consist of any of the following types: 953 * <ul> 954 * <li>Classes. 955 * <li>Arrays and collections of classes. 956 * </ul> 957 * @return This object (for method chaining). 958 */ 959 public BeanContextBuilder notBeanClasses(boolean append, Object...values) { 960 return set(append, BEAN_notBeanClasses, values); 961 } 962 963 /** 964 * Configuration property: Bean class exclusions. 965 * 966 * <p> 967 * List of classes that should not be treated as beans even if they appear to be bean-like. 968 * <br>Not-bean classes are converted to <code>Strings</code> during serialization. 969 * 970 * <h5 class='section'>See Also:</h5> 971 * <ul> 972 * <li class='jf'>{@link BeanContext#BEAN_notBeanClasses} 973 * </ul> 974 * 975 * @param values The values to add to this property. 976 * @return This object (for method chaining). 977 */ 978 public BeanContextBuilder notBeanClasses(Class<?>...values) { 979 return addTo(BEAN_notBeanClasses, values); 980 } 981 982 /** 983 * Configuration property: Bean class exclusions. 984 * 985 * <p> 986 * List of classes that should not be treated as beans even if they appear to be bean-like. 987 * <br>Not-bean classes are converted to <code>Strings</code> during serialization. 988 * 989 * <h5 class='section'>See Also:</h5> 990 * <ul> 991 * <li class='jf'>{@link BeanContext#BEAN_notBeanClasses} 992 * </ul> 993 * 994 * @param values 995 * The values to add to this property. 996 * <br>Values can consist of any of the following types: 997 * <ul> 998 * <li>Classes. 999 * <li>Arrays and collections of classes. 1000 * </ul> 1001 * @return This object (for method chaining). 1002 */ 1003 public BeanContextBuilder notBeanClasses(Object...values) { 1004 return addTo(BEAN_notBeanClasses, values); 1005 } 1006 1007 /** 1008 * Configuration property: Bean class exclusions. 1009 * 1010 * <h5 class='section'>See Also:</h5> 1011 * <ul> 1012 * <li class='jf'>{@link BeanContext#BEAN_notBeanClasses} 1013 * </ul> 1014 * 1015 * @param values 1016 * The values to remove from this property. 1017 * <br>Values can consist of any of the following types: 1018 * <ul> 1019 * <li>Classes. 1020 * <li>Arrays and collections of classes. 1021 * </ul> 1022 * @return This object (for method chaining). 1023 */ 1024 public BeanContextBuilder notBeanClassesRemove(Object...values) { 1025 return removeFrom(BEAN_notBeanClasses, values); 1026 } 1027 1028 /** 1029 * Configuration property: Bean package exclusions. 1030 * 1031 * <p> 1032 * When specified, the current list of ignore packages are appended to. 1033 * 1034 * <h5 class='section'>See Also:</h5> 1035 * <ul> 1036 * <li class='jf'>{@link BeanContext#BEAN_notBeanPackages} 1037 * </ul> 1038 * 1039 * @param append 1040 * If <jk>true</jk>, the previous value is appended to. 1041 * <br>Otherwise, the previous value is replaced. 1042 * @param values 1043 * The new values for this property. 1044 * <br>Values can consist of any of the following types: 1045 * <ul> 1046 * <li>Classes. 1047 * <li>Arrays and collections of classes. 1048 * </ul> 1049 * @return This object (for method chaining). 1050 */ 1051 public BeanContextBuilder notBeanPackages(boolean append, Object...values) { 1052 return set(append, BEAN_notBeanPackages, values); 1053 } 1054 1055 /** 1056 * Configuration property: Bean package exclusions. 1057 * 1058 * <h5 class='section'>See Also:</h5> 1059 * <ul> 1060 * <li class='jf'>{@link BeanContext#BEAN_notBeanPackages} 1061 * </ul> 1062 * 1063 * @param values 1064 * The values to add to this property. 1065 * <br>Values can consist of any of the following types: 1066 * <ul> 1067 * <li>Strings. 1068 * <li>Arrays and collections of strings. 1069 * </ul> 1070 * @return This object (for method chaining). 1071 */ 1072 public BeanContextBuilder notBeanPackages(Object...values) { 1073 return addTo(BEAN_notBeanPackages, values); 1074 } 1075 1076 /** 1077 * Configuration property: Bean package exclusions. 1078 * 1079 * <h5 class='section'>See Also:</h5> 1080 * <ul> 1081 * <li class='jf'>{@link BeanContext#BEAN_notBeanPackages} 1082 * </ul> 1083 * 1084 * @param values 1085 * The values to add to this property. 1086 * @return This object (for method chaining). 1087 */ 1088 public BeanContextBuilder notBeanPackages(String...values) { 1089 return addTo(BEAN_notBeanPackages, values); 1090 } 1091 1092 /** 1093 * Configuration property: Bean package exclusions. 1094 * 1095 * <h5 class='section'>See Also:</h5> 1096 * <ul> 1097 * <li class='jf'>{@link BeanContext#BEAN_notBeanPackages} 1098 * </ul> 1099 * 1100 * @param values 1101 * <br>Values can consist of any of the following types: 1102 * <br>Possible values are: 1103 * <ul> 1104 * <li>Strings. 1105 * <li>Arrays and collections of strings. 1106 * </ul> 1107 * @return This object (for method chaining). 1108 */ 1109 public BeanContextBuilder notBeanPackagesRemove(Object...values) { 1110 return removeFrom(BEAN_notBeanPackages, values); 1111 } 1112 1113 /** 1114 * Configuration property: POJO swaps. 1115 * 1116 * <p> 1117 * POJO swaps are used to "swap out" non-serializable classes with serializable equivalents during serialization, 1118 * and "swap in" the non-serializable class during parsing. 1119 * 1120 * <p> 1121 * An example of a POJO swap would be a <code>Calendar</code> object that gets swapped out for an ISO8601 string. 1122 * 1123 * <h5 class='section'>See Also:</h5> 1124 * <ul> 1125 * <li class='jf'>{@link BeanContext#BEAN_pojoSwaps} 1126 * </ul> 1127 * 1128 * @param append 1129 * If <jk>true</jk>, the previous value is appended to. 1130 * <br>Otherwise, the previous value is replaced. 1131 * @param values 1132 * The new value for this property. 1133 * <br>Values can consist of any of the following types: 1134 * <ul> 1135 * <li>Strings. 1136 * <li>Arrays and collections of strings. 1137 * </ul> 1138 * @return This object (for method chaining). 1139 */ 1140 public BeanContextBuilder pojoSwaps(boolean append, Object...values) { 1141 return set(append, BEAN_pojoSwaps, values); 1142 } 1143 1144 /** 1145 * Configuration property: POJO swaps. 1146 * 1147 * <h5 class='section'>See Also:</h5> 1148 * <ul> 1149 * <li class='jf'>{@link BeanContext#BEAN_pojoSwaps} 1150 * </ul> 1151 * 1152 * @param values The values to add to this property. 1153 * @return This object (for method chaining). 1154 */ 1155 public BeanContextBuilder pojoSwaps(Class<?>...values) { 1156 return addTo(BEAN_pojoSwaps, values); 1157 } 1158 1159 /** 1160 * Configuration property: POJO swaps. 1161 * 1162 * <h5 class='section'>See Also:</h5> 1163 * <ul> 1164 * <li class='jf'>{@link BeanContext#BEAN_pojoSwaps} 1165 * </ul> 1166 * 1167 * @param values 1168 * The values to add to this property. 1169 * <br>Values can consist of any of the following types: 1170 * <ul> 1171 * <li>Any subclass of {@link PojoSwap}. 1172 * <li>Any surrogate class. A shortcut for defining a {@link SurrogateSwap}. 1173 * <li>Any array or collection of the objects above. 1174 * </ul> 1175 * @return This object (for method chaining). 1176 */ 1177 public BeanContextBuilder pojoSwaps(Object...values) { 1178 return addTo(BEAN_pojoSwaps, values); 1179 } 1180 1181 /** 1182 * Configuration property: POJO swaps. 1183 * 1184 * <h5 class='section'>See Also:</h5> 1185 * <ul> 1186 * <li class='jf'>{@link BeanContext#BEAN_pojoSwaps} 1187 * </ul> 1188 * 1189 * @param values 1190 * The values to remove from this property. 1191 * <br>Values can consist of any of the following types: 1192 * <ul> 1193 * <li>Any subclass of {@link PojoSwap}. 1194 * <li>Any surrogate class. A shortcut for defining a {@link SurrogateSwap}. 1195 * <li>Any array or collection of the objects above. 1196 * </ul> 1197 * @return This object (for method chaining). 1198 */ 1199 public BeanContextBuilder pojoSwapsRemove(Object...values) { 1200 return removeFrom(BEAN_pojoSwaps, values); 1201 } 1202 1203 /** 1204 * Configuration property: Bean property namer 1205 * 1206 * <p> 1207 * The class to use for calculating bean property names. 1208 * 1209 * <h5 class='section'>See Also:</h5> 1210 * <ul> 1211 * <li class='jf'>{@link BeanContext#BEAN_propertyNamer} 1212 * </ul> 1213 * 1214 * @param value 1215 * The new value for this setting. 1216 * <br>The default is {@link PropertyNamerDefault}. 1217 * @return This object (for method chaining). 1218 */ 1219 public BeanContextBuilder propertyNamer(Class<? extends PropertyNamer> value) { 1220 return set(BEAN_propertyNamer, value); 1221 } 1222 1223 /** 1224 * Configuration property: Sort bean properties. 1225 * 1226 * <p> 1227 * When <jk>true</jk>, all bean properties will be serialized and access in alphabetical order. 1228 * Otherwise, the natural order of the bean properties is used which is dependent on the JVM vendor. 1229 * 1230 * <h5 class='section'>See Also:</h5> 1231 * <ul> 1232 * <li class='jf'>{@link BeanContext#BEAN_sortProperties} 1233 * </ul> 1234 * 1235 * @param value 1236 * The new value for this property. 1237 * <br>The default is <jk>false</jk>. 1238 * @return This object (for method chaining). 1239 */ 1240 public BeanContextBuilder sortProperties(boolean value) { 1241 return set(BEAN_sortProperties, value); 1242 } 1243 1244 /** 1245 * Configuration property: Sort bean properties. 1246 * 1247 * <p> 1248 * Shortcut for calling <code>sortProperties(<jk>true</jk>)</code>. 1249 * 1250 * <h5 class='section'>See Also:</h5> 1251 * <ul> 1252 * <li class='jf'>{@link BeanContext#BEAN_sortProperties} 1253 * </ul> 1254 * 1255 * @return This object (for method chaining). 1256 */ 1257 public BeanContextBuilder sortProperties() { 1258 return set(BEAN_sortProperties, true); 1259 } 1260 1261 /** 1262 * Configuration property: TimeZone. 1263 * 1264 * <h5 class='section'>See Also:</h5> 1265 * <ul> 1266 * <li class='jf'>{@link BeanContext#BEAN_timeZone} 1267 * </ul> 1268 * 1269 * @param value The new value for this property. 1270 * @return This object (for method chaining). 1271 */ 1272 public BeanContextBuilder timeZone(TimeZone value) { 1273 return set(BEAN_timeZone, value); 1274 } 1275 1276 /** 1277 * Configuration property: Use interface proxies. 1278 * 1279 * <p> 1280 * If <jk>true</jk>, then interfaces will be instantiated as proxy classes through the use of an 1281 * {@link InvocationHandler} if there is no other way of instantiating them. 1282 * 1283 * <h5 class='section'>See Also:</h5> 1284 * <ul> 1285 * <li class='jf'>{@link BeanContext#BEAN_useInterfaceProxies} 1286 * </ul> 1287 * 1288 * @param value 1289 * The new value for this property. 1290 * <br>The default is <jk>true</jk>. 1291 * @return This object (for method chaining). 1292 */ 1293 public BeanContextBuilder useInterfaceProxies(boolean value) { 1294 return set(BEAN_useInterfaceProxies, value); 1295 } 1296 1297 /** 1298 * Configuration property: Use Java Introspector. 1299 * 1300 * <p> 1301 * Using the built-in Java bean introspector will not pick up fields or non-standard getters/setters. 1302 * 1303 * <h5 class='section'>Notes:</h5> 1304 * <ul> 1305 * <li>Most {@link Bean @Bean} annotations will be ignored if you enable this setting. 1306 * </ul> 1307 * 1308 * <h5 class='section'>See Also:</h5> 1309 * <ul> 1310 * <li class='jf'>{@link BeanContext#BEAN_useJavaBeanIntrospector} 1311 * </ul> 1312 * 1313 * @param value 1314 * The new value for this property. 1315 * <br>The default is <jk>false</jk>. 1316 * @return This object (for method chaining). 1317 */ 1318 public BeanContextBuilder useJavaBeanIntrospector(boolean value) { 1319 return set(BEAN_useJavaBeanIntrospector, value); 1320 } 1321 1322 /** 1323 * Configuration property: Use Java Introspector. 1324 * 1325 * <p> 1326 * Shortcut for calling <code>useJavaBeanIntrospector(<jk>true</jk>)</code>. 1327 * 1328 * <h5 class='section'>See Also:</h5> 1329 * <ul> 1330 * <li class='jf'>{@link BeanContext#BEAN_useJavaBeanIntrospector} 1331 * </ul> 1332 * 1333 * @return This object (for method chaining). 1334 */ 1335 public BeanContextBuilder useJavaBeanIntrospector() { 1336 return set(BEAN_useJavaBeanIntrospector, true); 1337 } 1338 1339 @Override /* ContextBuilder */ 1340 public BeanContextBuilder set(String name, Object value) { 1341 super.set(name, value); 1342 return this; 1343 } 1344 1345 @Override /* ContextBuilder */ 1346 public BeanContextBuilder set(boolean append, String name, Object value) { 1347 super.set(append, name, value); 1348 return this; 1349 } 1350 1351 @Override /* ContextBuilder */ 1352 public BeanContextBuilder set(Map<String,Object> properties) { 1353 super.set(properties); 1354 return this; 1355 } 1356 1357 @Override /* ContextBuilder */ 1358 public BeanContextBuilder add(Map<String,Object> properties) { 1359 super.add(properties); 1360 return this; 1361 } 1362 1363 @Override /* ContextBuilder */ 1364 public BeanContextBuilder addTo(String name, Object value) { 1365 super.addTo(name, value); 1366 return this; 1367 } 1368 1369 @Override /* ContextBuilder */ 1370 public BeanContextBuilder addTo(String name, String key, Object value) { 1371 super.addTo(name, key, value); 1372 return this; 1373 } 1374 1375 @Override /* ContextBuilder */ 1376 public BeanContextBuilder removeFrom(String name, Object value) { 1377 super.removeFrom(name, value); 1378 return this; 1379 } 1380 1381 @Override /* ContextBuilder */ 1382 public BeanContextBuilder apply(PropertyStore copyFrom) { 1383 super.apply(copyFrom); 1384 return this; 1385 } 1386}