PageRenderTime 201ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/src/main/java/com/alibaba/fastjson/serializer/SerializerFeature.java

https://bitbucket.org/xiejuntao/xdesktop
Java | 131 lines | 42 code | 14 blank | 75 comment | 3 complexity | 275f67375f85a5052bc5470593181674 MD5 | raw file
  1. /*
  2. * Copyright 1999-2101 Alibaba Group.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.alibaba.fastjson.serializer;
  17. /**
  18. * @author wenshao<szujobs@hotmail.com>
  19. */
  20. public enum SerializerFeature {
  21. QuoteFieldNames,
  22. /**
  23. *
  24. */
  25. UseSingleQuotes,
  26. /**
  27. *
  28. */
  29. WriteMapNullValue,
  30. /**
  31. *
  32. */
  33. WriteEnumUsingToString,
  34. /**
  35. *
  36. */
  37. UseISO8601DateFormat,
  38. /**
  39. * @since 1.1
  40. */
  41. WriteNullListAsEmpty,
  42. /**
  43. * @since 1.1
  44. */
  45. WriteNullStringAsEmpty,
  46. /**
  47. * @since 1.1
  48. */
  49. WriteNullNumberAsZero,
  50. /**
  51. * @since 1.1
  52. */
  53. WriteNullBooleanAsFalse,
  54. /**
  55. * @since 1.1
  56. */
  57. SkipTransientField,
  58. /**
  59. * @since 1.1
  60. */
  61. SortField,
  62. /**
  63. * @since 1.1.1
  64. */
  65. WriteTabAsSpecial,
  66. /**
  67. * @since 1.1.2
  68. */
  69. PrettyFormat,
  70. /**
  71. * @since 1.1.2
  72. */
  73. WriteClassName,
  74. /**
  75. * @since 1.1.6
  76. */
  77. DisableCircularReferenceDetect,
  78. /**
  79. * @since 1.1.9
  80. */
  81. WriteSlashAsSpecial,
  82. /**
  83. * @since 1.1.10
  84. */
  85. BrowserCompatible,
  86. /**
  87. * @since 1.1.14
  88. */
  89. WriteDateUseDateFormat,
  90. /**
  91. * @since 1.1.15
  92. */
  93. NotWriteRootClassName,
  94. /**
  95. * @since 1.1.19
  96. */
  97. DisableCheckSpecialChar,
  98. ;
  99. private SerializerFeature(){
  100. mask = (1 << ordinal());
  101. }
  102. private final int mask;
  103. public final int getMask() {
  104. return mask;
  105. }
  106. public static boolean isEnabled(int features, SerializerFeature feature) {
  107. return (features & feature.getMask()) != 0;
  108. }
  109. public static int config(int features, SerializerFeature feature, boolean state) {
  110. if (state) {
  111. features |= feature.getMask();
  112. } else {
  113. features &= ~feature.getMask();
  114. }
  115. return features;
  116. }
  117. }