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