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.oapi; 014 015import java.lang.annotation.*; 016import java.lang.reflect.*; 017import java.nio.charset.*; 018import java.util.*; 019import java.util.concurrent.*; 020 021import org.apache.juneau.*; 022import org.apache.juneau.annotation.*; 023import org.apache.juneau.httppart.*; 024import org.apache.juneau.internal.*; 025import org.apache.juneau.uon.*; 026import org.apache.juneau.utils.*; 027 028/** 029 * Serializes POJOs to values suitable for transmission as HTTP headers, query/form-data parameters, and path variables. 030 * 031 * <h5 class='section'>Notes:</h5><ul> 032 * <li class='note'>This class is thread safe and reusable. 033 * </ul> 034 * 035 * <h5 class='section'>See Also:</h5><ul> 036 * <li class='link'><a class="doclink" href="../../../../index.html#jm.OpenApiDetails">OpenAPI Details</a> 037 038 * </ul> 039 */ 040public class OpenApiSerializer extends UonSerializer implements OpenApiMetaProvider { 041 042 //------------------------------------------------------------------------------------------------------------------- 043 // Static 044 //------------------------------------------------------------------------------------------------------------------- 045 046 /** Reusable instance of {@link OpenApiSerializer}, all default settings. */ 047 public static final OpenApiSerializer DEFAULT = new OpenApiSerializer(create()); 048 049 /** 050 * Creates a new builder for this object. 051 * 052 * @return A new builder. 053 */ 054 public static Builder create() { 055 return new Builder(); 056 } 057 058 //------------------------------------------------------------------------------------------------------------------- 059 // Builder 060 //------------------------------------------------------------------------------------------------------------------- 061 062 /** 063 * Builder class. 064 */ 065 @FluentSetters 066 public static class Builder extends UonSerializer.Builder { 067 068 private static final Cache<HashKey,OpenApiSerializer> CACHE = Cache.of(HashKey.class, OpenApiSerializer.class).build(); 069 070 HttpPartFormat format; 071 HttpPartCollectionFormat collectionFormat; 072 073 /** 074 * Constructor, default settings. 075 */ 076 protected Builder() { 077 produces("text/openapi"); 078 format = HttpPartFormat.NO_FORMAT; 079 collectionFormat = HttpPartCollectionFormat.NO_COLLECTION_FORMAT; 080 } 081 082 /** 083 * Copy constructor. 084 * 085 * @param copyFrom The bean to copy from. 086 */ 087 protected Builder(OpenApiSerializer copyFrom) { 088 super(copyFrom); 089 format = copyFrom.format; 090 collectionFormat = copyFrom.collectionFormat; 091 } 092 093 /** 094 * Copy constructor. 095 * 096 * @param copyFrom The builder to copy from. 097 */ 098 protected Builder(Builder copyFrom) { 099 super(copyFrom); 100 format = copyFrom.format; 101 collectionFormat = copyFrom.collectionFormat; 102 } 103 104 @Override /* Context.Builder */ 105 public Builder copy() { 106 return new Builder(this); 107 } 108 109 @Override /* Context.Builder */ 110 public OpenApiSerializer build() { 111 return cache(CACHE).build(OpenApiSerializer.class); 112 } 113 114 @Override /* Context.Builder */ 115 public HashKey hashKey() { 116 return HashKey.of( 117 super.hashKey(), 118 format, 119 collectionFormat 120 ); 121 } 122 123 //----------------------------------------------------------------------------------------------------------------- 124 // Properties 125 //----------------------------------------------------------------------------------------------------------------- 126 127 /** 128 * <i><l>OpenApiCommon</l> configuration property: </i> Default format for HTTP parts. 129 * 130 * <p> 131 * Specifies the format to use for HTTP parts when not otherwise specified via {@link org.apache.juneau.annotation.Schema#format()}. 132 * 133 * <h5 class='section'>Example:</h5> 134 * <p class='bjava'> 135 * <jc>// Create a plain-text serializer.</jc> 136 * OpenApiSerializer <jv>serializer1</jv> = OpenApiSerializer 137 * .<jsm>create</jsm>() 138 * .build(); 139 * 140 * <jc>// Create a UON serializer.</jc> 141 * OpenApiSerializer <jv>serializer2</jv> = OpenApiSerializer 142 * .<jsm>create</jsm>() 143 * .format(<jsf>UON</jsf>) 144 * .build(); 145 * 146 * String <jv>string</jv> = <js>"foo bar"</js>; 147 * 148 * <jc>// Produces: "foo bar"</jc> 149 * String <jv>value1</jv> = <jv>serializer1</jv>.serialize(<jv>string</jv>); 150 * 151 * <jc>// Produces: "'foo bar'"</jc> 152 * String <jv>value2</jv> = <jv>serializer2</jv>.serialize(<jv>string</jv>); 153 * </p> 154 * 155 * <ul class='values javatree'> 156 * <li class='jc'>{@link org.apache.juneau.httppart.HttpPartFormat} 157 * <ul> 158 * <li class='jf'>{@link org.apache.juneau.httppart.HttpPartFormat#UON UON} - UON notation (e.g. <js>"'foo bar'"</js>). 159 * <li class='jf'>{@link org.apache.juneau.httppart.HttpPartFormat#INT32 INT32} - Signed 32 bits. 160 * <li class='jf'>{@link org.apache.juneau.httppart.HttpPartFormat#INT64 INT64} - Signed 64 bits. 161 * <li class='jf'>{@link org.apache.juneau.httppart.HttpPartFormat#FLOAT FLOAT} - 32-bit floating point number. 162 * <li class='jf'>{@link org.apache.juneau.httppart.HttpPartFormat#DOUBLE DOUBLE} - 64-bit floating point number. 163 * <li class='jf'>{@link org.apache.juneau.httppart.HttpPartFormat#BYTE BYTE} - BASE-64 encoded characters. 164 * <li class='jf'>{@link org.apache.juneau.httppart.HttpPartFormat#BINARY BINARY} - Hexadecimal encoded octets (e.g. <js>"00FF"</js>). 165 * <li class='jf'>{@link org.apache.juneau.httppart.HttpPartFormat#BINARY_SPACED BINARY_SPACED} - Spaced-separated hexadecimal encoded octets (e.g. <js>"00 FF"</js>). 166 * <li class='jf'>{@link org.apache.juneau.httppart.HttpPartFormat#DATE DATE} - An <a href='http://xml2rfc.ietf.org/public/rfc/html/rfc3339.html#anchor14'>RFC3339 full-date</a>. 167 * <li class='jf'>{@link org.apache.juneau.httppart.HttpPartFormat#DATE_TIME DATE_TIME} - An <a href='http://xml2rfc.ietf.org/public/rfc/html/rfc3339.html#anchor14'>RFC3339 date-time</a>. 168 * <li class='jf'>{@link org.apache.juneau.httppart.HttpPartFormat#PASSWORD PASSWORD} - Used to hint UIs the input needs to be obscured. 169 * <li class='jf'>{@link org.apache.juneau.httppart.HttpPartFormat#NO_FORMAT NO_FORMAT} - (default) Not specified. 170 * </ul> 171 * </ul> 172 * 173 * @param value The new value for this property. 174 * @return This object. 175 */ 176 @FluentSetter 177 public Builder format(HttpPartFormat value) { 178 format = value; 179 return this; 180 } 181 182 /** 183 * <i><l>OpenApiCommon</l> configuration property: </i> Default collection format for HTTP parts. 184 * 185 * <p> 186 * Specifies the collection format to use for HTTP parts when not otherwise specified via {@link org.apache.juneau.annotation.Schema#collectionFormat()}. 187 * 188 * <h5 class='section'>Example:</h5> 189 * <p class='bjava'> 190 * <jc>// Create a serializer using CSV for collections.</jc> 191 * OpenApiSerializer <jv>serializer1</jv> = OpenApiSerializer 192 * .<jsm>create</jsm>() 193 * .collectionFormat(<jsf>CSV</jsf>) 194 * .build(); 195 * 196 * <jc>// Create a serializer using UON for collections.</jc> 197 * OpenApiSerializer <jv>serializer2</jv> = OpenApiSerializer 198 * .<jsm>create</jsm>() 199 * .collectionFormat(<jsf>UON</jsf>) 200 * .build(); 201 * 202 * <jc>// An arbitrary data structure.</jc> 203 * JsonList <jv>list</jv> = JsonList.<jsm>of</jsm>( 204 * <js>"foo"</js>, 205 * <js>"bar"</js>, 206 * JsonMap.<jsm>of</jsm>( 207 * <js>"baz"</js>, JsonList.<jsm>of</jsm>(<js>"qux"</js>,<js>"true"</js>,<js>"123"</js>) 208 * ) 209 * ); 210 * 211 * <jc>// Produces: "foo=bar,baz=qux\,true\,123"</jc> 212 * String <jv>value1</jv> = <jv>serializer1</jv>.serialize(<jv>list</jv>) 213 * 214 * <jc>// Produces: "(foo=bar,baz=@(qux,'true','123'))"</jc> 215 * String <jv>value2</jv> = <jv>serializer2</jv>.serialize(<jv>list</jv>) 216 * </p> 217 * 218 * <ul class='values javatree'> 219 * <li class='jc'>{@link org.apache.juneau.httppart.HttpPartFormat} 220 * <ul> 221 * <li class='jf'>{@link org.apache.juneau.httppart.HttpPartCollectionFormat#CSV CSV} - (default) Comma-separated values (e.g. <js>"foo,bar"</js>). 222 * <li class='jf'>{@link org.apache.juneau.httppart.HttpPartCollectionFormat#SSV SSV} - Space-separated values (e.g. <js>"foo bar"</js>). 223 * <li class='jf'>{@link org.apache.juneau.httppart.HttpPartCollectionFormat#TSV TSV} - Tab-separated values (e.g. <js>"foo\tbar"</js>). 224 * <li class='jf'>{@link org.apache.juneau.httppart.HttpPartCollectionFormat#PIPES PIPES} - Pipe-separated values (e.g. <js>"foo|bar"</js>). 225 * <li class='jf'>{@link org.apache.juneau.httppart.HttpPartCollectionFormat#MULTI MULTI} - Corresponds to multiple parameter instances instead of multiple values for a single instance (e.g. <js>"foo=bar&foo=baz"</js>). 226 * <li class='jf'>{@link org.apache.juneau.httppart.HttpPartCollectionFormat#UONC UONC} - UON collection notation (e.g. <js>"@(foo,bar)"</js>). 227 * </ul> 228 * </ul> 229 * 230 * @param value The new value for this property. 231 * @return This object. 232 */ 233 @FluentSetter 234 public Builder collectionFormat(HttpPartCollectionFormat value) { 235 collectionFormat = value; 236 return this; 237 } 238 239 // <FluentSetters> 240 241 @Override /* GENERATED - org.apache.juneau.Context.Builder */ 242 public Builder annotations(Annotation...values) { 243 super.annotations(values); 244 return this; 245 } 246 247 @Override /* GENERATED - org.apache.juneau.Context.Builder */ 248 public Builder apply(AnnotationWorkList work) { 249 super.apply(work); 250 return this; 251 } 252 253 @Override /* GENERATED - org.apache.juneau.Context.Builder */ 254 public Builder applyAnnotations(java.lang.Class<?>...fromClasses) { 255 super.applyAnnotations(fromClasses); 256 return this; 257 } 258 259 @Override /* GENERATED - org.apache.juneau.Context.Builder */ 260 public Builder applyAnnotations(Method...fromMethods) { 261 super.applyAnnotations(fromMethods); 262 return this; 263 } 264 265 @Override /* GENERATED - org.apache.juneau.Context.Builder */ 266 public Builder cache(Cache<HashKey,? extends org.apache.juneau.Context> value) { 267 super.cache(value); 268 return this; 269 } 270 271 @Override /* GENERATED - org.apache.juneau.Context.Builder */ 272 public Builder debug() { 273 super.debug(); 274 return this; 275 } 276 277 @Override /* GENERATED - org.apache.juneau.Context.Builder */ 278 public Builder debug(boolean value) { 279 super.debug(value); 280 return this; 281 } 282 283 @Override /* GENERATED - org.apache.juneau.Context.Builder */ 284 public Builder impl(Context value) { 285 super.impl(value); 286 return this; 287 } 288 289 @Override /* GENERATED - org.apache.juneau.Context.Builder */ 290 public Builder type(Class<? extends org.apache.juneau.Context> value) { 291 super.type(value); 292 return this; 293 } 294 295 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 296 public Builder beanClassVisibility(Visibility value) { 297 super.beanClassVisibility(value); 298 return this; 299 } 300 301 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 302 public Builder beanConstructorVisibility(Visibility value) { 303 super.beanConstructorVisibility(value); 304 return this; 305 } 306 307 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 308 public Builder beanContext(BeanContext value) { 309 super.beanContext(value); 310 return this; 311 } 312 313 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 314 public Builder beanContext(BeanContext.Builder value) { 315 super.beanContext(value); 316 return this; 317 } 318 319 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 320 public Builder beanDictionary(java.lang.Class<?>...values) { 321 super.beanDictionary(values); 322 return this; 323 } 324 325 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 326 public Builder beanFieldVisibility(Visibility value) { 327 super.beanFieldVisibility(value); 328 return this; 329 } 330 331 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 332 public Builder beanInterceptor(Class<?> on, Class<? extends org.apache.juneau.swap.BeanInterceptor<?>> value) { 333 super.beanInterceptor(on, value); 334 return this; 335 } 336 337 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 338 public Builder beanMapPutReturnsOldValue() { 339 super.beanMapPutReturnsOldValue(); 340 return this; 341 } 342 343 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 344 public Builder beanMethodVisibility(Visibility value) { 345 super.beanMethodVisibility(value); 346 return this; 347 } 348 349 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 350 public Builder beanProperties(Map<String,Object> values) { 351 super.beanProperties(values); 352 return this; 353 } 354 355 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 356 public Builder beanProperties(Class<?> beanClass, String properties) { 357 super.beanProperties(beanClass, properties); 358 return this; 359 } 360 361 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 362 public Builder beanProperties(String beanClassName, String properties) { 363 super.beanProperties(beanClassName, properties); 364 return this; 365 } 366 367 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 368 public Builder beanPropertiesExcludes(Map<String,Object> values) { 369 super.beanPropertiesExcludes(values); 370 return this; 371 } 372 373 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 374 public Builder beanPropertiesExcludes(Class<?> beanClass, String properties) { 375 super.beanPropertiesExcludes(beanClass, properties); 376 return this; 377 } 378 379 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 380 public Builder beanPropertiesExcludes(String beanClassName, String properties) { 381 super.beanPropertiesExcludes(beanClassName, properties); 382 return this; 383 } 384 385 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 386 public Builder beanPropertiesReadOnly(Map<String,Object> values) { 387 super.beanPropertiesReadOnly(values); 388 return this; 389 } 390 391 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 392 public Builder beanPropertiesReadOnly(Class<?> beanClass, String properties) { 393 super.beanPropertiesReadOnly(beanClass, properties); 394 return this; 395 } 396 397 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 398 public Builder beanPropertiesReadOnly(String beanClassName, String properties) { 399 super.beanPropertiesReadOnly(beanClassName, properties); 400 return this; 401 } 402 403 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 404 public Builder beanPropertiesWriteOnly(Map<String,Object> values) { 405 super.beanPropertiesWriteOnly(values); 406 return this; 407 } 408 409 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 410 public Builder beanPropertiesWriteOnly(Class<?> beanClass, String properties) { 411 super.beanPropertiesWriteOnly(beanClass, properties); 412 return this; 413 } 414 415 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 416 public Builder beanPropertiesWriteOnly(String beanClassName, String properties) { 417 super.beanPropertiesWriteOnly(beanClassName, properties); 418 return this; 419 } 420 421 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 422 public Builder beansRequireDefaultConstructor() { 423 super.beansRequireDefaultConstructor(); 424 return this; 425 } 426 427 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 428 public Builder beansRequireSerializable() { 429 super.beansRequireSerializable(); 430 return this; 431 } 432 433 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 434 public Builder beansRequireSettersForGetters() { 435 super.beansRequireSettersForGetters(); 436 return this; 437 } 438 439 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 440 public Builder dictionaryOn(Class<?> on, java.lang.Class<?>...values) { 441 super.dictionaryOn(on, values); 442 return this; 443 } 444 445 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 446 public Builder disableBeansRequireSomeProperties() { 447 super.disableBeansRequireSomeProperties(); 448 return this; 449 } 450 451 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 452 public Builder disableIgnoreMissingSetters() { 453 super.disableIgnoreMissingSetters(); 454 return this; 455 } 456 457 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 458 public Builder disableIgnoreTransientFields() { 459 super.disableIgnoreTransientFields(); 460 return this; 461 } 462 463 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 464 public Builder disableIgnoreUnknownNullBeanProperties() { 465 super.disableIgnoreUnknownNullBeanProperties(); 466 return this; 467 } 468 469 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 470 public Builder disableInterfaceProxies() { 471 super.disableInterfaceProxies(); 472 return this; 473 } 474 475 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 476 public <T> Builder example(Class<T> pojoClass, T o) { 477 super.example(pojoClass, o); 478 return this; 479 } 480 481 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 482 public <T> Builder example(Class<T> pojoClass, String json) { 483 super.example(pojoClass, json); 484 return this; 485 } 486 487 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 488 public Builder findFluentSetters() { 489 super.findFluentSetters(); 490 return this; 491 } 492 493 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 494 public Builder findFluentSetters(Class<?> on) { 495 super.findFluentSetters(on); 496 return this; 497 } 498 499 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 500 public Builder ignoreInvocationExceptionsOnGetters() { 501 super.ignoreInvocationExceptionsOnGetters(); 502 return this; 503 } 504 505 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 506 public Builder ignoreInvocationExceptionsOnSetters() { 507 super.ignoreInvocationExceptionsOnSetters(); 508 return this; 509 } 510 511 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 512 public Builder ignoreUnknownBeanProperties() { 513 super.ignoreUnknownBeanProperties(); 514 return this; 515 } 516 517 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 518 public Builder ignoreUnknownEnumValues() { 519 super.ignoreUnknownEnumValues(); 520 return this; 521 } 522 523 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 524 public Builder implClass(Class<?> interfaceClass, Class<?> implClass) { 525 super.implClass(interfaceClass, implClass); 526 return this; 527 } 528 529 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 530 public Builder implClasses(Map<Class<?>,Class<?>> values) { 531 super.implClasses(values); 532 return this; 533 } 534 535 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 536 public Builder interfaceClass(Class<?> on, Class<?> value) { 537 super.interfaceClass(on, value); 538 return this; 539 } 540 541 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 542 public Builder interfaces(java.lang.Class<?>...value) { 543 super.interfaces(value); 544 return this; 545 } 546 547 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 548 public Builder locale(Locale value) { 549 super.locale(value); 550 return this; 551 } 552 553 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 554 public Builder mediaType(MediaType value) { 555 super.mediaType(value); 556 return this; 557 } 558 559 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 560 public Builder notBeanClasses(java.lang.Class<?>...values) { 561 super.notBeanClasses(values); 562 return this; 563 } 564 565 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 566 public Builder notBeanPackages(String...values) { 567 super.notBeanPackages(values); 568 return this; 569 } 570 571 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 572 public Builder propertyNamer(Class<? extends org.apache.juneau.PropertyNamer> value) { 573 super.propertyNamer(value); 574 return this; 575 } 576 577 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 578 public Builder propertyNamer(Class<?> on, Class<? extends org.apache.juneau.PropertyNamer> value) { 579 super.propertyNamer(on, value); 580 return this; 581 } 582 583 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 584 public Builder sortProperties() { 585 super.sortProperties(); 586 return this; 587 } 588 589 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 590 public Builder sortProperties(java.lang.Class<?>...on) { 591 super.sortProperties(on); 592 return this; 593 } 594 595 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 596 public Builder stopClass(Class<?> on, Class<?> value) { 597 super.stopClass(on, value); 598 return this; 599 } 600 601 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 602 public <T, S> Builder swap(Class<T> normalClass, Class<S> swappedClass, ThrowingFunction<T,S> swapFunction) { 603 super.swap(normalClass, swappedClass, swapFunction); 604 return this; 605 } 606 607 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 608 public <T, S> Builder swap(Class<T> normalClass, Class<S> swappedClass, ThrowingFunction<T,S> swapFunction, ThrowingFunction<S,T> unswapFunction) { 609 super.swap(normalClass, swappedClass, swapFunction, unswapFunction); 610 return this; 611 } 612 613 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 614 public Builder swaps(java.lang.Class<?>...values) { 615 super.swaps(values); 616 return this; 617 } 618 619 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 620 public Builder timeZone(TimeZone value) { 621 super.timeZone(value); 622 return this; 623 } 624 625 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 626 public Builder typeName(Class<?> on, String value) { 627 super.typeName(on, value); 628 return this; 629 } 630 631 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 632 public Builder typePropertyName(String value) { 633 super.typePropertyName(value); 634 return this; 635 } 636 637 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 638 public Builder typePropertyName(Class<?> on, String value) { 639 super.typePropertyName(on, value); 640 return this; 641 } 642 643 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 644 public Builder useEnumNames() { 645 super.useEnumNames(); 646 return this; 647 } 648 649 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 650 public Builder useJavaBeanIntrospector() { 651 super.useJavaBeanIntrospector(); 652 return this; 653 } 654 655 @Override /* GENERATED - org.apache.juneau.BeanTraverseContext.Builder */ 656 public Builder detectRecursions() { 657 super.detectRecursions(); 658 return this; 659 } 660 661 @Override /* GENERATED - org.apache.juneau.BeanTraverseContext.Builder */ 662 public Builder detectRecursions(boolean value) { 663 super.detectRecursions(value); 664 return this; 665 } 666 667 @Override /* GENERATED - org.apache.juneau.BeanTraverseContext.Builder */ 668 public Builder ignoreRecursions() { 669 super.ignoreRecursions(); 670 return this; 671 } 672 673 @Override /* GENERATED - org.apache.juneau.BeanTraverseContext.Builder */ 674 public Builder ignoreRecursions(boolean value) { 675 super.ignoreRecursions(value); 676 return this; 677 } 678 679 @Override /* GENERATED - org.apache.juneau.BeanTraverseContext.Builder */ 680 public Builder initialDepth(int value) { 681 super.initialDepth(value); 682 return this; 683 } 684 685 @Override /* GENERATED - org.apache.juneau.BeanTraverseContext.Builder */ 686 public Builder maxDepth(int value) { 687 super.maxDepth(value); 688 return this; 689 } 690 691 @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */ 692 public Builder accept(String value) { 693 super.accept(value); 694 return this; 695 } 696 697 @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */ 698 public Builder addBeanTypes() { 699 super.addBeanTypes(); 700 return this; 701 } 702 703 @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */ 704 public Builder addBeanTypes(boolean value) { 705 super.addBeanTypes(value); 706 return this; 707 } 708 709 @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */ 710 public Builder addRootType() { 711 super.addRootType(); 712 return this; 713 } 714 715 @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */ 716 public Builder addRootType(boolean value) { 717 super.addRootType(value); 718 return this; 719 } 720 721 @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */ 722 public Builder keepNullProperties() { 723 super.keepNullProperties(); 724 return this; 725 } 726 727 @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */ 728 public Builder keepNullProperties(boolean value) { 729 super.keepNullProperties(value); 730 return this; 731 } 732 733 @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */ 734 public Builder listener(Class<? extends org.apache.juneau.serializer.SerializerListener> value) { 735 super.listener(value); 736 return this; 737 } 738 739 @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */ 740 public Builder produces(String value) { 741 super.produces(value); 742 return this; 743 } 744 745 @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */ 746 public Builder sortCollections() { 747 super.sortCollections(); 748 return this; 749 } 750 751 @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */ 752 public Builder sortCollections(boolean value) { 753 super.sortCollections(value); 754 return this; 755 } 756 757 @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */ 758 public Builder sortMaps() { 759 super.sortMaps(); 760 return this; 761 } 762 763 @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */ 764 public Builder sortMaps(boolean value) { 765 super.sortMaps(value); 766 return this; 767 } 768 769 @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */ 770 public Builder trimEmptyCollections() { 771 super.trimEmptyCollections(); 772 return this; 773 } 774 775 @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */ 776 public Builder trimEmptyCollections(boolean value) { 777 super.trimEmptyCollections(value); 778 return this; 779 } 780 781 @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */ 782 public Builder trimEmptyMaps() { 783 super.trimEmptyMaps(); 784 return this; 785 } 786 787 @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */ 788 public Builder trimEmptyMaps(boolean value) { 789 super.trimEmptyMaps(value); 790 return this; 791 } 792 793 @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */ 794 public Builder trimStrings() { 795 super.trimStrings(); 796 return this; 797 } 798 799 @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */ 800 public Builder trimStrings(boolean value) { 801 super.trimStrings(value); 802 return this; 803 } 804 805 @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */ 806 public Builder uriContext(UriContext value) { 807 super.uriContext(value); 808 return this; 809 } 810 811 @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */ 812 public Builder uriRelativity(UriRelativity value) { 813 super.uriRelativity(value); 814 return this; 815 } 816 817 @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */ 818 public Builder uriResolution(UriResolution value) { 819 super.uriResolution(value); 820 return this; 821 } 822 823 @Override /* GENERATED - org.apache.juneau.serializer.WriterSerializer.Builder */ 824 public Builder fileCharset(Charset value) { 825 super.fileCharset(value); 826 return this; 827 } 828 829 @Override /* GENERATED - org.apache.juneau.serializer.WriterSerializer.Builder */ 830 public Builder maxIndent(int value) { 831 super.maxIndent(value); 832 return this; 833 } 834 835 @Override /* GENERATED - org.apache.juneau.serializer.WriterSerializer.Builder */ 836 public Builder quoteChar(char value) { 837 super.quoteChar(value); 838 return this; 839 } 840 841 @Override /* GENERATED - org.apache.juneau.serializer.WriterSerializer.Builder */ 842 public Builder quoteCharOverride(char value) { 843 super.quoteCharOverride(value); 844 return this; 845 } 846 847 @Override /* GENERATED - org.apache.juneau.serializer.WriterSerializer.Builder */ 848 public Builder sq() { 849 super.sq(); 850 return this; 851 } 852 853 @Override /* GENERATED - org.apache.juneau.serializer.WriterSerializer.Builder */ 854 public Builder streamCharset(Charset value) { 855 super.streamCharset(value); 856 return this; 857 } 858 859 @Override /* GENERATED - org.apache.juneau.serializer.WriterSerializer.Builder */ 860 public Builder useWhitespace() { 861 super.useWhitespace(); 862 return this; 863 } 864 865 @Override /* GENERATED - org.apache.juneau.serializer.WriterSerializer.Builder */ 866 public Builder useWhitespace(boolean value) { 867 super.useWhitespace(value); 868 return this; 869 } 870 871 @Override /* GENERATED - org.apache.juneau.serializer.WriterSerializer.Builder */ 872 public Builder ws() { 873 super.ws(); 874 return this; 875 } 876 877 @Override /* GENERATED - org.apache.juneau.uon.UonSerializer.Builder */ 878 public Builder addBeanTypesUon() { 879 super.addBeanTypesUon(); 880 return this; 881 } 882 883 @Override /* GENERATED - org.apache.juneau.uon.UonSerializer.Builder */ 884 public Builder addBeanTypesUon(boolean value) { 885 super.addBeanTypesUon(value); 886 return this; 887 } 888 889 @Override /* GENERATED - org.apache.juneau.uon.UonSerializer.Builder */ 890 public Builder encoding() { 891 super.encoding(); 892 return this; 893 } 894 895 @Override /* GENERATED - org.apache.juneau.uon.UonSerializer.Builder */ 896 public Builder paramFormat(ParamFormat value) { 897 super.paramFormat(value); 898 return this; 899 } 900 901 @Override /* GENERATED - org.apache.juneau.uon.UonSerializer.Builder */ 902 public Builder paramFormatPlain() { 903 super.paramFormatPlain(); 904 return this; 905 } 906 907 @Override /* GENERATED - org.apache.juneau.uon.UonSerializer.Builder */ 908 public Builder quoteCharUon(char value) { 909 super.quoteCharUon(value); 910 return this; 911 } 912 913 // </FluentSetters> 914 } 915 916 //------------------------------------------------------------------------------------------------------------------- 917 // Instance 918 //------------------------------------------------------------------------------------------------------------------- 919 920 final HttpPartFormat format; 921 final HttpPartCollectionFormat collectionFormat; 922 923 private final Map<ClassMeta<?>,OpenApiClassMeta> openApiClassMetas = new ConcurrentHashMap<>(); 924 private final Map<BeanPropertyMeta,OpenApiBeanPropertyMeta> openApiBeanPropertyMetas = new ConcurrentHashMap<>(); 925 926 /** 927 * Constructor. 928 * 929 * @param builder 930 * The builder for this object. 931 */ 932 public OpenApiSerializer(Builder builder) { 933 super(builder.encoding(false)); 934 format = builder.format; 935 collectionFormat = builder.collectionFormat; 936 } 937 938 @Override /* Context */ 939 public Builder copy() { 940 return new Builder(this); 941 } 942 943 @Override /* Context */ 944 public OpenApiSerializerSession.Builder createSession() { 945 return OpenApiSerializerSession.create(this); 946 } 947 948 @Override /* Context */ 949 public OpenApiSerializerSession getSession() { 950 return createSession().build(); 951 } 952 953 @Override /* HttpPartSerializer */ 954 public OpenApiSerializerSession getPartSession() { 955 return OpenApiSerializerSession.create(this).build(); 956 } 957 958 //----------------------------------------------------------------------------------------------------------------- 959 // Extended metadata 960 //----------------------------------------------------------------------------------------------------------------- 961 962 @Override /* OpenApiMetaProvider */ 963 public OpenApiClassMeta getOpenApiClassMeta(ClassMeta<?> cm) { 964 OpenApiClassMeta m = openApiClassMetas.get(cm); 965 if (m == null) { 966 m = new OpenApiClassMeta(cm, this); 967 openApiClassMetas.put(cm, m); 968 } 969 return m; 970 } 971 972 @Override /* OpenApiMetaProvider */ 973 public OpenApiBeanPropertyMeta getOpenApiBeanPropertyMeta(BeanPropertyMeta bpm) { 974 if (bpm == null) 975 return OpenApiBeanPropertyMeta.DEFAULT; 976 OpenApiBeanPropertyMeta m = openApiBeanPropertyMetas.get(bpm); 977 if (m == null) { 978 m = new OpenApiBeanPropertyMeta(bpm.getDelegateFor(), this); 979 openApiBeanPropertyMetas.put(bpm, m); 980 } 981 return m; 982 } 983 984 //----------------------------------------------------------------------------------------------------------------- 985 // Properties 986 //----------------------------------------------------------------------------------------------------------------- 987 988 /** 989 * Returns the default format to use when not otherwise specified via {@link Schema#format()} 990 * 991 * @return The default format to use when not otherwise specified via {@link Schema#format()} 992 */ 993 protected final HttpPartFormat getFormat() { 994 return format; 995 } 996 997 /** 998 * Returns the default collection format to use when not otherwise specified via {@link Schema#collectionFormat()} 999 * 1000 * @return The default collection format to use when not otherwise specified via {@link Schema#collectionFormat()} 1001 */ 1002 protected final HttpPartCollectionFormat getCollectionFormat() { 1003 return collectionFormat; 1004 } 1005}