/src/main/java/com/alibaba/fastjson/serializer/InetSocketAddressSerializer.java
Java | 33 lines | 26 code | 7 blank | 0 comment | 4 complexity | 693bb911835db2692b0470c8f51001a5 MD5 | raw file
- package com.alibaba.fastjson.serializer;
- import java.io.IOException;
- import java.lang.reflect.Type;
- import java.net.InetAddress;
- import java.net.InetSocketAddress;
- public class InetSocketAddressSerializer implements ObjectSerializer {
- public static InetSocketAddressSerializer instance = new InetSocketAddressSerializer();
- public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType) throws IOException {
- if (object == null) {
- serializer.writeNull();
- return;
- }
- SerializeWriter out = serializer.getWriter();
- InetSocketAddress address = (InetSocketAddress) object;
- InetAddress inetAddress = address.getAddress();
- out.write('{');
- if (inetAddress != null) {
- out.writeFieldName("address");
- serializer.write(inetAddress);
- out.write(',');
- }
- out.writeFieldName("port");
- out.writeInt(address.getPort());
- out.write('}');
- }
- }