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 */ 150 public BeanContextBuilder beanDictionary(Object...values) { 151 return addTo(BEAN_beanDictionary, values); 152 } 153 154 /** 155 * Configuration property: Bean dictionary. 156 * 157 * <p> 158 * Same as {@link #beanDictionary(Object...)} but takes in an array of classes. 159 * 160 * <ul class='seealso'> 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 replaces the existing value. 177 * 178 * <ul class='seealso'> 179 * <li class='jf'>{@link BeanContext#BEAN_beanDictionary} 180 * </ul> 181 * 182 * @param values 183 * The new values for this property. 184 * @return This object (for method chaining). 185 */ 186 public BeanContextBuilder beanDictionaryReplace(Class<?>...values) { 187 return set(BEAN_beanDictionary, values); 188 } 189 190 /** 191 * Configuration property: Bean dictionary. 192 * 193 * <p> 194 * Same as {@link #beanDictionary(Object...)} but replaces the existing value. 195 * 196 * <ul class='seealso'> 197 * <li class='jf'>{@link BeanContext#BEAN_beanDictionary} 198 * </ul> 199 * 200 * @param values 201 * The new values for this property. 202 * @return This object (for method chaining). 203 */ 204 public BeanContextBuilder beanDictionaryReplace(Object...values) { 205 return set(BEAN_beanDictionary, values); 206 } 207 208 /** 209 * Configuration property: Bean dictionary. 210 * 211 * <p> 212 * Removes from the list of classes that make up the bean dictionary in this bean context. 213 * 214 * <ul class='seealso'> 215 * <li class='jf'>{@link BeanContext#BEAN_beanDictionary} 216 * </ul> 217 * 218 * @param values 219 * The values to remove from this property. 220 * @return This object (for method chaining). 221 */ 222 public BeanContextBuilder beanDictionaryRemove(Class<?>...values) { 223 return removeFrom(BEAN_beanDictionary, values); 224 } 225 226 /** 227 * Configuration property: Bean dictionary. 228 * 229 * <p> 230 * Removes from the list of classes that make up the bean dictionary in this bean context. 231 * 232 * <ul class='seealso'> 233 * <li class='jf'>{@link BeanContext#BEAN_beanDictionary} 234 * </ul> 235 * 236 * @param values 237 * The values to remove from this property. 238 * @return This object (for method chaining). 239 */ 240 public BeanContextBuilder beanDictionaryRemove(Object...values) { 241 return removeFrom(BEAN_beanDictionary, values); 242 } 243 244 /** 245 * Configuration property: Minimum bean field visibility. 246 * 247 * <p> 248 * Only look for bean fields with the specified minimum visibility. 249 * 250 * <ul class='seealso'> 251 * <li class='jf'>{@link BeanContext#BEAN_beanFieldVisibility} 252 * </ul> 253 * 254 * @param value 255 * The new value for this property. 256 * <br>The default is {@link Visibility#PUBLIC}. 257 * @return This object (for method chaining). 258 */ 259 public BeanContextBuilder beanFieldVisibility(Visibility value) { 260 return set(BEAN_beanFieldVisibility, value); 261 } 262 263 /** 264 * Configuration property: Bean filters. 265 * 266 * <p> 267 * This is a programmatic equivalent to the {@link Bean @Bean} annotation. 268 * <br>It's useful when you want to use the Bean annotation functionality, but you don't have the ability to alter 269 * the bean classes. 270 * 271 * <ul class='seealso'> 272 * <li class='jf'>{@link BeanContext#BEAN_beanFilters} 273 * </ul> 274 * 275 * @param values 276 * The values to add to this property. 277 * <br>Values can consist of any of the following types: 278 * <ul> 279 * <li>Any bean class that specifies a value for {@link Bean#typeName() @Bean(typeName)}. 280 * <li>Any subclass of {@link BeanDictionaryList} containing a collection of bean classes with type name annotations. 281 * <li>Any subclass of {@link BeanDictionaryMap} containing a mapping of type names to classes without type name annotations. 282 * <li>Any array or collection of the objects above. 283 * </ul> 284 * @return This object (for method chaining). 285 */ 286 public BeanContextBuilder beanFilters(Object...values) { 287 return addTo(BEAN_beanFilters, values); 288 } 289 290 /** 291 * Configuration property: Bean filters. 292 * 293 * <p> 294 * Same as {@link #beanFilters(Object...)} but takes in an array of classes. 295 * 296 * <ul class='seealso'> 297 * <li class='jf'>{@link BeanContext#BEAN_beanFilters} 298 * </ul> 299 * 300 * @param values 301 * The values to add to this property. 302 * @return This object (for method chaining). 303 */ 304 public BeanContextBuilder beanFilters(Class<?>...values) { 305 return addTo(BEAN_beanFilters, values); 306 } 307 308 /** 309 * Configuration property: Bean filters. 310 * 311 * <p> 312 * Same as {@link #beanFilters(Object...)} but replaces the existing values. 313 * 314 * <ul class='seealso'> 315 * <li class='jf'>{@link BeanContext#BEAN_beanFilters} 316 * </ul> 317 * 318 * @param values 319 * The new values for 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 * </ul> 326 * @return This object (for method chaining). 327 */ 328 public BeanContextBuilder beanFiltersReplace(Class<?>...values) { 329 return set(BEAN_beanFilters, values); 330 } 331 332 /** 333 * Configuration property: Bean filters. 334 * 335 * <p> 336 * Same as {@link #beanFilters(Object...)} but replaces the existing values. 337 * 338 * <ul class='seealso'> 339 * <li class='jf'>{@link BeanContext#BEAN_beanFilters} 340 * </ul> 341 * 342 * @param values 343 * The new values for this property. 344 * <br>Values can consist of any of the following types: 345 * <ul> 346 * <li>Any bean class that specifies a value for {@link Bean#typeName() @Bean(typeName)}. 347 * <li>Any subclass of {@link BeanDictionaryList} containing a collection of bean classes with type name annotations. 348 * <li>Any subclass of {@link BeanDictionaryMap} containing a mapping of type names to classes without type name annotations. 349 * <li>Any array or collection of the objects above. 350 * </ul> 351 * @return This object (for method chaining). 352 */ 353 public BeanContextBuilder beanFiltersReplace(Object...values) { 354 return set(BEAN_beanFilters, values); 355 } 356 357 /** 358 * Configuration property: Bean filters. 359 * 360 * <p> 361 * Removes from the list of classes that make up the bean filters in this bean context. 362 * 363 * <ul class='seealso'> 364 * <li class='jf'>{@link BeanContext#BEAN_beanFilters} 365 * </ul> 366 * 367 * @param values 368 * The values to remove from this property. 369 * <br>Values can consist of any of the following types: 370 * <ul> 371 * <li>Any bean class that specifies a value for {@link Bean#typeName() @Bean(typeName)}. 372 * <li>Any subclass of {@link BeanDictionaryList} containing a collection of bean classes with type name annotations. 373 * <li>Any subclass of {@link BeanDictionaryMap} containing a mapping of type names to classes without type name annotations. 374 * </ul> 375 * @return This object (for method chaining). 376 */ 377 public BeanContextBuilder beanFiltersRemove(Class<?>...values) { 378 return removeFrom(BEAN_beanFilters, values); 379 } 380 381 /** 382 * Configuration property: Bean filters. 383 * 384 * <p> 385 * Removes from the list of classes that make up the bean filters in this bean context. 386 * 387 * <ul class='seealso'> 388 * <li class='jf'>{@link BeanContext#BEAN_beanFilters} 389 * </ul> 390 * 391 * @param values 392 * The values to remove from this property. 393 * <br>Values can consist of any of the following types: 394 * <ul> 395 * <li>Any bean class that specifies a value for {@link Bean#typeName() @Bean(typeName)}. 396 * <li>Any subclass of {@link BeanDictionaryList} containing a collection of bean classes with type name annotations. 397 * <li>Any subclass of {@link BeanDictionaryMap} containing a mapping of type names to classes without type name annotations. 398 * <li>Any array or collection of the objects above. 399 * </ul> 400 * @return This object (for method chaining). 401 */ 402 public BeanContextBuilder beanFiltersRemove(Object...values) { 403 return removeFrom(BEAN_beanFilters, values); 404 } 405 406 /** 407 * Configuration property: BeanMap.put() returns old property value. 408 * 409 * <p> 410 * If <jk>true</jk>, then the {@link BeanMap#put(String,Object) BeanMap.put()} method will return old property 411 * values. 412 * <br>Otherwise, it returns <jk>null</jk>. 413 * 414 * <ul class='seealso'> 415 * <li class='jf'>{@link BeanContext#BEAN_beanMapPutReturnsOldValue} 416 * </ul> 417 * 418 * @param value 419 * The new value for this property. 420 * <br>The default is <jk>false</jk>. 421 * @return This object (for method chaining). 422 */ 423 public BeanContextBuilder beanMapPutReturnsOldValue(boolean value) { 424 return set(BEAN_beanMapPutReturnsOldValue, value); 425 } 426 427 /** 428 * Configuration property: BeanMap.put() returns old property value. 429 * 430 * <p> 431 * Shortcut for calling <code>beanMapPutReturnsOldValue(<jk>true</jk>)</code>. 432 * 433 * <ul class='seealso'> 434 * <li class='jf'>{@link BeanContext#BEAN_beanMapPutReturnsOldValue} 435 * </ul> 436 * 437 * @return This object (for method chaining). 438 */ 439 public BeanContextBuilder beanMapPutReturnsOldValue() { 440 return set(BEAN_beanMapPutReturnsOldValue, true); 441 } 442 443 /** 444 * Configuration property: Minimum bean method visibility. 445 * 446 * <p> 447 * Only look for bean methods with the specified minimum visibility. 448 * 449 * <ul class='seealso'> 450 * <li class='jf'>{@link BeanContext#BEAN_beanMethodVisibility} 451 * </ul> 452 * 453 * @param value 454 * The new value for this property. 455 * <br>The default is {@link Visibility#PUBLIC} 456 * @return This object (for method chaining). 457 */ 458 public BeanContextBuilder beanMethodVisibility(Visibility value) { 459 return set(BEAN_beanMethodVisibility, value); 460 } 461 462 /** 463 * Configuration property: Beans require no-arg constructors. 464 * 465 * <p> 466 * If <jk>true</jk>, a Java class must implement a default no-arg constructor to be considered a bean. 467 * <br>Otherwise, the bean will be serialized as a string using the {@link Object#toString()} method. 468 * 469 * <ul class='seealso'> 470 * <li class='jf'>{@link BeanContext#BEAN_beansRequireDefaultConstructor} 471 * </ul> 472 * 473 * @param value 474 * The new value for this property. 475 * <br>The default is <jk>false</jk>. 476 * @return This object (for method chaining). 477 */ 478 public BeanContextBuilder beansRequireDefaultConstructor(boolean value) { 479 return set(BEAN_beansRequireDefaultConstructor, value); 480 } 481 482 /** 483 * Configuration property: Beans require no-arg constructors. 484 * 485 * <p> 486 * Shortcut for calling <code>beansRequireDefaultConstructor(<jk>true</jk>)</code>. 487 * 488 * <ul class='seealso'> 489 * <li class='jf'>{@link BeanContext#BEAN_beansRequireDefaultConstructor} 490 * </ul> 491 * 492 * @return This object (for method chaining). 493 */ 494 public BeanContextBuilder beansRequireDefaultConstructor() { 495 return set(BEAN_beansRequireDefaultConstructor, true); 496 } 497 498 /** 499 * Configuration property: Beans require Serializable interface. 500 * 501 * <p> 502 * If <jk>true</jk>, a Java class must implement the {@link Serializable} interface to be considered a bean. 503 * <br>Otherwise, the bean will be serialized as a string using the {@link Object#toString()} method. 504 * 505 * <ul class='seealso'> 506 * <li class='jf'>{@link BeanContext#BEAN_beansRequireSerializable} 507 * </ul> 508 * 509 * @param value 510 * The new value for this property. 511 * <br>The default is <jk>false</jk>. 512 * @return This object (for method chaining). 513 */ 514 public BeanContextBuilder beansRequireSerializable(boolean value) { 515 return set(BEAN_beansRequireSerializable, value); 516 } 517 518 /** 519 * Configuration property: Beans require Serializable interface. 520 * 521 * <p> 522 * Shortcut for calling <code>beansRequireSerializable(<jk>true</jk>)</code>. 523 * 524 * <ul class='seealso'> 525 * <li class='jf'>{@link BeanContext#BEAN_beansRequireSerializable} 526 * </ul> 527 * 528 * @return This object (for method chaining). 529 */ 530 public BeanContextBuilder beansRequireSerializable() { 531 return set(BEAN_beansRequireSerializable, true); 532 } 533 534 /** 535 * Configuration property: Beans require setters for getters. 536 * 537 * <p> 538 * If <jk>true</jk>, only getters that have equivalent setters will be considered as properties on a bean. 539 * <br>Otherwise, they will be ignored. 540 * 541 * <ul class='seealso'> 542 * <li class='jf'>{@link BeanContext#BEAN_beansRequireSettersForGetters} 543 * </ul> 544 * 545 * @param value 546 * The new value for this property. 547 * <br>The default is <jk>false</jk>. 548 * @return This object (for method chaining). 549 */ 550 public BeanContextBuilder beansRequireSettersForGetters(boolean value) { 551 return set(BEAN_beansRequireSettersForGetters, value); 552 } 553 554 /** 555 * Configuration property: Beans require setters for getters. 556 * 557 * <p> 558 * Shortcut for calling <code>beansRequireSettersForGetters(<jk>true</jk>)</code>. 559 * 560 * <ul class='seealso'> 561 * <li class='jf'>{@link BeanContext#BEAN_beansRequireSettersForGetters} 562 * </ul> 563 * 564 * @return This object (for method chaining). 565 */ 566 public BeanContextBuilder beansRequireSettersForGetters() { 567 return set(BEAN_beansRequireSettersForGetters, true); 568 } 569 570 /** 571 * Configuration property: Beans require at least one property. 572 * 573 * <p> 574 * If <jk>true</jk>, then a Java class must contain at least 1 property to be considered a bean. 575 * <br>Otherwise, the bean will be serialized as a string using the {@link Object#toString()} method. 576 * 577 * <ul class='seealso'> 578 * <li class='jf'>{@link BeanContext#BEAN_beansRequireSomeProperties} 579 * </ul> 580 * 581 * @param value 582 * The new value for this property. 583 * <br>The default is <jk>true</jk>. 584 * @return This object (for method chaining). 585 */ 586 public BeanContextBuilder beansRequireSomeProperties(boolean value) { 587 return set(BEAN_beansRequireSomeProperties, value); 588 } 589 590 /** 591 * Configuration property: Bean type property name. 592 * 593 * <p> 594 * This specifies the name of the bean property used to store the dictionary name of a bean type so that the 595 * parser knows the data type to reconstruct. 596 * 597 * <ul class='seealso'> 598 * <li class='jf'>{@link BeanContext#BEAN_beanTypePropertyName} 599 * </ul> 600 * 601 * @param value 602 * The new value for this property. 603 * <br>The default is <js>"_type"</js>. 604 * @return This object (for method chaining). 605 */ 606 public BeanContextBuilder beanTypePropertyName(String value) { 607 return set(BEAN_beanTypePropertyName, value); 608 } 609 610 /** 611 * Configuration property: Debug mode. 612 * 613 * <p> 614 * Enables the following additional information during serialization: 615 * <ul class='spaced-list'> 616 * <li> 617 * When bean getters throws exceptions, the exception includes the object stack information 618 * in order to determine how that method was invoked. 619 * <li> 620 * Enables {@link Serializer#BEANTRAVERSE_detectRecursions}. 621 * </ul> 622 * 623 * <ul class='seealso'> 624 * <li class='jf'>{@link BeanContext#BEAN_debug} 625 * </ul> 626 * 627 * @param value 628 * The new value for this property. 629 * <br>The default is <jk>false</jk>. 630 * @return This object (for method chaining). 631 */ 632 public BeanContextBuilder debug(boolean value) { 633 return set(BEAN_debug, value); 634 } 635 636 /** 637 * Configuration property: Debug mode. 638 * 639 * <p> 640 * Shortcut for calling <code>debug(<jk>true</jk>)</code>. 641 * 642 * <ul class='seealso'> 643 * <li class='jf'>{@link BeanContext#BEAN_debug} 644 * </ul> 645 * 646 * @return This object (for method chaining). 647 */ 648 public BeanContextBuilder debug() { 649 return set(BEAN_debug, true); 650 } 651 652 /** 653 * Configuration property: POJO example. 654 * 655 * <p> 656 * Specifies an example of the specified class. 657 * 658 * <ul class='seealso'> 659 * <li class='jf'>{@link BeanContext#BEAN_examples} 660 * </ul> 661 * 662 * @param pojoClass The POJO class. 663 * @param o An instance of the POJO class used for examples. 664 * @return This object (for method chaining). 665 */ 666 public <T> BeanContextBuilder example(Class<T> pojoClass, T o) { 667 return addTo(BEAN_examples, pojoClass.getName(), o); 668 } 669 670 /** 671 * Configuration property: POJO example. 672 * 673 * <p> 674 * Specifies an example of the specified class. 675 * 676 * <ul class='seealso'> 677 * <li class='jf'>{@link BeanContext#BEAN_examples} 678 * </ul> 679 * 680 * @param <T> The POJO class type. 681 * @param pojoClass The POJO class. 682 * @param json The simple JSON representation of the example. 683 * @return This object (for method chaining). 684 */ 685 public <T> BeanContextBuilder exampleJson(Class<T> pojoClass, String json) { 686 try { 687 return addTo(BEAN_examples, pojoClass.getName(), SimpleJson.DEFAULT.read(json, pojoClass)); 688 } catch (ParseException e) { 689 throw new RuntimeException(e); 690 } 691 } 692 693 /** 694 * Configuration property: POJO examples. 695 * 696 * <p> 697 * Specifies an example of the specified class. 698 * 699 * <ul class='seealso'> 700 * <li class='jf'>{@link BeanContext#BEAN_examples} 701 * </ul> 702 * 703 * @param json The simple JSON representation of the example. 704 * @return This object (for method chaining). 705 * @throws ParseException If parameter is not valid Simple-JSON. 706 */ 707 public BeanContextBuilder examples(String json) throws ParseException { 708 if (! isObjectMap(json, true)) 709 json = "{" + json + "}"; 710 ObjectMap m = new ObjectMap(json); 711 for (Map.Entry<String,Object> e : m.entrySet()) 712 addTo(BEAN_examples, e.getKey(), e.getValue()); 713 return this; 714 } 715 716 /** 717 * Configuration property: Bean property excludes. 718 * 719 * <p> 720 * Specifies to exclude the specified list of properties for the specified bean class. 721 * 722 * <ul class='seealso'> 723 * <li class='jf'>{@link BeanContext#BEAN_excludeProperties} 724 * </ul> 725 * 726 * @param beanClass The bean class. 727 * @param properties Comma-delimited list of property names. 728 * @return This object (for method chaining). 729 */ 730 public BeanContextBuilder excludeProperties(Class<?> beanClass, String properties) { 731 return addTo(BEAN_excludeProperties, beanClass.getName(), properties); 732 } 733 734 /** 735 * Configuration property: Bean property excludes. 736 * 737 * <p> 738 * Specifies to exclude the specified list of properties for the specified bean classes. 739 * 740 * <ul class='seealso'> 741 * <li class='jf'>{@link BeanContext#BEAN_excludeProperties} 742 * </ul> 743 * 744 * @param values 745 * The new value for this property. 746 * @return This object (for method chaining). 747 */ 748 public BeanContextBuilder excludeProperties(Map<String,String> values) { 749 return set(BEAN_excludeProperties, values); 750 } 751 752 /** 753 * Configuration property: Bean property excludes. 754 * 755 * <ul class='seealso'> 756 * <li class='jf'>{@link BeanContext#BEAN_excludeProperties} 757 * </ul> 758 * 759 * @param beanClassName 760 * The bean class name. 761 * <br>Can be a simple name, fully-qualified name, or <js>"*"</js> for all bean classes. 762 * @param value Comma-delimited list of property names. 763 * @return This object (for method chaining). 764 */ 765 public BeanContextBuilder excludeProperties(String beanClassName, String value) { 766 return addTo(BEAN_excludeProperties, beanClassName, value); 767 } 768 769 /** 770 * Configuration property: Find fluent setters. 771 * 772 * <p> 773 * When enabled, fluent setters are detected on beans. 774 * 775 * <p> 776 * Fluent setters must have the following attributes: 777 * <ul> 778 * <li>Public. 779 * <li>Not static. 780 * <li>Take in one parameter. 781 * <li>Return the bean itself. 782 * </ul> 783 * 784 * <ul class='seealso'> 785 * <li class='jf'>{@link BeanContext#BEAN_fluentSetters} 786 * </ul> 787 * 788 * @param value 789 * The new value for this property. 790 * <br>The default is <jk>false</jk>. 791 * @return This object (for method chaining). 792 */ 793 public BeanContextBuilder fluentSetters(boolean value) { 794 return set(BEAN_fluentSetters, value); 795 } 796 797 /** 798 * Configuration property: Find fluent setters. 799 * 800 * <p> 801 * Shortcut for calling <code>fluentSetters(<jk>true</jk>)</code>. 802 * 803 * <ul class='seealso'> 804 * <li class='jf'>{@link BeanContext#BEAN_fluentSetters} 805 * </ul> 806 * 807 * @return This object (for method chaining). 808 */ 809 public BeanContextBuilder fluentSetters() { 810 return set(BEAN_fluentSetters, true); 811 } 812 813 /** 814 * Configuration property: Ignore invocation errors on getters. 815 * 816 * <p> 817 * If <jk>true</jk>, errors thrown when calling bean getter methods will silently be ignored. 818 * Otherwise, a {@code BeanRuntimeException} is thrown. 819 * 820 * <ul class='seealso'> 821 * <li class='jf'>{@link BeanContext#BEAN_ignoreInvocationExceptionsOnGetters} 822 * </ul> 823 * 824 * @param value 825 * The new value for this property. 826 * <br>The default is <jk>false</jk>. 827 * @return This object (for method chaining). 828 */ 829 public BeanContextBuilder ignoreInvocationExceptionsOnGetters(boolean value) { 830 return set(BEAN_ignoreInvocationExceptionsOnGetters, value); 831 } 832 833 /** 834 * Configuration property: Ignore invocation errors on getters. 835 * 836 * <p> 837 * Shortcut for calling <code>ignoreInvocationExceptionsOnGetters(<jk>true</jk>)</code>. 838 * 839 * <ul class='seealso'> 840 * <li class='jf'>{@link BeanContext#BEAN_ignoreInvocationExceptionsOnGetters} 841 * </ul> 842 * 843 * @return This object (for method chaining). 844 */ 845 public BeanContextBuilder ignoreInvocationExceptionsOnGetters() { 846 return set(BEAN_ignoreInvocationExceptionsOnGetters, true); 847 } 848 849 /** 850 * Configuration property: Ignore invocation errors on setters. 851 * 852 * <p> 853 * If <jk>true</jk>, errors thrown when calling bean setter methods will silently be ignored. 854 * <br>Otherwise, a {@code BeanRuntimeException} is thrown. 855 * 856 * <ul class='seealso'> 857 * <li class='jf'>{@link BeanContext#BEAN_ignoreInvocationExceptionsOnSetters} 858 * </ul> 859 * 860 * @param value 861 * The new value for this property. 862 * <br>The default is <jk>false</jk>. 863 * @return This object (for method chaining). 864 */ 865 public BeanContextBuilder ignoreInvocationExceptionsOnSetters(boolean value) { 866 return set(BEAN_ignoreInvocationExceptionsOnSetters, value); 867 } 868 869 /** 870 * Configuration property: Ignore invocation errors on setters. 871 * 872 * <p> 873 * Shortcut for calling <code>ignoreInvocationExceptionsOnSetters(<jk>true</jk>)</code>. 874 * 875 * <ul class='seealso'> 876 * <li class='jf'>{@link BeanContext#BEAN_ignoreInvocationExceptionsOnSetters} 877 * </ul> 878 * 879 * @return This object (for method chaining). 880 */ 881 public BeanContextBuilder ignoreInvocationExceptionsOnSetters() { 882 return set(BEAN_ignoreInvocationExceptionsOnSetters, true); 883 } 884 885 /** 886 * Configuration property: Ignore properties without setters. 887 * 888 * <p> 889 * If <jk>true</jk>, trying to set a value on a bean property without a setter will silently be ignored. 890 * <br>Otherwise, a {@code BeanRuntimeException} is thrown. 891 * 892 * <ul class='seealso'> 893 * <li class='jf'>{@link BeanContext#BEAN_ignorePropertiesWithoutSetters} 894 * </ul> 895 * 896 * @param value 897 * The new value for this property. 898 * <br>The default is <jk>true</jk>. 899 * @return This object (for method chaining). 900 */ 901 public BeanContextBuilder ignorePropertiesWithoutSetters(boolean value) { 902 return set(BEAN_ignorePropertiesWithoutSetters, value); 903 } 904 905 /** 906 * Configuration property: Ignore unknown properties. 907 * 908 * <p> 909 * If <jk>true</jk>, trying to set a value on a non-existent bean property will silently be ignored. 910 * <br>Otherwise, a {@code BeanRuntimeException} is thrown. 911 * 912 * <ul class='seealso'> 913 * <li class='jf'>{@link BeanContext#BEAN_ignoreUnknownBeanProperties} 914 * </ul> 915 * 916 * @param value 917 * The new value for this property. 918 * <br>The default is <jk>false</jk>. 919 * @return This object (for method chaining). 920 */ 921 public BeanContextBuilder ignoreUnknownBeanProperties(boolean value) { 922 return set(BEAN_ignoreUnknownBeanProperties, value); 923 } 924 925 /** 926 * Configuration property: Ignore unknown properties. 927 * 928 * <p> 929 * Shortcut for calling <code>ignoreUnknownBeanProperties(<jk>true</jk>)</code>. 930 * 931 * <ul class='seealso'> 932 * <li class='jf'>{@link BeanContext#BEAN_ignoreUnknownBeanProperties} 933 * </ul> 934 * 935 * @return This object (for method chaining). 936 */ 937 public BeanContextBuilder ignoreUnknownBeanProperties() { 938 return set(BEAN_ignoreUnknownBeanProperties, true); 939 } 940 941 /** 942 * Configuration property: Ignore unknown properties with null values. 943 * 944 * <p> 945 * If <jk>true</jk>, trying to set a <jk>null</jk> value on a non-existent bean property will silently be ignored. 946 * <br>Otherwise, a {@code BeanRuntimeException} is thrown. 947 * 948 * <ul class='seealso'> 949 * <li class='jf'>{@link BeanContext#BEAN_ignoreUnknownNullBeanProperties} 950 * </ul> 951 * 952 * @param value 953 * The new value for this property. 954 * <br>The default is <jk>true</jk>. 955 * @return This object (for method chaining). 956 */ 957 public BeanContextBuilder ignoreUnknownNullBeanProperties(boolean value) { 958 return set(BEAN_ignoreUnknownNullBeanProperties, value); 959 } 960 961 /** 962 * Configuration property: Implementation classes. 963 * 964 * <ul class='seealso'> 965 * <li class='jf'>{@link BeanContext#BEAN_implClasses} 966 * </ul> 967 * 968 * @param interfaceClass The interface class. 969 * @param implClass The implementation class. 970 * @return This object (for method chaining). 971 */ 972 public BeanContextBuilder implClass(Class<?> interfaceClass, Class<?> implClass) { 973 return addTo(BEAN_implClasses, interfaceClass.getName(), implClass); 974 } 975 976 /** 977 * Configuration property: Implementation classes. 978 * 979 * <p> 980 * For interfaces and abstract classes this method can be used to specify an implementation class for the 981 * interface/abstract class so that instances of the implementation class are used when instantiated (e.g. during a 982 * parse). 983 * 984 * <ul class='seealso'> 985 * <li class='jf'>{@link BeanContext#BEAN_implClasses} 986 * </ul> 987 * 988 * @param values The new value for this property. 989 * @return This object (for method chaining). 990 */ 991 public BeanContextBuilder implClasses(Map<String,Class<?>> values) { 992 return set(BEAN_implClasses, values); 993 } 994 995 /** 996 * Configuration property: Bean property includes. 997 * 998 * <p> 999 * Specifies the set and order of names of properties associated with the bean class. 1000 * 1001 * <ul class='seealso'> 1002 * <li class='jf'>{@link BeanContext#BEAN_includeProperties} 1003 * </ul> 1004 * 1005 * @param beanClass The bean class. 1006 * @param value Comma-delimited list of property names. 1007 * @return This object (for method chaining). 1008 */ 1009 public BeanContextBuilder includeProperties(Class<?> beanClass, String value) { 1010 return addTo(BEAN_includeProperties, beanClass.getName(), value); 1011 } 1012 1013 /** 1014 * Configuration property: Bean property includes. 1015 * 1016 * <p> 1017 * Specifies the set and order of names of properties associated with the bean class. 1018 * 1019 * <ul class='seealso'> 1020 * <li class='jf'>{@link BeanContext#BEAN_includeProperties} 1021 * </ul> 1022 * 1023 * @param values The new value for this property. 1024 * @return This object (for method chaining). 1025 */ 1026 public BeanContextBuilder includeProperties(Map<String,String> values) { 1027 return set(BEAN_includeProperties, values); 1028 } 1029 1030 /** 1031 * Configuration property: Bean property includes. 1032 * 1033 * <p> 1034 * Specifies the set and order of names of properties associated with the bean class. 1035 * 1036 * <ul class='seealso'> 1037 * <li class='jf'>{@link BeanContext#BEAN_includeProperties} 1038 * </ul> 1039 * 1040 * @param beanClassName 1041 * The bean class name. 1042 * <br>Can be a simple name, fully-qualified name, or <js>"*"</js> for all beans. 1043 * @param value Comma-delimited list of property names. 1044 * @return This object (for method chaining). 1045 */ 1046 public BeanContextBuilder includeProperties(String beanClassName, String value) { 1047 return addTo(BEAN_includeProperties, beanClassName, value); 1048 } 1049 1050 /** 1051 * Configuration property: Locale. 1052 * 1053 * <p> 1054 * Specifies a default locale for serializer and parser sessions. 1055 * 1056 * <ul class='seealso'> 1057 * <li class='jf'>{@link BeanContext#BEAN_locale} 1058 * </ul> 1059 * 1060 * @param value The new value for this property. 1061 * @return This object (for method chaining). 1062 */ 1063 public BeanContextBuilder locale(Locale value) { 1064 return set(BEAN_locale, value); 1065 } 1066 1067 /** 1068 * Configuration property: Media type. 1069 * 1070 * <p> 1071 * Specifies a default media type value for serializer and parser sessions. 1072 * 1073 * <ul class='seealso'> 1074 * <li class='jf'>{@link BeanContext#BEAN_mediaType} 1075 * </ul> 1076 * 1077 * @param value The new value for this property. 1078 * @return This object (for method chaining). 1079 */ 1080 public BeanContextBuilder mediaType(MediaType value) { 1081 return set(BEAN_mediaType, value); 1082 } 1083 1084 /** 1085 * Configuration property: Bean class exclusions. 1086 * 1087 * <p> 1088 * List of classes that should not be treated as beans even if they appear to be bean-like. 1089 * <br>Not-bean classes are converted to <c>Strings</c> during serialization. 1090 * 1091 * <ul class='seealso'> 1092 * <li class='jf'>{@link BeanContext#BEAN_notBeanClasses} 1093 * </ul> 1094 * 1095 * @param values The values to add to this property. 1096 * @return This object (for method chaining). 1097 */ 1098 public BeanContextBuilder notBeanClasses(Class<?>...values) { 1099 return addTo(BEAN_notBeanClasses, values); 1100 } 1101 1102 /** 1103 * Configuration property: Bean class exclusions. 1104 * 1105 * <p> 1106 * List of classes that should not be treated as beans even if they appear to be bean-like. 1107 * <br>Not-bean classes are converted to <c>Strings</c> during serialization. 1108 * 1109 * <ul class='seealso'> 1110 * <li class='jf'>{@link BeanContext#BEAN_notBeanClasses} 1111 * </ul> 1112 * 1113 * @param values 1114 * The values to add to this property. 1115 * <br>Values can consist of any of the following types: 1116 * <ul> 1117 * <li>Classes. 1118 * <li>Arrays and collections of classes. 1119 * </ul> 1120 * @return This object (for method chaining). 1121 */ 1122 public BeanContextBuilder notBeanClasses(Object...values) { 1123 return addTo(BEAN_notBeanClasses, values); 1124 } 1125 1126 /** 1127 * Configuration property: Bean class exclusions. 1128 * 1129 * <p> 1130 * Not-bean classes are converted to <c>Strings</c> during serialization even if they appear to be 1131 * bean-like. 1132 * 1133 * <ul class='seealso'> 1134 * <li class='jf'>{@link BeanContext#BEAN_notBeanClasses} 1135 * </ul> 1136 * 1137 * @param values 1138 * The new value for this property. 1139 * @return This object (for method chaining). 1140 */ 1141 public BeanContextBuilder notBeanClassesReplace(Class<?>...values) { 1142 return set(BEAN_notBeanClasses, values); 1143 } 1144 1145 /** 1146 * Configuration property: Bean class exclusions. 1147 * 1148 * <p> 1149 * Not-bean classes are converted to <c>Strings</c> during serialization even if they appear to be 1150 * bean-like. 1151 * 1152 * <ul class='seealso'> 1153 * <li class='jf'>{@link BeanContext#BEAN_notBeanClasses} 1154 * </ul> 1155 * 1156 * @param values 1157 * The new value for this property. 1158 * <br>Values can consist of any of the following types: 1159 * <ul> 1160 * <li>Classes. 1161 * <li>Arrays and collections of classes. 1162 * </ul> 1163 * @return This object (for method chaining). 1164 */ 1165 public BeanContextBuilder notBeanClassesReplace(Object...values) { 1166 return set(BEAN_notBeanClasses, values); 1167 } 1168 1169 /** 1170 * Configuration property: Bean class exclusions. 1171 * 1172 * <ul class='seealso'> 1173 * <li class='jf'>{@link BeanContext#BEAN_notBeanClasses} 1174 * </ul> 1175 * 1176 * @param values 1177 * The values to remove from this property. 1178 * @return This object (for method chaining). 1179 */ 1180 public BeanContextBuilder notBeanClassesRemove(Class<?>...values) { 1181 return removeFrom(BEAN_notBeanClasses, values); 1182 } 1183 1184 /** 1185 * Configuration property: Bean class exclusions. 1186 * 1187 * <ul class='seealso'> 1188 * <li class='jf'>{@link BeanContext#BEAN_notBeanClasses} 1189 * </ul> 1190 * 1191 * @param values 1192 * The values to remove from this property. 1193 * <br>Values can consist of any of the following types: 1194 * <ul> 1195 * <li>Classes. 1196 * <li>Arrays and collections of classes. 1197 * </ul> 1198 * @return This object (for method chaining). 1199 */ 1200 public BeanContextBuilder notBeanClassesRemove(Object...values) { 1201 return removeFrom(BEAN_notBeanClasses, values); 1202 } 1203 1204 /** 1205 * Configuration property: Bean package exclusions. 1206 * 1207 * <ul class='seealso'> 1208 * <li class='jf'>{@link BeanContext#BEAN_notBeanPackages} 1209 * </ul> 1210 * 1211 * @param values 1212 * The values to add to this property. 1213 * @return This object (for method chaining). 1214 */ 1215 public BeanContextBuilder notBeanPackages(String...values) { 1216 return addTo(BEAN_notBeanPackages, values); 1217 } 1218 1219 /** 1220 * Configuration property: Bean package exclusions. 1221 * 1222 * <ul class='seealso'> 1223 * <li class='jf'>{@link BeanContext#BEAN_notBeanPackages} 1224 * </ul> 1225 * 1226 * @param values 1227 * The values to add to this property. 1228 * <br>Values can consist of any of the following types: 1229 * <ul> 1230 * <li>Strings. 1231 * <li>Arrays and collections of strings. 1232 * </ul> 1233 * @return This object (for method chaining). 1234 */ 1235 public BeanContextBuilder notBeanPackages(Object...values) { 1236 return addTo(BEAN_notBeanPackages, values); 1237 } 1238 1239 /** 1240 * Configuration property: Bean package exclusions. 1241 * 1242 * <ul class='seealso'> 1243 * <li class='jf'>{@link BeanContext#BEAN_notBeanPackages} 1244 * </ul> 1245 * 1246 * @param values 1247 * <br>Values can consist of any of the following types: 1248 * @return This object (for method chaining). 1249 */ 1250 public BeanContextBuilder notBeanPackagesReplace(String...values) { 1251 return set(BEAN_notBeanPackages, values); 1252 } 1253 1254 /** 1255 * Configuration property: Bean package exclusions. 1256 * 1257 * <ul class='seealso'> 1258 * <li class='jf'>{@link BeanContext#BEAN_notBeanPackages} 1259 * </ul> 1260 * 1261 * @param values 1262 * <br>Values can consist of any of the following types: 1263 * <br>Possible values are: 1264 * <ul> 1265 * <li>Strings. 1266 * <li>Arrays and collections of strings. 1267 * </ul> 1268 * @return This object (for method chaining). 1269 */ 1270 public BeanContextBuilder notBeanPackagesReplace(Object...values) { 1271 return set(BEAN_notBeanPackages, values); 1272 } 1273 1274 /** 1275 * Configuration property: Bean package exclusions. 1276 * 1277 * <ul class='seealso'> 1278 * <li class='jf'>{@link BeanContext#BEAN_notBeanPackages} 1279 * </ul> 1280 * 1281 * @param values The values to remove from this property. 1282 * @return This object (for method chaining). 1283 */ 1284 public BeanContextBuilder notBeanPackagesRemove(String...values) { 1285 return removeFrom(BEAN_notBeanPackages, values); 1286 } 1287 1288 /** 1289 * Configuration property: Bean package exclusions. 1290 * 1291 * <ul class='seealso'> 1292 * <li class='jf'>{@link BeanContext#BEAN_notBeanPackages} 1293 * </ul> 1294 * 1295 * @param values 1296 * <br>Values can consist of any of the following types: 1297 * <br>Possible values are: 1298 * <ul> 1299 * <li>Strings. 1300 * <li>Arrays and collections of strings. 1301 * </ul> 1302 * @return This object (for method chaining). 1303 */ 1304 public BeanContextBuilder notBeanPackagesRemove(Object...values) { 1305 return removeFrom(BEAN_notBeanPackages, values); 1306 } 1307 1308 /** 1309 * Configuration property: POJO swaps. 1310 * 1311 * <ul class='seealso'> 1312 * <li class='jf'>{@link BeanContext#BEAN_pojoSwaps} 1313 * </ul> 1314 * 1315 * @param values The values to add to this property. 1316 * @return This object (for method chaining). 1317 */ 1318 public BeanContextBuilder pojoSwaps(Class<?>...values) { 1319 return addTo(BEAN_pojoSwaps, values); 1320 } 1321 1322 /** 1323 * Configuration property: POJO swaps. 1324 * 1325 * <ul class='seealso'> 1326 * <li class='jf'>{@link BeanContext#BEAN_pojoSwaps} 1327 * </ul> 1328 * 1329 * @param values 1330 * The values to add to this property. 1331 * <br>Values can consist of any of the following types: 1332 * <ul> 1333 * <li>Any subclass of {@link PojoSwap}. 1334 * <li>Any surrogate class. A shortcut for defining a {@link SurrogateSwap}. 1335 * <li>Any array or collection of the objects above. 1336 * </ul> 1337 * @return This object (for method chaining). 1338 */ 1339 public BeanContextBuilder pojoSwaps(Object...values) { 1340 return addTo(BEAN_pojoSwaps, values); 1341 } 1342 1343 /** 1344 * Configuration property: POJO swaps. 1345 * 1346 * <ul class='seealso'> 1347 * <li class='jf'>{@link BeanContext#BEAN_pojoSwaps} 1348 * </ul> 1349 * 1350 * @param values 1351 * The values to remove from this property. 1352 * <br>Values can consist of any of the following types: 1353 * <ul> 1354 * <li>Any subclass of {@link PojoSwap}. 1355 * <li>Any surrogate class. A shortcut for defining a {@link SurrogateSwap}. 1356 * <li>Any array or collection of the objects above. 1357 * </ul> 1358 * @return This object (for method chaining). 1359 */ 1360 public BeanContextBuilder pojoSwapsReplace(Class<?>...values) { 1361 return set(BEAN_pojoSwaps, values); 1362 } 1363 1364 /** 1365 * Configuration property: POJO swaps. 1366 * 1367 * <ul class='seealso'> 1368 * <li class='jf'>{@link BeanContext#BEAN_pojoSwaps} 1369 * </ul> 1370 * 1371 * @param values 1372 * The values to remove from this property. 1373 * <br>Values can consist of any of the following types: 1374 * <ul> 1375 * <li>Any subclass of {@link PojoSwap}. 1376 * <li>Any surrogate class. A shortcut for defining a {@link SurrogateSwap}. 1377 * <li>Any array or collection of the objects above. 1378 * </ul> 1379 * @return This object (for method chaining). 1380 */ 1381 public BeanContextBuilder pojoSwapsReplace(Object...values) { 1382 return set(BEAN_pojoSwaps, values); 1383 } 1384 1385 /** 1386 * Configuration property: POJO swaps. 1387 * 1388 * <ul class='seealso'> 1389 * <li class='jf'>{@link BeanContext#BEAN_pojoSwaps} 1390 * </ul> 1391 * 1392 * @param values 1393 * The values to remove from this property. 1394 * <br>Values can consist of any of the following types: 1395 * <ul> 1396 * <li>Any subclass of {@link PojoSwap}. 1397 * <li>Any surrogate class. A shortcut for defining a {@link SurrogateSwap}. 1398 * </ul> 1399 * @return This object (for method chaining). 1400 */ 1401 public BeanContextBuilder pojoSwapsRemove(Class<?>...values) { 1402 return removeFrom(BEAN_pojoSwaps, values); 1403 } 1404 1405 /** 1406 * Configuration property: POJO swaps. 1407 * 1408 * <ul class='seealso'> 1409 * <li class='jf'>{@link BeanContext#BEAN_pojoSwaps} 1410 * </ul> 1411 * 1412 * @param values 1413 * The values to remove from this property. 1414 * <br>Values can consist of any of the following types: 1415 * <ul> 1416 * <li>Any subclass of {@link PojoSwap}. 1417 * <li>Any surrogate class. A shortcut for defining a {@link SurrogateSwap}. 1418 * <li>Any array or collection of the objects above. 1419 * </ul> 1420 * @return This object (for method chaining). 1421 */ 1422 public BeanContextBuilder pojoSwapsRemove(Object...values) { 1423 return removeFrom(BEAN_pojoSwaps, values); 1424 } 1425 1426 /** 1427 * Configuration property: Bean property namer 1428 * 1429 * <p> 1430 * The class to use for calculating bean property names. 1431 * 1432 * <ul class='seealso'> 1433 * <li class='jf'>{@link BeanContext#BEAN_propertyNamer} 1434 * </ul> 1435 * 1436 * @param value 1437 * The new value for this setting. 1438 * <br>The default is {@link PropertyNamerDefault}. 1439 * @return This object (for method chaining). 1440 */ 1441 public BeanContextBuilder propertyNamer(Class<? extends PropertyNamer> value) { 1442 return set(BEAN_propertyNamer, value); 1443 } 1444 1445 /** 1446 * Configuration property: Sort bean properties. 1447 * 1448 * <p> 1449 * When <jk>true</jk>, all bean properties will be serialized and access in alphabetical order. 1450 * Otherwise, the natural order of the bean properties is used which is dependent on the JVM vendor. 1451 * 1452 * <ul class='seealso'> 1453 * <li class='jf'>{@link BeanContext#BEAN_sortProperties} 1454 * </ul> 1455 * 1456 * @param value 1457 * The new value for this property. 1458 * <br>The default is <jk>false</jk>. 1459 * @return This object (for method chaining). 1460 */ 1461 public BeanContextBuilder sortProperties(boolean value) { 1462 return set(BEAN_sortProperties, value); 1463 } 1464 1465 /** 1466 * Configuration property: Sort bean properties. 1467 * 1468 * <p> 1469 * Shortcut for calling <code>sortProperties(<jk>true</jk>)</code>. 1470 * 1471 * <ul class='seealso'> 1472 * <li class='jf'>{@link BeanContext#BEAN_sortProperties} 1473 * </ul> 1474 * 1475 * @return This object (for method chaining). 1476 */ 1477 public BeanContextBuilder sortProperties() { 1478 return set(BEAN_sortProperties, true); 1479 } 1480 1481 /** 1482 * Configuration property: TimeZone. 1483 * 1484 * <ul class='seealso'> 1485 * <li class='jf'>{@link BeanContext#BEAN_timeZone} 1486 * </ul> 1487 * 1488 * @param value The new value for this property. 1489 * @return This object (for method chaining). 1490 */ 1491 public BeanContextBuilder timeZone(TimeZone value) { 1492 return set(BEAN_timeZone, value); 1493 } 1494 1495 /** 1496 * Configuration property: Use enum names. 1497 * 1498 * <p> 1499 * When enabled, enums are always serialized by name instead of using {@link Object#toString()}. 1500 * 1501 * <ul class='seealso'> 1502 * <li class='jf'>{@link BeanContext#BEAN_useEnumNames} 1503 * </ul> 1504 * 1505 * @param value The property value. 1506 * @return This object (for method chaining). 1507 */ 1508 public BeanContextBuilder useEnumNames(boolean value) { 1509 return set(BEAN_useEnumNames, value); 1510 } 1511 1512 /** 1513 * Configuration property: Use enum names. 1514 * 1515 * <p> 1516 * When enabled, enums are always serialized by name instead of using {@link Object#toString()}. 1517 * 1518 * <ul class='seealso'> 1519 * <li class='jf'>{@link BeanContext#BEAN_useEnumNames} 1520 * </ul> 1521 * 1522 * @return This object (for method chaining). 1523 */ 1524 public BeanContextBuilder useEnumNames() { 1525 return set(BEAN_useEnumNames, true); 1526 } 1527 1528 /** 1529 * Configuration property: Use interface proxies. 1530 * 1531 * <p> 1532 * If <jk>true</jk>, then interfaces will be instantiated as proxy classes through the use of an 1533 * {@link InvocationHandler} if there is no other way of instantiating them. 1534 * 1535 * <ul class='seealso'> 1536 * <li class='jf'>{@link BeanContext#BEAN_useInterfaceProxies} 1537 * </ul> 1538 * 1539 * @param value 1540 * The new value for this property. 1541 * <br>The default is <jk>true</jk>. 1542 * @return This object (for method chaining). 1543 */ 1544 public BeanContextBuilder useInterfaceProxies(boolean value) { 1545 return set(BEAN_useInterfaceProxies, value); 1546 } 1547 1548 /** 1549 * Configuration property: Use Java Introspector. 1550 * 1551 * <p> 1552 * Using the built-in Java bean introspector will not pick up fields or non-standard getters/setters. 1553 * 1554 * <ul class='notes'> 1555 * <li>Most {@link Bean @Bean} annotations will be ignored if you enable this setting. 1556 * </ul> 1557 * 1558 * <ul class='seealso'> 1559 * <li class='jf'>{@link BeanContext#BEAN_useJavaBeanIntrospector} 1560 * </ul> 1561 * 1562 * @param value 1563 * The new value for this property. 1564 * <br>The default is <jk>false</jk>. 1565 * @return This object (for method chaining). 1566 */ 1567 public BeanContextBuilder useJavaBeanIntrospector(boolean value) { 1568 return set(BEAN_useJavaBeanIntrospector, value); 1569 } 1570 1571 /** 1572 * Configuration property: Use Java Introspector. 1573 * 1574 * <p> 1575 * Shortcut for calling <code>useJavaBeanIntrospector(<jk>true</jk>)</code>. 1576 * 1577 * <ul class='seealso'> 1578 * <li class='jf'>{@link BeanContext#BEAN_useJavaBeanIntrospector} 1579 * </ul> 1580 * 1581 * @return This object (for method chaining). 1582 */ 1583 public BeanContextBuilder useJavaBeanIntrospector() { 1584 return set(BEAN_useJavaBeanIntrospector, true); 1585 } 1586 1587 @Override /* ContextBuilder */ 1588 public BeanContextBuilder set(String name, Object value) { 1589 super.set(name, value); 1590 return this; 1591 } 1592 1593 @Override /* ContextBuilder */ 1594 public BeanContextBuilder set(Map<String,Object> properties) { 1595 super.set(properties); 1596 return this; 1597 } 1598 1599 @Override /* ContextBuilder */ 1600 public BeanContextBuilder add(Map<String,Object> properties) { 1601 super.add(properties); 1602 return this; 1603 } 1604 1605 @Override /* ContextBuilder */ 1606 public BeanContextBuilder addTo(String name, Object value) { 1607 super.addTo(name, value); 1608 return this; 1609 } 1610 1611 @Override /* ContextBuilder */ 1612 public BeanContextBuilder addTo(String name, String key, Object value) { 1613 super.addTo(name, key, value); 1614 return this; 1615 } 1616 1617 @Override /* ContextBuilder */ 1618 public BeanContextBuilder removeFrom(String name, Object value) { 1619 super.removeFrom(name, value); 1620 return this; 1621 } 1622 1623 @Override /* ContextBuilder */ 1624 public BeanContextBuilder apply(PropertyStore copyFrom) { 1625 super.apply(copyFrom); 1626 return this; 1627 } 1628 1629 @Override /* ContextBuilder */ 1630 public BeanContextBuilder applyAnnotations(AnnotationList al, VarResolverSession vrs) { 1631 super.applyAnnotations(al, vrs); 1632 return this; 1633 } 1634 1635 @Override /* ContextBuilder */ 1636 public BeanContextBuilder applyAnnotations(Class<?> fromClass) { 1637 super.applyAnnotations(fromClass); 1638 return this; 1639 } 1640 1641 @Override /* ContextBuilder */ 1642 public BeanContextBuilder applyAnnotations(Method fromMethod) { 1643 super.applyAnnotations(fromMethod); 1644 return this; 1645 } 1646}