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