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.msgpack;
014
015import static org.apache.juneau.collections.JsonMap.*;
016
017import java.lang.annotation.*;
018import java.lang.reflect.*;
019import java.util.*;
020import java.util.concurrent.*;
021
022import org.apache.juneau.*;
023import org.apache.juneau.collections.*;
024import org.apache.juneau.internal.*;
025import org.apache.juneau.serializer.*;
026import org.apache.juneau.utils.*;
027
028/**
029 * Serializes POJO models to MessagePack.
030 *
031 * <h5 class='section'>Media types:</h5>
032 *
033 * Handles <c>Accept</c> types:  <bc>octal/msgpack</bc>
034 * <p>
035 * Produces <c>Content-Type</c> types: <bc>octal/msgpack</bc>
036 *
037 * <h5 class='section'>Notes:</h5><ul>
038 *    <li class='note'>This class is thread safe and reusable.
039 * </ul>
040 *
041 * <h5 class='section'>See Also:</h5><ul>
042 *    <li class='link'><a class="doclink" href="../../../../index.html#jm.MsgPackDetails">MessagePack Details</a>
043
044 * </ul>
045 */
046public class MsgPackSerializer extends OutputStreamSerializer implements MsgPackMetaProvider {
047
048   //-------------------------------------------------------------------------------------------------------------------
049   // Static
050   //-------------------------------------------------------------------------------------------------------------------
051
052   /** Default serializer, all default settings.*/
053   public static final MsgPackSerializer DEFAULT = new MsgPackSerializer(create());
054
055   /** Default serializer, all default settings, spaced-hex string output.*/
056   public static final MsgPackSerializer DEFAULT_SPACED_HEX = new SpacedHex(create());
057
058   /** Default serializer, all default settings, spaced-hex string output.*/
059   public static final MsgPackSerializer DEFAULT_BASE64 = new Base64(create());
060
061   /**
062    * Creates a new builder for this object.
063    *
064    * @return A new builder.
065    */
066   public static Builder create() {
067      return new Builder();
068   }
069
070   //-------------------------------------------------------------------------------------------------------------------
071   // Static subclasses
072   //-------------------------------------------------------------------------------------------------------------------
073
074   /** Default serializer, spaced-hex string output. */
075   public static class SpacedHex extends MsgPackSerializer {
076
077      /**
078       * Constructor.
079       *
080       * @param builder The builder for this object.
081       */
082      public SpacedHex(Builder builder) {
083         super(builder.binaryFormat(BinaryFormat.SPACED_HEX));
084      }
085   }
086
087   /** Default serializer, BASE64 string output. */
088   public static class Base64 extends MsgPackSerializer {
089
090      /**
091       * Constructor.
092       *
093       * @param builder The builder for this object.
094       */
095      public Base64(Builder builder) {
096         super(builder.binaryFormat(BinaryFormat.BASE64));
097      }
098   }
099
100   //-------------------------------------------------------------------------------------------------------------------
101   // Builder
102   //-------------------------------------------------------------------------------------------------------------------
103
104   /**
105    * Builder class.
106    */
107   @FluentSetters
108   public static class Builder extends OutputStreamSerializer.Builder {
109
110      private static final Cache<HashKey,MsgPackSerializer> CACHE = Cache.of(HashKey.class, MsgPackSerializer.class).build();
111
112      boolean addBeanTypesMsgPack;
113
114      /**
115       * Constructor, default settings.
116       */
117      protected Builder() {
118         produces("octal/msgpack");
119         addBeanTypesMsgPack = env("MsgPackSerializer.addBeanTypesMsgPack", false);
120      }
121
122      /**
123       * Copy constructor.
124       *
125       * @param copyFrom The bean to copy from.
126       */
127      protected Builder(MsgPackSerializer copyFrom) {
128         super(copyFrom);
129      }
130
131      /**
132       * Copy constructor.
133       *
134       * @param copyFrom The builder to copy from.
135       */
136      protected Builder(Builder copyFrom) {
137         super(copyFrom);
138      }
139
140      @Override /* Context.Builder */
141      public Builder copy() {
142         return new Builder(this);
143      }
144
145      @Override /* Context.Builder */
146      public MsgPackSerializer build() {
147         return cache(CACHE).build(MsgPackSerializer.class);
148      }
149
150      @Override /* Context.Builder */
151      public HashKey hashKey() {
152         return HashKey.of(
153            super.hashKey(),
154            addBeanTypesMsgPack
155         );
156      }
157
158      //-----------------------------------------------------------------------------------------------------------------
159      // Properties
160      //-----------------------------------------------------------------------------------------------------------------
161
162      /**
163       * Add <js>"_type"</js> properties when needed.
164       *
165       * <p>
166       * If <jk>true</jk>, then <js>"_type"</js> properties will be added to beans if their type cannot be inferred
167       * through reflection.
168       *
169       * <p>
170       * When present, this value overrides the {@link org.apache.juneau.serializer.Serializer.Builder#addBeanTypes()} setting and is
171       * provided to customize the behavior of specific serializers in a {@link SerializerSet}.
172       *
173       * @return This object.
174       */
175      @FluentSetter
176      public Builder addBeanTypesMsgPack() {
177         return addBeanTypesMsgPack(true);
178      }
179
180      /**
181       * Same as {@link #addBeanTypesMsgPack()} but allows you to explicitly specify the value.
182       *
183       * @param value The value for this setting.
184       * @return This object.
185       */
186      @FluentSetter
187      public Builder addBeanTypesMsgPack(boolean value) {
188         addBeanTypesMsgPack = value;
189         return this;
190      }
191
192      // <FluentSetters>
193
194      @Override /* GENERATED - org.apache.juneau.Context.Builder */
195      public Builder annotations(Annotation...values) {
196         super.annotations(values);
197         return this;
198      }
199
200      @Override /* GENERATED - org.apache.juneau.Context.Builder */
201      public Builder apply(AnnotationWorkList work) {
202         super.apply(work);
203         return this;
204      }
205
206      @Override /* GENERATED - org.apache.juneau.Context.Builder */
207      public Builder applyAnnotations(java.lang.Class<?>...fromClasses) {
208         super.applyAnnotations(fromClasses);
209         return this;
210      }
211
212      @Override /* GENERATED - org.apache.juneau.Context.Builder */
213      public Builder applyAnnotations(Method...fromMethods) {
214         super.applyAnnotations(fromMethods);
215         return this;
216      }
217
218      @Override /* GENERATED - org.apache.juneau.Context.Builder */
219      public Builder cache(Cache<HashKey,? extends org.apache.juneau.Context> value) {
220         super.cache(value);
221         return this;
222      }
223
224      @Override /* GENERATED - org.apache.juneau.Context.Builder */
225      public Builder debug() {
226         super.debug();
227         return this;
228      }
229
230      @Override /* GENERATED - org.apache.juneau.Context.Builder */
231      public Builder debug(boolean value) {
232         super.debug(value);
233         return this;
234      }
235
236      @Override /* GENERATED - org.apache.juneau.Context.Builder */
237      public Builder impl(Context value) {
238         super.impl(value);
239         return this;
240      }
241
242      @Override /* GENERATED - org.apache.juneau.Context.Builder */
243      public Builder type(Class<? extends org.apache.juneau.Context> value) {
244         super.type(value);
245         return this;
246      }
247
248      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
249      public Builder beanClassVisibility(Visibility value) {
250         super.beanClassVisibility(value);
251         return this;
252      }
253
254      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
255      public Builder beanConstructorVisibility(Visibility value) {
256         super.beanConstructorVisibility(value);
257         return this;
258      }
259
260      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
261      public Builder beanContext(BeanContext value) {
262         super.beanContext(value);
263         return this;
264      }
265
266      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
267      public Builder beanContext(BeanContext.Builder value) {
268         super.beanContext(value);
269         return this;
270      }
271
272      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
273      public Builder beanDictionary(java.lang.Class<?>...values) {
274         super.beanDictionary(values);
275         return this;
276      }
277
278      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
279      public Builder beanFieldVisibility(Visibility value) {
280         super.beanFieldVisibility(value);
281         return this;
282      }
283
284      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
285      public Builder beanInterceptor(Class<?> on, Class<? extends org.apache.juneau.swap.BeanInterceptor<?>> value) {
286         super.beanInterceptor(on, value);
287         return this;
288      }
289
290      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
291      public Builder beanMapPutReturnsOldValue() {
292         super.beanMapPutReturnsOldValue();
293         return this;
294      }
295
296      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
297      public Builder beanMethodVisibility(Visibility value) {
298         super.beanMethodVisibility(value);
299         return this;
300      }
301
302      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
303      public Builder beanProperties(Map<String,Object> values) {
304         super.beanProperties(values);
305         return this;
306      }
307
308      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
309      public Builder beanProperties(Class<?> beanClass, String properties) {
310         super.beanProperties(beanClass, properties);
311         return this;
312      }
313
314      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
315      public Builder beanProperties(String beanClassName, String properties) {
316         super.beanProperties(beanClassName, properties);
317         return this;
318      }
319
320      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
321      public Builder beanPropertiesExcludes(Map<String,Object> values) {
322         super.beanPropertiesExcludes(values);
323         return this;
324      }
325
326      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
327      public Builder beanPropertiesExcludes(Class<?> beanClass, String properties) {
328         super.beanPropertiesExcludes(beanClass, properties);
329         return this;
330      }
331
332      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
333      public Builder beanPropertiesExcludes(String beanClassName, String properties) {
334         super.beanPropertiesExcludes(beanClassName, properties);
335         return this;
336      }
337
338      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
339      public Builder beanPropertiesReadOnly(Map<String,Object> values) {
340         super.beanPropertiesReadOnly(values);
341         return this;
342      }
343
344      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
345      public Builder beanPropertiesReadOnly(Class<?> beanClass, String properties) {
346         super.beanPropertiesReadOnly(beanClass, properties);
347         return this;
348      }
349
350      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
351      public Builder beanPropertiesReadOnly(String beanClassName, String properties) {
352         super.beanPropertiesReadOnly(beanClassName, properties);
353         return this;
354      }
355
356      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
357      public Builder beanPropertiesWriteOnly(Map<String,Object> values) {
358         super.beanPropertiesWriteOnly(values);
359         return this;
360      }
361
362      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
363      public Builder beanPropertiesWriteOnly(Class<?> beanClass, String properties) {
364         super.beanPropertiesWriteOnly(beanClass, properties);
365         return this;
366      }
367
368      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
369      public Builder beanPropertiesWriteOnly(String beanClassName, String properties) {
370         super.beanPropertiesWriteOnly(beanClassName, properties);
371         return this;
372      }
373
374      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
375      public Builder beansRequireDefaultConstructor() {
376         super.beansRequireDefaultConstructor();
377         return this;
378      }
379
380      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
381      public Builder beansRequireSerializable() {
382         super.beansRequireSerializable();
383         return this;
384      }
385
386      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
387      public Builder beansRequireSettersForGetters() {
388         super.beansRequireSettersForGetters();
389         return this;
390      }
391
392      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
393      public Builder dictionaryOn(Class<?> on, java.lang.Class<?>...values) {
394         super.dictionaryOn(on, values);
395         return this;
396      }
397
398      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
399      public Builder disableBeansRequireSomeProperties() {
400         super.disableBeansRequireSomeProperties();
401         return this;
402      }
403
404      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
405      public Builder disableIgnoreMissingSetters() {
406         super.disableIgnoreMissingSetters();
407         return this;
408      }
409
410      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
411      public Builder disableIgnoreTransientFields() {
412         super.disableIgnoreTransientFields();
413         return this;
414      }
415
416      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
417      public Builder disableIgnoreUnknownNullBeanProperties() {
418         super.disableIgnoreUnknownNullBeanProperties();
419         return this;
420      }
421
422      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
423      public Builder disableInterfaceProxies() {
424         super.disableInterfaceProxies();
425         return this;
426      }
427
428      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
429      public <T> Builder example(Class<T> pojoClass, T o) {
430         super.example(pojoClass, o);
431         return this;
432      }
433
434      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
435      public <T> Builder example(Class<T> pojoClass, String json) {
436         super.example(pojoClass, json);
437         return this;
438      }
439
440      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
441      public Builder findFluentSetters() {
442         super.findFluentSetters();
443         return this;
444      }
445
446      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
447      public Builder findFluentSetters(Class<?> on) {
448         super.findFluentSetters(on);
449         return this;
450      }
451
452      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
453      public Builder ignoreInvocationExceptionsOnGetters() {
454         super.ignoreInvocationExceptionsOnGetters();
455         return this;
456      }
457
458      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
459      public Builder ignoreInvocationExceptionsOnSetters() {
460         super.ignoreInvocationExceptionsOnSetters();
461         return this;
462      }
463
464      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
465      public Builder ignoreUnknownBeanProperties() {
466         super.ignoreUnknownBeanProperties();
467         return this;
468      }
469
470      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
471      public Builder ignoreUnknownEnumValues() {
472         super.ignoreUnknownEnumValues();
473         return this;
474      }
475
476      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
477      public Builder implClass(Class<?> interfaceClass, Class<?> implClass) {
478         super.implClass(interfaceClass, implClass);
479         return this;
480      }
481
482      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
483      public Builder implClasses(Map<Class<?>,Class<?>> values) {
484         super.implClasses(values);
485         return this;
486      }
487
488      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
489      public Builder interfaceClass(Class<?> on, Class<?> value) {
490         super.interfaceClass(on, value);
491         return this;
492      }
493
494      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
495      public Builder interfaces(java.lang.Class<?>...value) {
496         super.interfaces(value);
497         return this;
498      }
499
500      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
501      public Builder locale(Locale value) {
502         super.locale(value);
503         return this;
504      }
505
506      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
507      public Builder mediaType(MediaType value) {
508         super.mediaType(value);
509         return this;
510      }
511
512      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
513      public Builder notBeanClasses(java.lang.Class<?>...values) {
514         super.notBeanClasses(values);
515         return this;
516      }
517
518      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
519      public Builder notBeanPackages(String...values) {
520         super.notBeanPackages(values);
521         return this;
522      }
523
524      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
525      public Builder propertyNamer(Class<? extends org.apache.juneau.PropertyNamer> value) {
526         super.propertyNamer(value);
527         return this;
528      }
529
530      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
531      public Builder propertyNamer(Class<?> on, Class<? extends org.apache.juneau.PropertyNamer> value) {
532         super.propertyNamer(on, value);
533         return this;
534      }
535
536      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
537      public Builder sortProperties() {
538         super.sortProperties();
539         return this;
540      }
541
542      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
543      public Builder sortProperties(java.lang.Class<?>...on) {
544         super.sortProperties(on);
545         return this;
546      }
547
548      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
549      public Builder stopClass(Class<?> on, Class<?> value) {
550         super.stopClass(on, value);
551         return this;
552      }
553
554      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
555      public <T, S> Builder swap(Class<T> normalClass, Class<S> swappedClass, ThrowingFunction<T,S> swapFunction) {
556         super.swap(normalClass, swappedClass, swapFunction);
557         return this;
558      }
559
560      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
561      public <T, S> Builder swap(Class<T> normalClass, Class<S> swappedClass, ThrowingFunction<T,S> swapFunction, ThrowingFunction<S,T> unswapFunction) {
562         super.swap(normalClass, swappedClass, swapFunction, unswapFunction);
563         return this;
564      }
565
566      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
567      public Builder swaps(java.lang.Class<?>...values) {
568         super.swaps(values);
569         return this;
570      }
571
572      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
573      public Builder timeZone(TimeZone value) {
574         super.timeZone(value);
575         return this;
576      }
577
578      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
579      public Builder typeName(Class<?> on, String value) {
580         super.typeName(on, value);
581         return this;
582      }
583
584      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
585      public Builder typePropertyName(String value) {
586         super.typePropertyName(value);
587         return this;
588      }
589
590      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
591      public Builder typePropertyName(Class<?> on, String value) {
592         super.typePropertyName(on, value);
593         return this;
594      }
595
596      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
597      public Builder useEnumNames() {
598         super.useEnumNames();
599         return this;
600      }
601
602      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
603      public Builder useJavaBeanIntrospector() {
604         super.useJavaBeanIntrospector();
605         return this;
606      }
607
608      @Override /* GENERATED - org.apache.juneau.BeanTraverseContext.Builder */
609      public Builder detectRecursions() {
610         super.detectRecursions();
611         return this;
612      }
613
614      @Override /* GENERATED - org.apache.juneau.BeanTraverseContext.Builder */
615      public Builder detectRecursions(boolean value) {
616         super.detectRecursions(value);
617         return this;
618      }
619
620      @Override /* GENERATED - org.apache.juneau.BeanTraverseContext.Builder */
621      public Builder ignoreRecursions() {
622         super.ignoreRecursions();
623         return this;
624      }
625
626      @Override /* GENERATED - org.apache.juneau.BeanTraverseContext.Builder */
627      public Builder ignoreRecursions(boolean value) {
628         super.ignoreRecursions(value);
629         return this;
630      }
631
632      @Override /* GENERATED - org.apache.juneau.BeanTraverseContext.Builder */
633      public Builder initialDepth(int value) {
634         super.initialDepth(value);
635         return this;
636      }
637
638      @Override /* GENERATED - org.apache.juneau.BeanTraverseContext.Builder */
639      public Builder maxDepth(int value) {
640         super.maxDepth(value);
641         return this;
642      }
643
644      @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */
645      public Builder accept(String value) {
646         super.accept(value);
647         return this;
648      }
649
650      @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */
651      public Builder addBeanTypes() {
652         super.addBeanTypes();
653         return this;
654      }
655
656      @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */
657      public Builder addBeanTypes(boolean value) {
658         super.addBeanTypes(value);
659         return this;
660      }
661
662      @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */
663      public Builder addRootType() {
664         super.addRootType();
665         return this;
666      }
667
668      @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */
669      public Builder addRootType(boolean value) {
670         super.addRootType(value);
671         return this;
672      }
673
674      @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */
675      public Builder keepNullProperties() {
676         super.keepNullProperties();
677         return this;
678      }
679
680      @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */
681      public Builder keepNullProperties(boolean value) {
682         super.keepNullProperties(value);
683         return this;
684      }
685
686      @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */
687      public Builder listener(Class<? extends org.apache.juneau.serializer.SerializerListener> value) {
688         super.listener(value);
689         return this;
690      }
691
692      @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */
693      public Builder produces(String value) {
694         super.produces(value);
695         return this;
696      }
697
698      @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */
699      public Builder sortCollections() {
700         super.sortCollections();
701         return this;
702      }
703
704      @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */
705      public Builder sortCollections(boolean value) {
706         super.sortCollections(value);
707         return this;
708      }
709
710      @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */
711      public Builder sortMaps() {
712         super.sortMaps();
713         return this;
714      }
715
716      @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */
717      public Builder sortMaps(boolean value) {
718         super.sortMaps(value);
719         return this;
720      }
721
722      @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */
723      public Builder trimEmptyCollections() {
724         super.trimEmptyCollections();
725         return this;
726      }
727
728      @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */
729      public Builder trimEmptyCollections(boolean value) {
730         super.trimEmptyCollections(value);
731         return this;
732      }
733
734      @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */
735      public Builder trimEmptyMaps() {
736         super.trimEmptyMaps();
737         return this;
738      }
739
740      @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */
741      public Builder trimEmptyMaps(boolean value) {
742         super.trimEmptyMaps(value);
743         return this;
744      }
745
746      @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */
747      public Builder trimStrings() {
748         super.trimStrings();
749         return this;
750      }
751
752      @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */
753      public Builder trimStrings(boolean value) {
754         super.trimStrings(value);
755         return this;
756      }
757
758      @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */
759      public Builder uriContext(UriContext value) {
760         super.uriContext(value);
761         return this;
762      }
763
764      @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */
765      public Builder uriRelativity(UriRelativity value) {
766         super.uriRelativity(value);
767         return this;
768      }
769
770      @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */
771      public Builder uriResolution(UriResolution value) {
772         super.uriResolution(value);
773         return this;
774      }
775
776      @Override /* GENERATED - org.apache.juneau.serializer.OutputStreamSerializer.Builder */
777      public Builder binaryFormat(BinaryFormat value) {
778         super.binaryFormat(value);
779         return this;
780      }
781
782      // </FluentSetters>
783   }
784
785   //-------------------------------------------------------------------------------------------------------------------
786   // Instance
787   //-------------------------------------------------------------------------------------------------------------------
788
789   final boolean
790      addBeanTypesMsgPack;
791
792   private final Map<ClassMeta<?>,MsgPackClassMeta> msgPackClassMetas = new ConcurrentHashMap<>();
793   private final Map<BeanPropertyMeta,MsgPackBeanPropertyMeta> msgPackBeanPropertyMetas = new ConcurrentHashMap<>();
794
795   /**
796    * Constructor.
797    *
798    * @param builder The builder for this object.
799    */
800   public MsgPackSerializer(Builder builder) {
801      super(builder);
802      this.addBeanTypesMsgPack = builder.addBeanTypesMsgPack;
803   }
804
805   @Override /* Context */
806   public Builder copy() {
807      return new Builder(this);
808   }
809
810   @Override /* Context */
811   public MsgPackSerializerSession.Builder createSession() {
812      return MsgPackSerializerSession.create(this);
813   }
814
815   @Override /* Context */
816   public MsgPackSerializerSession getSession() {
817      return createSession().build();
818   }
819
820   //-----------------------------------------------------------------------------------------------------------------
821   // Extended metadata
822   //-----------------------------------------------------------------------------------------------------------------
823
824   @Override /* MsgPackMetaProvider */
825   public MsgPackClassMeta getMsgPackClassMeta(ClassMeta<?> cm) {
826      MsgPackClassMeta m = msgPackClassMetas.get(cm);
827      if (m == null) {
828         m = new MsgPackClassMeta(cm, this);
829         msgPackClassMetas.put(cm, m);
830      }
831      return m;
832   }
833
834   @Override /* MsgPackMetaProvider */
835   public MsgPackBeanPropertyMeta getMsgPackBeanPropertyMeta(BeanPropertyMeta bpm) {
836      if (bpm == null)
837         return MsgPackBeanPropertyMeta.DEFAULT;
838      MsgPackBeanPropertyMeta m = msgPackBeanPropertyMetas.get(bpm);
839      if (m == null) {
840         m = new MsgPackBeanPropertyMeta(bpm.getDelegateFor(), this);
841         msgPackBeanPropertyMetas.put(bpm, m);
842      }
843      return m;
844   }
845
846   //-----------------------------------------------------------------------------------------------------------------
847   // Properties
848   //-----------------------------------------------------------------------------------------------------------------
849
850   @Override
851   protected final boolean isAddBeanTypes() {
852      return addBeanTypesMsgPack || super.isAddBeanTypes();
853   }
854
855   //-----------------------------------------------------------------------------------------------------------------
856   // Other methods
857   //-----------------------------------------------------------------------------------------------------------------
858
859   @Override /* Context */
860   protected JsonMap properties() {
861      return filteredMap("addBeanTypesMsgPack", addBeanTypesMsgPack);
862   }
863}