Code example for InetAddress

Methods: toString

0
    @Override 
    public void serialize(InetAddress value, JsonGenerator jgen, SerializerProvider provider)
        throws IOException, JsonGenerationException 
    { 
        // Ok: get textual description; choose "more specific" part 
        String str = value.toString().trim();
        int ix = str.indexOf('/');
        if (ix >= 0) {
            if (ix == 0) { // missing host name; use address
                str = str.substring(1);
            } else { // otherwise use name 
                str = str.substring(0, ix);
            } 
        } 
        jgen.writeString(str);
    } 
 
    @Override 
    public void serializeWithType(InetAddress value, JsonGenerator jgen, SerializerProvider provider,
            TypeSerializer typeSer)
        throws IOException, JsonGenerationException