diff --git a/src/org/redkale/convert/ConvertFactory.java b/src/org/redkale/convert/ConvertFactory.java index 7825c1295..8d631092f 100644 --- a/src/org/redkale/convert/ConvertFactory.java +++ b/src/org/redkale/convert/ConvertFactory.java @@ -94,6 +94,8 @@ public abstract class ConvertFactory { this.register(InetSocketAddress.class, InetSocketAddressSimpledCoder.instance); this.register(Pattern.class, PatternSimpledCoder.instance); this.register(CompletionHandler.class, CompletionHandlerSimpledCoder.instance); + this.register(URL.class, URLSimpledCoder.instance); + this.register(URI.class, URISimpledCoder.instance); //--------------------------------------------------------- this.register(boolean[].class, BoolArraySimpledCoder.instance); this.register(byte[].class, ByteArraySimpledCoder.instance); diff --git a/src/org/redkale/convert/ext/URISimpledCoder.java b/src/org/redkale/convert/ext/URISimpledCoder.java new file mode 100644 index 000000000..05daf0f74 --- /dev/null +++ b/src/org/redkale/convert/ext/URISimpledCoder.java @@ -0,0 +1,39 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package org.redkale.convert.ext; + +import java.net.*; +import org.redkale.convert.*; + +/** + * + * @author zhangjx + */ +public class URISimpledCoder extends SimpledCoder { + + public static final URLSimpledCoder instance = new URLSimpledCoder(); + + @Override + public void convertTo(final Writer out, final URI value) { + if (value == null) { + out.writeNull(); + } else { + out.writeString(value.toString()); + } + } + + @Override + public URI convertFrom(Reader in) { + final String str = in.readString(); + if (str == null) return null; + try { + return new URI(str); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } +} diff --git a/src/org/redkale/convert/ext/URLSimpledCoder.java b/src/org/redkale/convert/ext/URLSimpledCoder.java new file mode 100644 index 000000000..431424efe --- /dev/null +++ b/src/org/redkale/convert/ext/URLSimpledCoder.java @@ -0,0 +1,39 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package org.redkale.convert.ext; + +import java.net.*; +import org.redkale.convert.*; + +/** + * + * @author zhangjx + */ +public class URLSimpledCoder extends SimpledCoder { + + public static final URLSimpledCoder instance = new URLSimpledCoder(); + + @Override + public void convertTo(final Writer out, final URL value) { + if (value == null) { + out.writeNull(); + } else { + out.writeString(value.toString()); + } + } + + @Override + public URL convertFrom(Reader in) { + final String str = in.readString(); + if (str == null) return null; + try { + return new URL(str); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } +}