PageRenderTime 108ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/xiejuntao/xdesktop
Java | 33 lines | 26 code | 7 blank | 0 comment | 4 complexity | 693bb911835db2692b0470c8f51001a5 MD5 | raw file
  1. package com.alibaba.fastjson.serializer;
  2. import java.io.IOException;
  3. import java.lang.reflect.Type;
  4. import java.net.InetAddress;
  5. import java.net.InetSocketAddress;
  6. public class InetSocketAddressSerializer implements ObjectSerializer {
  7. public static InetSocketAddressSerializer instance = new InetSocketAddressSerializer();
  8. public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType) throws IOException {
  9. if (object == null) {
  10. serializer.writeNull();
  11. return;
  12. }
  13. SerializeWriter out = serializer.getWriter();
  14. InetSocketAddress address = (InetSocketAddress) object;
  15. InetAddress inetAddress = address.getAddress();
  16. out.write('{');
  17. if (inetAddress != null) {
  18. out.writeFieldName("address");
  19. serializer.write(inetAddress);
  20. out.write(',');
  21. }
  22. out.writeFieldName("port");
  23. out.writeInt(address.getPort());
  24. out.write('}');
  25. }
  26. }