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.*; 016import static org.apache.juneau.internal.StringUtils.*; 017 018import java.io.*; 019import java.lang.reflect.*; 020import java.util.*; 021 022import org.apache.juneau.annotation.*; 023import org.apache.juneau.http.*; 024import org.apache.juneau.marshall.*; 025import org.apache.juneau.parser.*; 026import org.apache.juneau.reflect.*; 027import org.apache.juneau.serializer.*; 028import org.apache.juneau.svl.*; 029import org.apache.juneau.transform.*; 030 031/** 032 * Builder class for building instances of serializers, parsers, and bean contexts. 033 * 034 * <p> 035 * All serializers and parsers extend from this class. 036 * 037 * <p> 038 * Provides a base set of common config property setters that allow you to build up serializers and parsers. 039 * 040 * <p class='bcode w800'> 041 * WriterSerializer s = JsonSerializer 042 * .<jsm>create</jsm>() 043 * .set(<jsf>JSON_simpleMode</jsf>, <jk>true</jk>) 044 * .set(<jsf>SERIALIZER_useWhitespace</jsf>, <jk>true</jk>) 045 * .set(<jsf>SERIALIZER_quoteChar</jsf>, <js>"'"</js>) 046 * .build(); 047 * </p> 048 * 049 * <p> 050 * Additional convenience methods are provided for setting properties using reduced syntax. 051 * 052 * <p class='bcode w800'> 053 * WriterSerializer s = JsonSerializer 054 * .<jsm>create</jsm>() <jc>// Create a JsonSerializerBuilder</jc> 055 * .simple() <jc>// Simple mode</jc> 056 * .ws() <jc>// Use whitespace</jc> 057 * .sq() <jc>// Use single quotes </jc> 058 * .build(); <jc>// Create a JsonSerializer</jc> 059 * </p> 060 * 061 * <ul class='seealso'> 062 * <li class='link'>{@doc juneau-marshall.ConfigurableProperties} 063 * </ul> 064 */ 065public class BeanContextBuilder extends ContextBuilder { 066 067 /** 068 * Constructor. 069 * 070 * All default settings. 071 */ 072 public BeanContextBuilder() { 073 super(); 074 } 075 076 /** 077 * Constructor. 078 * 079 * @param ps The initial configuration settings for this builder. 080 */ 081 public BeanContextBuilder(PropertyStore ps) { 082 super(ps); 083 } 084 085 @Override /* ContextBuilder */ 086 public BeanContext build() { 087 return build(BeanContext.class); 088 } 089 090 //----------------------------------------------------------------------------------------------------------------- 091 // Properties 092 //----------------------------------------------------------------------------------------------------------------- 093 094 /** 095 * Configuration property: Minimum bean class visibility. 096 * 097 * <p> 098 * Classes are not considered beans unless they meet the minimum visibility requirements. 099 * 100 * <p> 101 * For example, if the visibility is <c>PUBLIC</c> and the bean class is <jk>protected</jk>, then the class 102 * will not be interpreted as a bean class and will be treated as a string. 103 * 104 * <ul class='seealso'> 105 * <li class='jf'>{@link BeanContext#BEAN_beanClassVisibility} 106 * </ul> 107 * 108 * @param value 109 * The new value for this property. 110 * <br>The default is {@link Visibility#PUBLIC}. 111 * @return This object (for method chaining). 112 */ 113 public BeanContextBuilder beanClassVisibility(Visibility value) { 114 return set(BEAN_beanClassVisibility, value); 115 } 116 117 /** 118 * Configuration property: Minimum bean constructor visibility. 119 * 120 * <p> 121 * Only look for constructors with the specified minimum visibility. 122 * 123 * <ul class='seealso'> 124 * <li class='jf'>{@link BeanContext#BEAN_beanConstructorVisibility} 125 * </ul> 126 * 127 * @param value 128 * The new value for this property. 129 * <br>The default is {@link Visibility#PUBLIC}. 130 * @return This object (for method chaining). 131 */ 132 public BeanContextBuilder beanConstructorVisibility(Visibility value) { 133 return set(BEAN_beanConstructorVisibility, value); 134 } 135 136 /** 137 * Configuration property: Bean dictionary. 138 * 139 * <p> 140 * Adds to the list of classes that make up the bean dictionary in this bean context. 141 * 142 * <ul class='seealso'> 143 * <li class='jf'>{@link BeanContext#BEAN_beanDictionary} 144 * </ul> 145 * 146 * @param values 147 * The values to add to this property. 148 * @return This object (for method chaining). 149 * @deprecated Use {@link #dictionary(Object...)} 150 */ 151 @Deprecated 152 public BeanContextBuilder beanDictionary(Object...values) { 153 return addTo(BEAN_beanDictionary, values); 154 } 155 156 /** 157 * Configuration property: Bean dictionary. 158 * 159 * <p> 160 * Same as {@link #beanDictionary(Object...)} but takes in an array of classes. 161 * 162 * <ul class='seealso'> 163 * <li class='jf'>{@link BeanContext#BEAN_beanDictionary} 164 * </ul> 165 * 166 * @param values 167 * The values to add to this property. 168 * @return This object (for method chaining). 169 * @deprecated Use {@link #dictionary(Class...)} 170 */ 171 @Deprecated 172 public BeanContextBuilder beanDictionary(Class<?>...values) { 173 return addTo(BEAN_beanDictionary, values); 174 } 175 176 /** 177 * Configuration property: Bean dictionary. 178 * 179 * <p> 180 * Same as {@link #beanDictionary(Object...)} but replaces the existing value. 181 * 182 * <ul class='seealso'> 183 * <li class='jf'>{@link BeanContext#BEAN_beanDictionary} 184 * </ul> 185 * 186 * @param values 187 * The new values for this property. 188 * @return This object (for method chaining). 189 * @deprecated Use {@link #dictionaryReplace(Class...)} 190 */ 191 @Deprecated 192 public BeanContextBuilder beanDictionaryReplace(Class<?>...values) { 193 return set(BEAN_beanDictionary, values); 194 } 195 196 /** 197 * Configuration property: Bean dictionary. 198 * 199 * <p> 200 * Same as {@link #beanDictionary(Object...)} but replaces the existing value. 201 * 202 * <ul class='seealso'> 203 * <li class='jf'>{@link BeanContext#BEAN_beanDictionary} 204 * </ul> 205 * 206 * @param values 207 * The new values for this property. 208 * @return This object (for method chaining). 209 * @deprecated Use {@link #dictionaryReplace(Object...)} 210 */ 211 @Deprecated 212 public BeanContextBuilder beanDictionaryReplace(Object...values) { 213 return set(BEAN_beanDictionary, values); 214 } 215 216 /** 217 * Configuration property: Bean dictionary. 218 * 219 * <p> 220 * Removes from the list of classes that make up the bean dictionary in this bean context. 221 * 222 * <ul class='seealso'> 223 * <li class='jf'>{@link BeanContext#BEAN_beanDictionary} 224 * </ul> 225 * 226 * @param values 227 * The values to remove from this property. 228 * @return This object (for method chaining). 229 * @deprecated Use {@link #dictionaryRemove(Class...)} 230 */ 231 @Deprecated 232 public BeanContextBuilder beanDictionaryRemove(Class<?>...values) { 233 return removeFrom(BEAN_beanDictionary, values); 234 } 235 236 /** 237 * Configuration property: Bean dictionary. 238 * 239 * <p> 240 * Removes from the list of classes that make up the bean dictionary in this bean context. 241 * 242 * <ul class='seealso'> 243 * <li class='jf'>{@link BeanContext#BEAN_beanDictionary} 244 * </ul> 245 * 246 * @param values 247 * The values to remove from this property. 248 * @return This object (for method chaining). 249 * @deprecated Use {@link #dictionaryRemove(Object...)} 250 */ 251 @Deprecated 252 public BeanContextBuilder beanDictionaryRemove(Object...values) { 253 return removeFrom(BEAN_beanDictionary, values); 254 } 255 256 /** 257 * Configuration property: Minimum bean field visibility. 258 * 259 * <p> 260 * Only look for bean fields with the specified minimum visibility. 261 * 262 * <ul class='seealso'> 263 * <li class='jf'>{@link BeanContext#BEAN_beanFieldVisibility} 264 * </ul> 265 * 266 * @param value 267 * The new value for this property. 268 * <br>The default is {@link Visibility#PUBLIC}. 269 * @return This object (for method chaining). 270 */ 271 public BeanContextBuilder beanFieldVisibility(Visibility value) { 272 return set(BEAN_beanFieldVisibility, value); 273 } 274 275 /** 276 * Configuration property: Bean filters. 277 * 278 * <p> 279 * This is a programmatic equivalent to the {@link Bean @Bean} annotation. 280 * <br>It's useful when you want to use the Bean annotation functionality, but you don't have the ability to alter 281 * the bean classes. 282 * 283 * <ul class='seealso'> 284 * <li class='jf'>{@link BeanContext#BEAN_beanFilters} 285 * </ul> 286 * 287 * @param values 288 * The values to add to this property. 289 * <br>Values can consist of any of the following types: 290 * <ul> 291 * <li>Any bean class that specifies a value for {@link Bean#typeName() @Bean(typeName)}. 292 * <li>Any subclass of {@link BeanDictionaryList} containing a collection of bean classes with type name annotations. 293 * <li>Any subclass of {@link BeanDictionaryMap} containing a mapping of type names to classes without type name annotations. 294 * <li>Any array or collection of the objects above. 295 * </ul> 296 * @return This object (for method chaining). 297 */ 298 public BeanContextBuilder beanFilters(Object...values) { 299 return addTo(BEAN_beanFilters, values); 300 } 301 302 /** 303 * Configuration property: Bean filters. 304 * 305 * <p> 306 * Same as {@link #beanFilters(Object...)} but takes in an array of classes. 307 * 308 * <ul class='seealso'> 309 * <li class='jf'>{@link BeanContext#BEAN_beanFilters} 310 * </ul> 311 * 312 * @param values 313 * The values to add to this property. 314 * @return This object (for method chaining). 315 */ 316 public BeanContextBuilder beanFilters(Class<?>...values) { 317 return addTo(BEAN_beanFilters, values); 318 } 319 320 /** 321 * Configuration property: Bean filters. 322 * 323 * <p> 324 * Same as {@link #beanFilters(Object...)} but replaces the existing values. 325 * 326 * <ul class='seealso'> 327 * <li class='jf'>{@link BeanContext#BEAN_beanFilters} 328 * </ul> 329 * 330 * @param values 331 * The new values for this property. 332 * <br>Values can consist of any of the following types: 333 * <ul> 334 * <li>Any bean class that specifies a value for {@link Bean#typeName() @Bean(typeName)}. 335 * <li>Any subclass of {@link BeanDictionaryList} containing a collection of bean classes with type name annotations. 336 * <li>Any subclass of {@link BeanDictionaryMap} containing a mapping of type names to classes without type name annotations. 337 * </ul> 338 * @return This object (for method chaining). 339 */ 340 public BeanContextBuilder beanFiltersReplace(Class<?>...values) { 341 return set(BEAN_beanFilters, values); 342 } 343 344 /** 345 * Configuration property: Bean filters. 346 * 347 * <p> 348 * Same as {@link #beanFilters(Object...)} but replaces the existing values. 349 * 350 * <ul class='seealso'> 351 * <li class='jf'>{@link BeanContext#BEAN_beanFilters} 352 * </ul> 353 * 354 * @param values 355 * The new values for this property. 356 * <br>Values can consist of any of the following types: 357 * <ul> 358 * <li>Any bean class that specifies a value for {@link Bean#typeName() @Bean(typeName)}. 359 * <li>Any subclass of {@link BeanDictionaryList} containing a collection of bean classes with type name annotations. 360 * <li>Any subclass of {@link BeanDictionaryMap} containing a mapping of type names to classes without type name annotations. 361 * <li>Any array or collection of the objects above. 362 * </ul> 363 * @return This object (for method chaining). 364 */ 365 public BeanContextBuilder beanFiltersReplace(Object...values) { 366 return set(BEAN_beanFilters, values); 367 } 368 369 /** 370 * Configuration property: Bean filters. 371 * 372 * <p> 373 * Removes from the list of classes that make up the bean filters in this bean context. 374 * 375 * <ul class='seealso'> 376 * <li class='jf'>{@link BeanContext#BEAN_beanFilters} 377 * </ul> 378 * 379 * @param values 380 * The values to remove from this property. 381 * <br>Values can consist of any of the following types: 382 * <ul> 383 * <li>Any bean class that specifies a value for {@link Bean#typeName() @Bean(typeName)}. 384 * <li>Any subclass of {@link BeanDictionaryList} containing a collection of bean classes with type name annotations. 385 * <li>Any subclass of {@link BeanDictionaryMap} containing a mapping of type names to classes without type name annotations. 386 * </ul> 387 * @return This object (for method chaining). 388 */ 389 public BeanContextBuilder beanFiltersRemove(Class<?>...values) { 390 return removeFrom(BEAN_beanFilters, values); 391 } 392 393 /** 394 * Configuration property: Bean filters. 395 * 396 * <p> 397 * Removes from the list of classes that make up the bean filters in this bean context. 398 * 399 * <ul class='seealso'> 400 * <li class='jf'>{@link BeanContext#BEAN_beanFilters} 401 * </ul> 402 * 403 * @param values 404 * The values to remove from this property. 405 * <br>Values can consist of any of the following types: 406 * <ul> 407 * <li>Any bean class that specifies a value for {@link Bean#typeName() @Bean(typeName)}. 408 * <li>Any subclass of {@link BeanDictionaryList} containing a collection of bean classes with type name annotations. 409 * <li>Any subclass of {@link BeanDictionaryMap} containing a mapping of type names to classes without type name annotations. 410 * <li>Any array or collection of the objects above. 411 * </ul> 412 * @return This object (for method chaining). 413 */ 414 public BeanContextBuilder beanFiltersRemove(Object...values) { 415 return removeFrom(BEAN_beanFilters, values); 416 } 417 418 /** 419 * Configuration property: BeanMap.put() returns old property value. 420 * 421 * <p> 422 * If <jk>true</jk>, then the {@link BeanMap#put(String,Object) BeanMap.put()} method will return old property 423 * values. 424 * <br>Otherwise, it returns <jk>null</jk>. 425 * 426 * <ul class='seealso'> 427 * <li class='jf'>{@link BeanContext#BEAN_beanMapPutReturnsOldValue} 428 * </ul> 429 * 430 * @param value 431 * The new value for this property. 432 * <br>The default is <jk>false</jk>. 433 * @return This object (for method chaining). 434 */ 435 public BeanContextBuilder beanMapPutReturnsOldValue(boolean value) { 436 return set(BEAN_beanMapPutReturnsOldValue, value); 437 } 438 439 /** 440 * Configuration property: BeanMap.put() returns old property value. 441 * 442 * <p> 443 * Shortcut for calling <code>beanMapPutReturnsOldValue(<jk>true</jk>)</code>. 444 * 445 * <ul class='seealso'> 446 * <li class='jf'>{@link BeanContext#BEAN_beanMapPutReturnsOldValue} 447 * </ul> 448 * 449 * @return This object (for method chaining). 450 */ 451 public BeanContextBuilder beanMapPutReturnsOldValue() { 452 return set(BEAN_beanMapPutReturnsOldValue, true); 453 } 454 455 /** 456 * Configuration property: Minimum bean method visibility. 457 * 458 * <p> 459 * Only look for bean methods with the specified minimum visibility. 460 * 461 * <ul class='seealso'> 462 * <li class='jf'>{@link BeanContext#BEAN_beanMethodVisibility} 463 * </ul> 464 * 465 * @param value 466 * The new value for this property. 467 * <br>The default is {@link Visibility#PUBLIC} 468 * @return This object (for method chaining). 469 */ 470 public BeanContextBuilder beanMethodVisibility(Visibility value) { 471 return set(BEAN_beanMethodVisibility, value); 472 } 473 474 /** 475 * Configuration property: Beans require no-arg constructors. 476 * 477 * <p> 478 * If <jk>true</jk>, a Java class must implement a default no-arg constructor to be considered a bean. 479 * <br>Otherwise, the bean will be serialized as a string using the {@link Object#toString()} method. 480 * 481 * <ul class='seealso'> 482 * <li class='jf'>{@link BeanContext#BEAN_beansRequireDefaultConstructor} 483 * </ul> 484 * 485 * @param value 486 * The new value for this property. 487 * <br>The default is <jk>false</jk>. 488 * @return This object (for method chaining). 489 */ 490 public BeanContextBuilder beansRequireDefaultConstructor(boolean value) { 491 return set(BEAN_beansRequireDefaultConstructor, value); 492 } 493 494 /** 495 * Configuration property: Beans require no-arg constructors. 496 * 497 * <p> 498 * Shortcut for calling <code>beansRequireDefaultConstructor(<jk>true</jk>)</code>. 499 * 500 * <ul class='seealso'> 501 * <li class='jf'>{@link BeanContext#BEAN_beansRequireDefaultConstructor} 502 * </ul> 503 * 504 * @return This object (for method chaining). 505 */ 506 public BeanContextBuilder beansRequireDefaultConstructor() { 507 return set(BEAN_beansRequireDefaultConstructor, true); 508 } 509 510 /** 511 * Configuration property: Beans require Serializable interface. 512 * 513 * <p> 514 * If <jk>true</jk>, a Java class must implement the {@link Serializable} interface to be considered a bean. 515 * <br>Otherwise, the bean will be serialized as a string using the {@link Object#toString()} method. 516 * 517 * <ul class='seealso'> 518 * <li class='jf'>{@link BeanContext#BEAN_beansRequireSerializable} 519 * </ul> 520 * 521 * @param value 522 * The new value for this property. 523 * <br>The default is <jk>false</jk>. 524 * @return This object (for method chaining). 525 */ 526 public BeanContextBuilder beansRequireSerializable(boolean value) { 527 return set(BEAN_beansRequireSerializable, value); 528 } 529 530 /** 531 * Configuration property: Beans require Serializable interface. 532 * 533 * <p> 534 * Shortcut for calling <code>beansRequireSerializable(<jk>true</jk>)</code>. 535 * 536 * <ul class='seealso'> 537 * <li class='jf'>{@link BeanContext#BEAN_beansRequireSerializable} 538 * </ul> 539 * 540 * @return This object (for method chaining). 541 */ 542 public BeanContextBuilder beansRequireSerializable() { 543 return set(BEAN_beansRequireSerializable, true); 544 } 545 546 /** 547 * Configuration property: Beans require setters for getters. 548 * 549 * <p> 550 * If <jk>true</jk>, only getters that have equivalent setters will be considered as properties on a bean. 551 * <br>Otherwise, they will be ignored. 552 * 553 * <ul class='seealso'> 554 * <li class='jf'>{@link BeanContext#BEAN_beansRequireSettersForGetters} 555 * </ul> 556 * 557 * @param value 558 * The new value for this property. 559 * <br>The default is <jk>false</jk>. 560 * @return This object (for method chaining). 561 */ 562 public BeanContextBuilder beansRequireSettersForGetters(boolean value) { 563 return set(BEAN_beansRequireSettersForGetters, value); 564 } 565 566 /** 567 * Configuration property: Beans require setters for getters. 568 * 569 * <p> 570 * Shortcut for calling <code>beansRequireSettersForGetters(<jk>true</jk>)</code>. 571 * 572 * <ul class='seealso'> 573 * <li class='jf'>{@link BeanContext#BEAN_beansRequireSettersForGetters} 574 * </ul> 575 * 576 * @return This object (for method chaining). 577 */ 578 public BeanContextBuilder beansRequireSettersForGetters() { 579 return set(BEAN_beansRequireSettersForGetters, true); 580 } 581 582 /** 583 * Configuration property: Beans require at least one property. 584 * 585 * <p> 586 * If <jk>true</jk>, then a Java class must contain at least 1 property to be considered a bean. 587 * <br>Otherwise, the bean will be serialized as a string using the {@link Object#toString()} method. 588 * 589 * <ul class='seealso'> 590 * <li class='jf'>{@link BeanContext#BEAN_beansRequireSomeProperties} 591 * </ul> 592 * 593 * @param value 594 * The new value for this property. 595 * <br>The default is <jk>true</jk>. 596 * @return This object (for method chaining). 597 */ 598 public BeanContextBuilder beansRequireSomeProperties(boolean value) { 599 return set(BEAN_beansRequireSomeProperties, value); 600 } 601 602 /** 603 * Configuration property: Bean type property name. 604 * 605 * <p> 606 * This specifies the name of the bean property used to store the dictionary name of a bean type so that the 607 * parser knows the data type to reconstruct. 608 * 609 * <ul class='seealso'> 610 * <li class='jf'>{@link BeanContext#BEAN_beanTypePropertyName} 611 * </ul> 612 * 613 * @param value 614 * The new value for this property. 615 * <br>The default is <js>"_type"</js>. 616 * @return This object (for method chaining). 617 */ 618 public BeanContextBuilder beanTypePropertyName(String value) { 619 return set(BEAN_beanTypePropertyName, value); 620 } 621 622 /** 623 * Configuration property: Bean property includes. 624 * 625 * <p> 626 * Specifies the set and order of names of properties associated with the bean class. 627 * 628 * <ul class='seealso'> 629 * <li class='jf'>{@link BeanContext#BEAN_bpi} 630 * </ul> 631 * 632 * @param beanClass The bean class. 633 * @param value Comma-delimited list of property names. 634 * @return This object (for method chaining). 635 */ 636 public BeanContextBuilder bpi(Class<?> beanClass, String value) { 637 return addTo(BEAN_bpi, beanClass.getName(), value); 638 } 639 640 /** 641 * Configuration property: Bean property includes. 642 * 643 * <p> 644 * Specifies the set and order of names of properties associated with the bean class. 645 * 646 * <ul class='seealso'> 647 * <li class='jf'>{@link BeanContext#BEAN_bpi} 648 * </ul> 649 * 650 * @param values The new value for this property. 651 * @return This object (for method chaining). 652 */ 653 public BeanContextBuilder bpi(Map<String,String> values) { 654 return set(BEAN_bpi, values); 655 } 656 657 /** 658 * Configuration property: Bean property includes. 659 * 660 * <p> 661 * Specifies the set and order of names of properties associated with the bean class. 662 * 663 * <ul class='seealso'> 664 * <li class='jf'>{@link BeanContext#BEAN_bpi} 665 * </ul> 666 * 667 * @param beanClassName 668 * The bean class name. 669 * <br>Can be a simple name, fully-qualified name, or <js>"*"</js> for all beans. 670 * @param value Comma-delimited list of property names. 671 * @return This object (for method chaining). 672 */ 673 public BeanContextBuilder bpi(String beanClassName, String value) { 674 return addTo(BEAN_bpi, beanClassName, value); 675 } 676 677 /** 678 * Configuration property: Bean property excludes. 679 * 680 * <p> 681 * Specifies to exclude the specified list of properties for the specified bean class. 682 * 683 * <ul class='seealso'> 684 * <li class='jf'>{@link BeanContext#BEAN_bpx} 685 * </ul> 686 * 687 * @param beanClass The bean class. 688 * @param properties Comma-delimited list of property names. 689 * @return This object (for method chaining). 690 */ 691 public BeanContextBuilder bpx(Class<?> beanClass, String properties) { 692 return addTo(BEAN_bpx, beanClass.getName(), properties); 693 } 694 695 /** 696 * Configuration property: Bean property excludes. 697 * 698 * <p> 699 * Specifies to exclude the specified list of properties for the specified bean classes. 700 * 701 * <ul class='seealso'> 702 * <li class='jf'>{@link BeanContext#BEAN_bpx} 703 * </ul> 704 * 705 * @param values 706 * The new value for this property. 707 * @return This object (for method chaining). 708 */ 709 public BeanContextBuilder bpx(Map<String,String> values) { 710 return set(BEAN_bpx, values); 711 } 712 713 /** 714 * Configuration property: Bean property excludes. 715 * 716 * <ul class='seealso'> 717 * <li class='jf'>{@link BeanContext#BEAN_bpx} 718 * </ul> 719 * 720 * @param beanClassName 721 * The bean class name. 722 * <br>Can be a simple name, fully-qualified name, or <js>"*"</js> for all bean classes. 723 * @param value Comma-delimited list of property names. 724 * @return This object (for method chaining). 725 */ 726 public BeanContextBuilder bpx(String beanClassName, String value) { 727 return addTo(BEAN_bpx, beanClassName, value); 728 } 729 730 /** 731 * Configuration property: Read-only bean properties. 732 * 733 * <p> 734 * Specifies the read-only properties for the specified bean class. 735 * 736 * <ul class='seealso'> 737 * <li class='jf'>{@link BeanContext#BEAN_bpro} 738 * </ul> 739 * 740 * @param beanClass The bean class. 741 * @param properties Comma-delimited list of property names. 742 * @return This object (for method chaining). 743 */ 744 public BeanContextBuilder bpro(Class<?> beanClass, String properties) { 745 return addTo(BEAN_bpro, beanClass.getName(), properties); 746 } 747 748 /** 749 * Configuration property: Read-only bean properties. 750 * 751 * <p> 752 * Specifies the read-only properties for the specified bean classes. 753 * 754 * <ul class='seealso'> 755 * <li class='jf'>{@link BeanContext#BEAN_bpro} 756 * </ul> 757 * 758 * @param values 759 * The new value for this property. 760 * @return This object (for method chaining). 761 */ 762 public BeanContextBuilder bpro(Map<String,String> values) { 763 return set(BEAN_bpro, values); 764 } 765 766 /** 767 * Configuration property: Read-only bean properties. 768 * 769 * <p> 770 * Specifies the read-only properties for the specified bean class. 771 * 772 * <ul class='seealso'> 773 * <li class='jf'>{@link BeanContext#BEAN_bpro} 774 * </ul> 775 * 776 * @param beanClassName 777 * The bean class name. 778 * <br>Can be a simple name, fully-qualified name, or <js>"*"</js> for all bean classes. 779 * @param value Comma-delimited list of property names. 780 * @return This object (for method chaining). 781 */ 782 public BeanContextBuilder bpro(String beanClassName, String value) { 783 return addTo(BEAN_bpro, beanClassName, value); 784 } 785 786 /** 787 * Configuration property: Write-only bean properties. 788 * 789 * <p> 790 * Specifies the write-only properties for the specified bean class. 791 * 792 * <ul class='seealso'> 793 * <li class='jf'>{@link BeanContext#BEAN_bpwo} 794 * </ul> 795 * 796 * @param beanClass The bean class. 797 * @param properties Comma-delimited list of property names. 798 * @return This object (for method chaining). 799 */ 800 public BeanContextBuilder bpwo(Class<?> beanClass, String properties) { 801 return addTo(BEAN_bpwo, beanClass.getName(), properties); 802 } 803 804 /** 805 * Configuration property: Write-only bean properties. 806 * 807 * <p> 808 * Specifies the write-only properties for the specified bean classes. 809 * 810 * <ul class='seealso'> 811 * <li class='jf'>{@link BeanContext#BEAN_bpwo} 812 * </ul> 813 * 814 * @param values 815 * The new value for this property. 816 * @return This object (for method chaining). 817 */ 818 public BeanContextBuilder bpwo(Map<String,String> values) { 819 return set(BEAN_bpwo, values); 820 } 821 822 /** 823 * Configuration property: Write-only bean properties. 824 * 825 * <p> 826 * Specifies the write-only properties for the specified bean class. 827 * 828 * <ul class='seealso'> 829 * <li class='jf'>{@link BeanContext#BEAN_bpwo} 830 * </ul> 831 * 832 * @param beanClassName 833 * The bean class name. 834 * <br>Can be a simple name, fully-qualified name, or <js>"*"</js> for all bean classes. 835 * @param value Comma-delimited list of property names. 836 * @return This object (for method chaining). 837 */ 838 public BeanContextBuilder bpwo(String beanClassName, String value) { 839 return addTo(BEAN_bpwo, beanClassName, value); 840 } 841 842 /** 843 * Configuration property: Debug mode. 844 * 845 * <p> 846 * Enables the following additional information during serialization: 847 * <ul class='spaced-list'> 848 * <li> 849 * When bean getters throws exceptions, the exception includes the object stack information 850 * in order to determine how that method was invoked. 851 * <li> 852 * Enables {@link Serializer#BEANTRAVERSE_detectRecursions}. 853 * </ul> 854 * 855 * <ul class='seealso'> 856 * <li class='jf'>{@link BeanContext#BEAN_debug} 857 * </ul> 858 * 859 * @param value 860 * The new value for this property. 861 * <br>The default is <jk>false</jk>. 862 * @return This object (for method chaining). 863 */ 864 public BeanContextBuilder debug(boolean value) { 865 return set(BEAN_debug, value); 866 } 867 868 /** 869 * Configuration property: Bean dictionary. 870 * 871 * <p> 872 * Adds to the list of classes that make up the bean dictionary in this bean context. 873 * 874 * <ul class='seealso'> 875 * <li class='jf'>{@link BeanContext#BEAN_beanDictionary} 876 * </ul> 877 * 878 * @param values 879 * The values to add to this property. 880 * @return This object (for method chaining). 881 */ 882 public BeanContextBuilder dictionary(Object...values) { 883 return addTo(BEAN_beanDictionary, values); 884 } 885 886 /** 887 * Configuration property: Bean dictionary. 888 * 889 * <p> 890 * Same as {@link #beanDictionary(Object...)} but takes in an array of classes. 891 * 892 * <ul class='seealso'> 893 * <li class='jf'>{@link BeanContext#BEAN_beanDictionary} 894 * </ul> 895 * 896 * @param values 897 * The values to add to this property. 898 * @return This object (for method chaining). 899 */ 900 public BeanContextBuilder dictionary(Class<?>...values) { 901 return addTo(BEAN_beanDictionary, values); 902 } 903 904 /** 905 * Configuration property: Bean dictionary. 906 * 907 * <p> 908 * Same as {@link #beanDictionary(Object...)} but replaces the existing value. 909 * 910 * <ul class='seealso'> 911 * <li class='jf'>{@link BeanContext#BEAN_beanDictionary} 912 * </ul> 913 * 914 * @param values 915 * The new values for this property. 916 * @return This object (for method chaining). 917 */ 918 public BeanContextBuilder dictionaryReplace(Class<?>...values) { 919 return set(BEAN_beanDictionary, values); 920 } 921 922 /** 923 * Configuration property: Bean dictionary. 924 * 925 * <p> 926 * Same as {@link #beanDictionary(Object...)} but replaces the existing value. 927 * 928 * <ul class='seealso'> 929 * <li class='jf'>{@link BeanContext#BEAN_beanDictionary} 930 * </ul> 931 * 932 * @param values 933 * The new values for this property. 934 * @return This object (for method chaining). 935 */ 936 public BeanContextBuilder dictionaryReplace(Object...values) { 937 return set(BEAN_beanDictionary, values); 938 } 939 940 /** 941 * Configuration property: Bean dictionary. 942 * 943 * <p> 944 * Removes from the list of classes that make up the bean dictionary in this bean context. 945 * 946 * <ul class='seealso'> 947 * <li class='jf'>{@link BeanContext#BEAN_beanDictionary} 948 * </ul> 949 * 950 * @param values 951 * The values to remove from this property. 952 * @return This object (for method chaining). 953 */ 954 public BeanContextBuilder dictionaryRemove(Class<?>...values) { 955 return removeFrom(BEAN_beanDictionary, values); 956 } 957 958 /** 959 * Configuration property: Bean dictionary. 960 * 961 * <p> 962 * Removes from the list of classes that make up the bean dictionary in this bean context. 963 * 964 * <ul class='seealso'> 965 * <li class='jf'>{@link BeanContext#BEAN_beanDictionary} 966 * </ul> 967 * 968 * @param values 969 * The values to remove from this property. 970 * @return This object (for method chaining). 971 */ 972 public BeanContextBuilder dictionaryRemove(Object...values) { 973 return removeFrom(BEAN_beanDictionary, values); 974 } 975 976 /** 977 * Configuration property: Debug mode. 978 * 979 * <p> 980 * Shortcut for calling <code>debug(<jk>true</jk>)</code>. 981 * 982 * <ul class='seealso'> 983 * <li class='jf'>{@link BeanContext#BEAN_debug} 984 * </ul> 985 * 986 * @return This object (for method chaining). 987 */ 988 public BeanContextBuilder debug() { 989 return set(BEAN_debug, true); 990 } 991 992 /** 993 * Configuration property: POJO example. 994 * 995 * <p> 996 * Specifies an example of the specified class. 997 * 998 * <ul class='seealso'> 999 * <li class='jf'>{@link BeanContext#BEAN_examples} 1000 * </ul> 1001 * 1002 * @param pojoClass The POJO class. 1003 * @param o An instance of the POJO class used for examples. 1004 * @return This object (for method chaining). 1005 */ 1006 public <T> BeanContextBuilder example(Class<T> pojoClass, T o) { 1007 return addTo(BEAN_examples, pojoClass.getName(), o); 1008 } 1009 1010 /** 1011 * Configuration property: POJO example. 1012 * 1013 * <p> 1014 * Specifies an example of the specified class. 1015 * 1016 * <ul class='seealso'> 1017 * <li class='jf'>{@link BeanContext#BEAN_examples} 1018 * </ul> 1019 * 1020 * @param <T> The POJO class type. 1021 * @param pojoClass The POJO class. 1022 * @param json The simple JSON representation of the example. 1023 * @return This object (for method chaining). 1024 */ 1025 public <T> BeanContextBuilder exampleJson(Class<T> pojoClass, String json) { 1026 try { 1027 return addTo(BEAN_examples, pojoClass.getName(), SimpleJson.DEFAULT.read(json, pojoClass)); 1028 } catch (ParseException e) { 1029 throw new RuntimeException(e); 1030 } 1031 } 1032 1033 /** 1034 * Configuration property: POJO examples. 1035 * 1036 * <p> 1037 * Specifies an example of the specified class. 1038 * 1039 * <ul class='seealso'> 1040 * <li class='jf'>{@link BeanContext#BEAN_examples} 1041 * </ul> 1042 * 1043 * @param json The simple JSON representation of the example. 1044 * @return This object (for method chaining). 1045 * @throws ParseException If parameter is not valid Simple-JSON. 1046 */ 1047 public BeanContextBuilder examples(String json) throws ParseException { 1048 if (! isObjectMap(json, true)) 1049 json = "{" + json + "}"; 1050 ObjectMap m = new ObjectMap(json); 1051 for (Map.Entry<String,Object> e : m.entrySet()) 1052 addTo(BEAN_examples, e.getKey(), e.getValue()); 1053 return this; 1054 } 1055 1056 /** 1057 * Configuration property: Bean property excludes. 1058 * 1059 * @deprecated Use {@link #bpx(Class, String)} 1060 */ 1061 @SuppressWarnings("javadoc") 1062 @Deprecated public BeanContextBuilder excludeProperties(Class<?> beanClass, String properties) { 1063 return addTo(BEAN_bpx, beanClass.getName(), properties); 1064 } 1065 1066 /** 1067 * Configuration property: Bean property excludes. 1068 * 1069 * @deprecated Use {@link #bpx(Map)} 1070 */ 1071 @SuppressWarnings("javadoc") 1072 @Deprecated public BeanContextBuilder excludeProperties(Map<String,String> values) { 1073 return set(BEAN_bpx, values); 1074 } 1075 1076 /** 1077 * Configuration property: Bean property excludes. 1078 * 1079 * @deprecated Use {@link #bpx(String, String)} 1080 */ 1081 @SuppressWarnings("javadoc") 1082 @Deprecated public BeanContextBuilder excludeProperties(String beanClassName, String value) { 1083 return addTo(BEAN_bpx, beanClassName, value); 1084 } 1085 1086 /** 1087 * Configuration property: Find fluent setters. 1088 * 1089 * <p> 1090 * When enabled, fluent setters are detected on beans. 1091 * 1092 * <p> 1093 * Fluent setters must have the following attributes: 1094 * <ul> 1095 * <li>Public. 1096 * <li>Not static. 1097 * <li>Take in one parameter. 1098 * <li>Return the bean itself. 1099 * </ul> 1100 * 1101 * <ul class='seealso'> 1102 * <li class='jf'>{@link BeanContext#BEAN_fluentSetters} 1103 * </ul> 1104 * 1105 * @param value 1106 * The new value for this property. 1107 * <br>The default is <jk>false</jk>. 1108 * @return This object (for method chaining). 1109 */ 1110 public BeanContextBuilder fluentSetters(boolean value) { 1111 return set(BEAN_fluentSetters, value); 1112 } 1113 1114 /** 1115 * Configuration property: Find fluent setters. 1116 * 1117 * <p> 1118 * Shortcut for calling <code>fluentSetters(<jk>true</jk>)</code>. 1119 * 1120 * <ul class='seealso'> 1121 * <li class='jf'>{@link BeanContext#BEAN_fluentSetters} 1122 * </ul> 1123 * 1124 * @return This object (for method chaining). 1125 */ 1126 public BeanContextBuilder fluentSetters() { 1127 return set(BEAN_fluentSetters, true); 1128 } 1129 1130 /** 1131 * Configuration property: Ignore invocation errors on getters. 1132 * 1133 * <p> 1134 * If <jk>true</jk>, errors thrown when calling bean getter methods will silently be ignored. 1135 * Otherwise, a {@code BeanRuntimeException} is thrown. 1136 * 1137 * <ul class='seealso'> 1138 * <li class='jf'>{@link BeanContext#BEAN_ignoreInvocationExceptionsOnGetters} 1139 * </ul> 1140 * 1141 * @param value 1142 * The new value for this property. 1143 * <br>The default is <jk>false</jk>. 1144 * @return This object (for method chaining). 1145 */ 1146 public BeanContextBuilder ignoreInvocationExceptionsOnGetters(boolean value) { 1147 return set(BEAN_ignoreInvocationExceptionsOnGetters, value); 1148 } 1149 1150 /** 1151 * Configuration property: Ignore invocation errors on getters. 1152 * 1153 * <p> 1154 * Shortcut for calling <code>ignoreInvocationExceptionsOnGetters(<jk>true</jk>)</code>. 1155 * 1156 * <ul class='seealso'> 1157 * <li class='jf'>{@link BeanContext#BEAN_ignoreInvocationExceptionsOnGetters} 1158 * </ul> 1159 * 1160 * @return This object (for method chaining). 1161 */ 1162 public BeanContextBuilder ignoreInvocationExceptionsOnGetters() { 1163 return set(BEAN_ignoreInvocationExceptionsOnGetters, true); 1164 } 1165 1166 /** 1167 * Configuration property: Ignore invocation errors on setters. 1168 * 1169 * <p> 1170 * If <jk>true</jk>, errors thrown when calling bean setter methods will silently be ignored. 1171 * <br>Otherwise, a {@code BeanRuntimeException} is thrown. 1172 * 1173 * <ul class='seealso'> 1174 * <li class='jf'>{@link BeanContext#BEAN_ignoreInvocationExceptionsOnSetters} 1175 * </ul> 1176 * 1177 * @param value 1178 * The new value for this property. 1179 * <br>The default is <jk>false</jk>. 1180 * @return This object (for method chaining). 1181 */ 1182 public BeanContextBuilder ignoreInvocationExceptionsOnSetters(boolean value) { 1183 return set(BEAN_ignoreInvocationExceptionsOnSetters, value); 1184 } 1185 1186 /** 1187 * Configuration property: Ignore invocation errors on setters. 1188 * 1189 * <p> 1190 * Shortcut for calling <code>ignoreInvocationExceptionsOnSetters(<jk>true</jk>)</code>. 1191 * 1192 * <ul class='seealso'> 1193 * <li class='jf'>{@link BeanContext#BEAN_ignoreInvocationExceptionsOnSetters} 1194 * </ul> 1195 * 1196 * @return This object (for method chaining). 1197 */ 1198 public BeanContextBuilder ignoreInvocationExceptionsOnSetters() { 1199 return set(BEAN_ignoreInvocationExceptionsOnSetters, true); 1200 } 1201 1202 /** 1203 * Configuration property: Ignore properties without setters. 1204 * 1205 * <p> 1206 * If <jk>true</jk>, trying to set a value on a bean property without a setter will silently be ignored. 1207 * <br>Otherwise, a {@code BeanRuntimeException} is thrown. 1208 * 1209 * <ul class='seealso'> 1210 * <li class='jf'>{@link BeanContext#BEAN_ignorePropertiesWithoutSetters} 1211 * </ul> 1212 * 1213 * @param value 1214 * The new value for this property. 1215 * <br>The default is <jk>true</jk>. 1216 * @return This object (for method chaining). 1217 */ 1218 public BeanContextBuilder ignorePropertiesWithoutSetters(boolean value) { 1219 return set(BEAN_ignorePropertiesWithoutSetters, value); 1220 } 1221 1222 /** 1223 * Configuration property: Ignore unknown properties. 1224 * 1225 * <p> 1226 * If <jk>true</jk>, trying to set a value on a non-existent bean property will silently be ignored. 1227 * <br>Otherwise, a {@code BeanRuntimeException} is thrown. 1228 * 1229 * <ul class='seealso'> 1230 * <li class='jf'>{@link BeanContext#BEAN_ignoreUnknownBeanProperties} 1231 * </ul> 1232 * 1233 * @param value 1234 * The new value for this property. 1235 * <br>The default is <jk>false</jk>. 1236 * @return This object (for method chaining). 1237 */ 1238 public BeanContextBuilder ignoreUnknownBeanProperties(boolean value) { 1239 return set(BEAN_ignoreUnknownBeanProperties, value); 1240 } 1241 1242 /** 1243 * Configuration property: Ignore unknown properties. 1244 * 1245 * <p> 1246 * Shortcut for calling <code>ignoreUnknownBeanProperties(<jk>true</jk>)</code>. 1247 * 1248 * <ul class='seealso'> 1249 * <li class='jf'>{@link BeanContext#BEAN_ignoreUnknownBeanProperties} 1250 * </ul> 1251 * 1252 * @return This object (for method chaining). 1253 */ 1254 public BeanContextBuilder ignoreUnknownBeanProperties() { 1255 return set(BEAN_ignoreUnknownBeanProperties, true); 1256 } 1257 1258 /** 1259 * Configuration property: Ignore unknown properties with null values. 1260 * 1261 * <p> 1262 * If <jk>true</jk>, trying to set a <jk>null</jk> value on a non-existent bean property will silently be ignored. 1263 * <br>Otherwise, a {@code BeanRuntimeException} is thrown. 1264 * 1265 * <ul class='seealso'> 1266 * <li class='jf'>{@link BeanContext#BEAN_ignoreUnknownNullBeanProperties} 1267 * </ul> 1268 * 1269 * @param value 1270 * The new value for this property. 1271 * <br>The default is <jk>true</jk>. 1272 * @return This object (for method chaining). 1273 */ 1274 public BeanContextBuilder ignoreUnknownNullBeanProperties(boolean value) { 1275 return set(BEAN_ignoreUnknownNullBeanProperties, value); 1276 } 1277 1278 /** 1279 * Configuration property: Implementation classes. 1280 * 1281 * <ul class='seealso'> 1282 * <li class='jf'>{@link BeanContext#BEAN_implClasses} 1283 * </ul> 1284 * 1285 * @param interfaceClass The interface class. 1286 * @param implClass The implementation class. 1287 * @return This object (for method chaining). 1288 */ 1289 public BeanContextBuilder implClass(Class<?> interfaceClass, Class<?> implClass) { 1290 return addTo(BEAN_implClasses, interfaceClass.getName(), implClass); 1291 } 1292 1293 /** 1294 * Configuration property: Implementation classes. 1295 * 1296 * <p> 1297 * For interfaces and abstract classes this method can be used to specify an implementation class for the 1298 * interface/abstract class so that instances of the implementation class are used when instantiated (e.g. during a 1299 * parse). 1300 * 1301 * <ul class='seealso'> 1302 * <li class='jf'>{@link BeanContext#BEAN_implClasses} 1303 * </ul> 1304 * 1305 * @param values The new value for this property. 1306 * @return This object (for method chaining). 1307 */ 1308 public BeanContextBuilder implClasses(Map<String,Class<?>> values) { 1309 return set(BEAN_implClasses, values); 1310 } 1311 1312 /** 1313 * Configuration property: Bean property includes. 1314 * 1315 * @deprecated Use {@link #bpi(Class, String)} 1316 */ 1317 @SuppressWarnings("javadoc") 1318 @Deprecated public BeanContextBuilder includeProperties(Class<?> beanClass, String value) { 1319 return addTo(BEAN_bpi, beanClass.getName(), value); 1320 } 1321 1322 /** 1323 * Configuration property: Bean property includes. 1324 * 1325 * @deprecated Use {@link #bpi(Map)} 1326 */ 1327 @SuppressWarnings("javadoc") 1328 @Deprecated public BeanContextBuilder includeProperties(Map<String,String> values) { 1329 return set(BEAN_bpi, values); 1330 } 1331 1332 /** 1333 * Configuration property: Bean property includes. 1334 * 1335 * @deprecated Use {@link #bpi(String, String)} 1336 */ 1337 @SuppressWarnings("javadoc") 1338 @Deprecated public BeanContextBuilder includeProperties(String beanClassName, String value) { 1339 return addTo(BEAN_bpi, beanClassName, value); 1340 } 1341 1342 /** 1343 * Configuration property: Locale. 1344 * 1345 * <p> 1346 * Specifies a default locale for serializer and parser sessions. 1347 * 1348 * <ul class='seealso'> 1349 * <li class='jf'>{@link BeanContext#BEAN_locale} 1350 * </ul> 1351 * 1352 * @param value The new value for this property. 1353 * @return This object (for method chaining). 1354 */ 1355 public BeanContextBuilder locale(Locale value) { 1356 return set(BEAN_locale, value); 1357 } 1358 1359 /** 1360 * Configuration property: Media type. 1361 * 1362 * <p> 1363 * Specifies a default media type value for serializer and parser sessions. 1364 * 1365 * <ul class='seealso'> 1366 * <li class='jf'>{@link BeanContext#BEAN_mediaType} 1367 * </ul> 1368 * 1369 * @param value The new value for this property. 1370 * @return This object (for method chaining). 1371 */ 1372 public BeanContextBuilder mediaType(MediaType value) { 1373 return set(BEAN_mediaType, value); 1374 } 1375 1376 /** 1377 * Configuration property: Bean class exclusions. 1378 * 1379 * <p> 1380 * List of classes that should not be treated as beans even if they appear to be bean-like. 1381 * <br>Not-bean classes are converted to <c>Strings</c> during serialization. 1382 * 1383 * <ul class='seealso'> 1384 * <li class='jf'>{@link BeanContext#BEAN_notBeanClasses} 1385 * </ul> 1386 * 1387 * @param values The values to add to this property. 1388 * @return This object (for method chaining). 1389 */ 1390 public BeanContextBuilder notBeanClasses(Class<?>...values) { 1391 return addTo(BEAN_notBeanClasses, values); 1392 } 1393 1394 /** 1395 * Configuration property: Bean class exclusions. 1396 * 1397 * <p> 1398 * List of classes that should not be treated as beans even if they appear to be bean-like. 1399 * <br>Not-bean classes are converted to <c>Strings</c> during serialization. 1400 * 1401 * <ul class='seealso'> 1402 * <li class='jf'>{@link BeanContext#BEAN_notBeanClasses} 1403 * </ul> 1404 * 1405 * @param values 1406 * The values to add to this property. 1407 * <br>Values can consist of any of the following types: 1408 * <ul> 1409 * <li>Classes. 1410 * <li>Arrays and collections of classes. 1411 * </ul> 1412 * @return This object (for method chaining). 1413 */ 1414 public BeanContextBuilder notBeanClasses(Object...values) { 1415 return addTo(BEAN_notBeanClasses, values); 1416 } 1417 1418 /** 1419 * Configuration property: Bean class exclusions. 1420 * 1421 * <p> 1422 * Not-bean classes are converted to <c>Strings</c> during serialization even if they appear to be 1423 * bean-like. 1424 * 1425 * <ul class='seealso'> 1426 * <li class='jf'>{@link BeanContext#BEAN_notBeanClasses} 1427 * </ul> 1428 * 1429 * @param values 1430 * The new value for this property. 1431 * @return This object (for method chaining). 1432 */ 1433 public BeanContextBuilder notBeanClassesReplace(Class<?>...values) { 1434 return set(BEAN_notBeanClasses, values); 1435 } 1436 1437 /** 1438 * Configuration property: Bean class exclusions. 1439 * 1440 * <p> 1441 * Not-bean classes are converted to <c>Strings</c> during serialization even if they appear to be 1442 * bean-like. 1443 * 1444 * <ul class='seealso'> 1445 * <li class='jf'>{@link BeanContext#BEAN_notBeanClasses} 1446 * </ul> 1447 * 1448 * @param values 1449 * The new value for this property. 1450 * <br>Values can consist of any of the following types: 1451 * <ul> 1452 * <li>Classes. 1453 * <li>Arrays and collections of classes. 1454 * </ul> 1455 * @return This object (for method chaining). 1456 */ 1457 public BeanContextBuilder notBeanClassesReplace(Object...values) { 1458 return set(BEAN_notBeanClasses, values); 1459 } 1460 1461 /** 1462 * Configuration property: Bean class exclusions. 1463 * 1464 * <ul class='seealso'> 1465 * <li class='jf'>{@link BeanContext#BEAN_notBeanClasses} 1466 * </ul> 1467 * 1468 * @param values 1469 * The values to remove from this property. 1470 * @return This object (for method chaining). 1471 */ 1472 public BeanContextBuilder notBeanClassesRemove(Class<?>...values) { 1473 return removeFrom(BEAN_notBeanClasses, values); 1474 } 1475 1476 /** 1477 * Configuration property: Bean class exclusions. 1478 * 1479 * <ul class='seealso'> 1480 * <li class='jf'>{@link BeanContext#BEAN_notBeanClasses} 1481 * </ul> 1482 * 1483 * @param values 1484 * The values to remove from this property. 1485 * <br>Values can consist of any of the following types: 1486 * <ul> 1487 * <li>Classes. 1488 * <li>Arrays and collections of classes. 1489 * </ul> 1490 * @return This object (for method chaining). 1491 */ 1492 public BeanContextBuilder notBeanClassesRemove(Object...values) { 1493 return removeFrom(BEAN_notBeanClasses, values); 1494 } 1495 1496 /** 1497 * Configuration property: Bean package exclusions. 1498 * 1499 * <ul class='seealso'> 1500 * <li class='jf'>{@link BeanContext#BEAN_notBeanPackages} 1501 * </ul> 1502 * 1503 * @param values 1504 * The values to add to this property. 1505 * @return This object (for method chaining). 1506 */ 1507 public BeanContextBuilder notBeanPackages(String...values) { 1508 return addTo(BEAN_notBeanPackages, values); 1509 } 1510 1511 /** 1512 * Configuration property: Bean package exclusions. 1513 * 1514 * <ul class='seealso'> 1515 * <li class='jf'>{@link BeanContext#BEAN_notBeanPackages} 1516 * </ul> 1517 * 1518 * @param values 1519 * The values to add to this property. 1520 * <br>Values can consist of any of the following types: 1521 * <ul> 1522 * <li>Strings. 1523 * <li>Arrays and collections of strings. 1524 * </ul> 1525 * @return This object (for method chaining). 1526 */ 1527 public BeanContextBuilder notBeanPackages(Object...values) { 1528 return addTo(BEAN_notBeanPackages, values); 1529 } 1530 1531 /** 1532 * Configuration property: Bean package exclusions. 1533 * 1534 * <ul class='seealso'> 1535 * <li class='jf'>{@link BeanContext#BEAN_notBeanPackages} 1536 * </ul> 1537 * 1538 * @param values 1539 * <br>Values can consist of any of the following types: 1540 * @return This object (for method chaining). 1541 */ 1542 public BeanContextBuilder notBeanPackagesReplace(String...values) { 1543 return set(BEAN_notBeanPackages, values); 1544 } 1545 1546 /** 1547 * Configuration property: Bean package exclusions. 1548 * 1549 * <ul class='seealso'> 1550 * <li class='jf'>{@link BeanContext#BEAN_notBeanPackages} 1551 * </ul> 1552 * 1553 * @param values 1554 * <br>Values can consist of any of the following types: 1555 * <br>Possible values are: 1556 * <ul> 1557 * <li>Strings. 1558 * <li>Arrays and collections of strings. 1559 * </ul> 1560 * @return This object (for method chaining). 1561 */ 1562 public BeanContextBuilder notBeanPackagesReplace(Object...values) { 1563 return set(BEAN_notBeanPackages, values); 1564 } 1565 1566 /** 1567 * Configuration property: Bean package exclusions. 1568 * 1569 * <ul class='seealso'> 1570 * <li class='jf'>{@link BeanContext#BEAN_notBeanPackages} 1571 * </ul> 1572 * 1573 * @param values The values to remove from this property. 1574 * @return This object (for method chaining). 1575 */ 1576 public BeanContextBuilder notBeanPackagesRemove(String...values) { 1577 return removeFrom(BEAN_notBeanPackages, values); 1578 } 1579 1580 /** 1581 * Configuration property: Bean package exclusions. 1582 * 1583 * <ul class='seealso'> 1584 * <li class='jf'>{@link BeanContext#BEAN_notBeanPackages} 1585 * </ul> 1586 * 1587 * @param values 1588 * <br>Values can consist of any of the following types: 1589 * <br>Possible values are: 1590 * <ul> 1591 * <li>Strings. 1592 * <li>Arrays and collections of strings. 1593 * </ul> 1594 * @return This object (for method chaining). 1595 */ 1596 public BeanContextBuilder notBeanPackagesRemove(Object...values) { 1597 return removeFrom(BEAN_notBeanPackages, values); 1598 } 1599 1600 /** 1601 * Configuration property: POJO swaps. 1602 * 1603 * <ul class='seealso'> 1604 * <li class='jf'>{@link BeanContext#BEAN_pojoSwaps} 1605 * </ul> 1606 * 1607 * @param values The values to add to this property. 1608 * @return This object (for method chaining). 1609 */ 1610 public BeanContextBuilder pojoSwaps(Class<?>...values) { 1611 return addTo(BEAN_pojoSwaps, values); 1612 } 1613 1614 /** 1615 * Configuration property: POJO swaps. 1616 * 1617 * <ul class='seealso'> 1618 * <li class='jf'>{@link BeanContext#BEAN_pojoSwaps} 1619 * </ul> 1620 * 1621 * @param values 1622 * The values to add to this property. 1623 * <br>Values can consist of any of the following types: 1624 * <ul> 1625 * <li>Any subclass of {@link PojoSwap}. 1626 * <li>Any surrogate class. A shortcut for defining a {@link SurrogateSwap}. 1627 * <li>Any array or collection of the objects above. 1628 * </ul> 1629 * @return This object (for method chaining). 1630 */ 1631 public BeanContextBuilder pojoSwaps(Object...values) { 1632 return addTo(BEAN_pojoSwaps, values); 1633 } 1634 1635 /** 1636 * Configuration property: POJO swaps. 1637 * 1638 * <ul class='seealso'> 1639 * <li class='jf'>{@link BeanContext#BEAN_pojoSwaps} 1640 * </ul> 1641 * 1642 * @param values 1643 * The values to remove from this property. 1644 * <br>Values can consist of any of the following types: 1645 * <ul> 1646 * <li>Any subclass of {@link PojoSwap}. 1647 * <li>Any surrogate class. A shortcut for defining a {@link SurrogateSwap}. 1648 * <li>Any array or collection of the objects above. 1649 * </ul> 1650 * @return This object (for method chaining). 1651 */ 1652 public BeanContextBuilder pojoSwapsReplace(Class<?>...values) { 1653 return set(BEAN_pojoSwaps, values); 1654 } 1655 1656 /** 1657 * Configuration property: POJO swaps. 1658 * 1659 * <ul class='seealso'> 1660 * <li class='jf'>{@link BeanContext#BEAN_pojoSwaps} 1661 * </ul> 1662 * 1663 * @param values 1664 * The values to remove from this property. 1665 * <br>Values can consist of any of the following types: 1666 * <ul> 1667 * <li>Any subclass of {@link PojoSwap}. 1668 * <li>Any surrogate class. A shortcut for defining a {@link SurrogateSwap}. 1669 * <li>Any array or collection of the objects above. 1670 * </ul> 1671 * @return This object (for method chaining). 1672 */ 1673 public BeanContextBuilder pojoSwapsReplace(Object...values) { 1674 return set(BEAN_pojoSwaps, values); 1675 } 1676 1677 /** 1678 * Configuration property: POJO swaps. 1679 * 1680 * <ul class='seealso'> 1681 * <li class='jf'>{@link BeanContext#BEAN_pojoSwaps} 1682 * </ul> 1683 * 1684 * @param values 1685 * The values to remove from this property. 1686 * <br>Values can consist of any of the following types: 1687 * <ul> 1688 * <li>Any subclass of {@link PojoSwap}. 1689 * <li>Any surrogate class. A shortcut for defining a {@link SurrogateSwap}. 1690 * </ul> 1691 * @return This object (for method chaining). 1692 */ 1693 public BeanContextBuilder pojoSwapsRemove(Class<?>...values) { 1694 return removeFrom(BEAN_pojoSwaps, values); 1695 } 1696 1697 /** 1698 * Configuration property: POJO swaps. 1699 * 1700 * <ul class='seealso'> 1701 * <li class='jf'>{@link BeanContext#BEAN_pojoSwaps} 1702 * </ul> 1703 * 1704 * @param values 1705 * The values to remove from this property. 1706 * <br>Values can consist of any of the following types: 1707 * <ul> 1708 * <li>Any subclass of {@link PojoSwap}. 1709 * <li>Any surrogate class. A shortcut for defining a {@link SurrogateSwap}. 1710 * <li>Any array or collection of the objects above. 1711 * </ul> 1712 * @return This object (for method chaining). 1713 */ 1714 public BeanContextBuilder pojoSwapsRemove(Object...values) { 1715 return removeFrom(BEAN_pojoSwaps, values); 1716 } 1717 1718 /** 1719 * Configuration property: Bean property namer 1720 * 1721 * <p> 1722 * The class to use for calculating bean property names. 1723 * 1724 * <ul class='seealso'> 1725 * <li class='jf'>{@link BeanContext#BEAN_propertyNamer} 1726 * </ul> 1727 * 1728 * @param value 1729 * The new value for this setting. 1730 * <br>The default is {@link PropertyNamerDefault}. 1731 * @return This object (for method chaining). 1732 */ 1733 public BeanContextBuilder propertyNamer(Class<? extends PropertyNamer> value) { 1734 return set(BEAN_propertyNamer, value); 1735 } 1736 1737 /** 1738 * Configuration property: Sort bean properties. 1739 * 1740 * <p> 1741 * When <jk>true</jk>, all bean properties will be serialized and access in alphabetical order. 1742 * Otherwise, the natural order of the bean properties is used which is dependent on the JVM vendor. 1743 * 1744 * <ul class='seealso'> 1745 * <li class='jf'>{@link BeanContext#BEAN_sortProperties} 1746 * </ul> 1747 * 1748 * @param value 1749 * The new value for this property. 1750 * <br>The default is <jk>false</jk>. 1751 * @return This object (for method chaining). 1752 */ 1753 public BeanContextBuilder sortProperties(boolean value) { 1754 return set(BEAN_sortProperties, value); 1755 } 1756 1757 /** 1758 * Configuration property: Sort bean properties. 1759 * 1760 * <p> 1761 * Shortcut for calling <code>sortProperties(<jk>true</jk>)</code>. 1762 * 1763 * <ul class='seealso'> 1764 * <li class='jf'>{@link BeanContext#BEAN_sortProperties} 1765 * </ul> 1766 * 1767 * @return This object (for method chaining). 1768 */ 1769 public BeanContextBuilder sortProperties() { 1770 return set(BEAN_sortProperties, true); 1771 } 1772 1773 /** 1774 * Configuration property: TimeZone. 1775 * 1776 * <ul class='seealso'> 1777 * <li class='jf'>{@link BeanContext#BEAN_timeZone} 1778 * </ul> 1779 * 1780 * @param value The new value for this property. 1781 * @return This object (for method chaining). 1782 */ 1783 public BeanContextBuilder timeZone(TimeZone value) { 1784 return set(BEAN_timeZone, value); 1785 } 1786 1787 /** 1788 * Configuration property: Use enum names. 1789 * 1790 * <p> 1791 * When enabled, enums are always serialized by name instead of using {@link Object#toString()}. 1792 * 1793 * <ul class='seealso'> 1794 * <li class='jf'>{@link BeanContext#BEAN_useEnumNames} 1795 * </ul> 1796 * 1797 * @param value The property value. 1798 * @return This object (for method chaining). 1799 */ 1800 public BeanContextBuilder useEnumNames(boolean value) { 1801 return set(BEAN_useEnumNames, value); 1802 } 1803 1804 /** 1805 * Configuration property: Use enum names. 1806 * 1807 * <p> 1808 * When enabled, enums are always serialized by name instead of using {@link Object#toString()}. 1809 * 1810 * <ul class='seealso'> 1811 * <li class='jf'>{@link BeanContext#BEAN_useEnumNames} 1812 * </ul> 1813 * 1814 * @return This object (for method chaining). 1815 */ 1816 public BeanContextBuilder useEnumNames() { 1817 return set(BEAN_useEnumNames, true); 1818 } 1819 1820 /** 1821 * Configuration property: Use interface proxies. 1822 * 1823 * <p> 1824 * If <jk>true</jk>, then interfaces will be instantiated as proxy classes through the use of an 1825 * {@link InvocationHandler} if there is no other way of instantiating them. 1826 * 1827 * <ul class='seealso'> 1828 * <li class='jf'>{@link BeanContext#BEAN_useInterfaceProxies} 1829 * </ul> 1830 * 1831 * @param value 1832 * The new value for this property. 1833 * <br>The default is <jk>true</jk>. 1834 * @return This object (for method chaining). 1835 */ 1836 public BeanContextBuilder useInterfaceProxies(boolean value) { 1837 return set(BEAN_useInterfaceProxies, value); 1838 } 1839 1840 /** 1841 * Configuration property: Use Java Introspector. 1842 * 1843 * <p> 1844 * Using the built-in Java bean introspector will not pick up fields or non-standard getters/setters. 1845 * 1846 * <ul class='notes'> 1847 * <li>Most {@link Bean @Bean} annotations will be ignored if you enable this setting. 1848 * </ul> 1849 * 1850 * <ul class='seealso'> 1851 * <li class='jf'>{@link BeanContext#BEAN_useJavaBeanIntrospector} 1852 * </ul> 1853 * 1854 * @param value 1855 * The new value for this property. 1856 * <br>The default is <jk>false</jk>. 1857 * @return This object (for method chaining). 1858 */ 1859 public BeanContextBuilder useJavaBeanIntrospector(boolean value) { 1860 return set(BEAN_useJavaBeanIntrospector, value); 1861 } 1862 1863 /** 1864 * Configuration property: Use Java Introspector. 1865 * 1866 * <p> 1867 * Shortcut for calling <code>useJavaBeanIntrospector(<jk>true</jk>)</code>. 1868 * 1869 * <ul class='seealso'> 1870 * <li class='jf'>{@link BeanContext#BEAN_useJavaBeanIntrospector} 1871 * </ul> 1872 * 1873 * @return This object (for method chaining). 1874 */ 1875 public BeanContextBuilder useJavaBeanIntrospector() { 1876 return set(BEAN_useJavaBeanIntrospector, true); 1877 } 1878 1879 @Override /* ContextBuilder */ 1880 public BeanContextBuilder set(String name, Object value) { 1881 super.set(name, value); 1882 return this; 1883 } 1884 1885 @Override /* ContextBuilder */ 1886 public BeanContextBuilder set(Map<String,Object> properties) { 1887 super.set(properties); 1888 return this; 1889 } 1890 1891 @Override /* ContextBuilder */ 1892 public BeanContextBuilder add(Map<String,Object> properties) { 1893 super.add(properties); 1894 return this; 1895 } 1896 1897 @Override /* ContextBuilder */ 1898 public BeanContextBuilder addTo(String name, Object value) { 1899 super.addTo(name, value); 1900 return this; 1901 } 1902 1903 @Override /* ContextBuilder */ 1904 public BeanContextBuilder addTo(String name, String key, Object value) { 1905 super.addTo(name, key, value); 1906 return this; 1907 } 1908 1909 @Override /* ContextBuilder */ 1910 public BeanContextBuilder removeFrom(String name, Object value) { 1911 super.removeFrom(name, value); 1912 return this; 1913 } 1914 1915 @Override /* ContextBuilder */ 1916 public BeanContextBuilder apply(PropertyStore copyFrom) { 1917 super.apply(copyFrom); 1918 return this; 1919 } 1920 1921 @Override /* ContextBuilder */ 1922 public BeanContextBuilder applyAnnotations(AnnotationList al, VarResolverSession vrs) { 1923 super.applyAnnotations(al, vrs); 1924 return this; 1925 } 1926 1927 @Override /* ContextBuilder */ 1928 public BeanContextBuilder applyAnnotations(Class<?> fromClass) { 1929 super.applyAnnotations(fromClass); 1930 return this; 1931 } 1932 1933 @Override /* ContextBuilder */ 1934 public BeanContextBuilder applyAnnotations(Method fromMethod) { 1935 super.applyAnnotations(fromMethod); 1936 return this; 1937 } 1938}