PageRenderTime 39ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://bitbucket.org/xiejuntao/xdesktop
Java | 54 lines | 29 code | 7 blank | 18 comment | 7 complexity | 6c0dec471909365f0f2ecfe32e43b294 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. import java.io.IOException;
  18. import java.lang.reflect.Type;
  19. import java.util.concurrent.atomic.AtomicLongArray;
  20. /**
  21. * @author wenshao<szujobs@hotmail.com>
  22. */
  23. public class AtomicLongArraySerializer implements ObjectSerializer {
  24. public final static AtomicLongArraySerializer instance = new AtomicLongArraySerializer();
  25. public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType) throws IOException {
  26. SerializeWriter out = serializer.getWriter();
  27. if (object == null) {
  28. if (out.isEnabled(SerializerFeature.WriteNullListAsEmpty)) {
  29. out.write("[]");
  30. } else {
  31. out.writeNull();
  32. }
  33. return;
  34. }
  35. AtomicLongArray array = (AtomicLongArray) object;
  36. int len = array.length();
  37. out.append('[');
  38. for (int i = 0; i < len; ++i) {
  39. long val = array.get(i);
  40. if (i != 0) {
  41. out.write(',');
  42. }
  43. out.writeLong(val);
  44. }
  45. out.append(']');
  46. }
  47. }