PageRenderTime 89ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/xiejuntao/xdesktop
Java | 49 lines | 22 code | 9 blank | 18 comment | 4 complexity | 2a97acdd3b4fd1873d9bb93fed994041 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 com.alibaba.fastjson.util.FieldInfo;
  18. /**
  19. * @author wenshao<szujobs@hotmail.com>
  20. */
  21. class NumberFieldSerializer extends FieldSerializer {
  22. public NumberFieldSerializer(FieldInfo fieldInfo){
  23. super(fieldInfo);
  24. }
  25. @Override
  26. public void writeProperty(JSONSerializer serializer, Object propertyValue) throws Exception {
  27. SerializeWriter out = serializer.getWriter();
  28. writePrefix(serializer);
  29. Object value = propertyValue;
  30. if (value == null) {
  31. if (out.isEnabled(SerializerFeature.WriteNullNumberAsZero)) {
  32. out.write('0');
  33. } else {
  34. out.writeNull();
  35. }
  36. return;
  37. }
  38. out.append(value.toString());
  39. }
  40. }