This commit is contained in:
@@ -39,4 +39,24 @@ public final class DLongSimpledCoder<R extends Reader, W extends Writer> extends
|
||||
return DLong.create(bs);
|
||||
}
|
||||
|
||||
public static class DLongJsonSimpledCoder<R extends Reader, W extends Writer> extends SimpledCoder<R, W, DLong> {
|
||||
|
||||
public static final DLongJsonSimpledCoder instance = new DLongJsonSimpledCoder();
|
||||
|
||||
@Override
|
||||
public void convertTo(final Writer out, final DLong value) {
|
||||
if (value == null) {
|
||||
out.writeNull();
|
||||
} else {
|
||||
out.writeSmallString(value.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public DLong convertFrom(Reader in) {
|
||||
final String str = in.readString();
|
||||
if (str == null) return null;
|
||||
return DLong.create(Utility.hexToBin(str));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,4 +68,57 @@ public final class InetAddressSimpledCoder<R extends Reader, W extends Writer> e
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public final static class InetAddressJsonSimpledCoder<R extends Reader, W extends Writer> extends SimpledCoder<R, W, InetAddress> {
|
||||
|
||||
public static final InetAddressJsonSimpledCoder instance = new InetAddressJsonSimpledCoder();
|
||||
|
||||
@Override
|
||||
public void convertTo(W out, InetAddress value) {
|
||||
if (value == null) {
|
||||
out.writeNull();
|
||||
return;
|
||||
}
|
||||
StringSimpledCoder.instance.convertTo(out, value.getHostAddress());
|
||||
}
|
||||
|
||||
@Override
|
||||
public InetAddress convertFrom(R in) {
|
||||
String str = StringSimpledCoder.instance.convertFrom(in);
|
||||
if (str == null) return null;
|
||||
try {
|
||||
return InetAddress.getByName(str);
|
||||
} catch (Exception ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public final static class InetSocketAddressJsonSimpledCoder<R extends Reader, W extends Writer> extends SimpledCoder<R, W, InetSocketAddress> {
|
||||
|
||||
public static final InetSocketAddressJsonSimpledCoder instance = new InetSocketAddressJsonSimpledCoder();
|
||||
|
||||
@Override
|
||||
public void convertTo(W out, InetSocketAddress value) {
|
||||
if (value == null) {
|
||||
out.writeNull();
|
||||
return;
|
||||
}
|
||||
StringSimpledCoder.instance.convertTo(out, value.getHostString() + ":" + value.getPort());
|
||||
}
|
||||
|
||||
@Override
|
||||
public InetSocketAddress convertFrom(R in) {
|
||||
String str = StringSimpledCoder.instance.convertFrom(in);
|
||||
if (str == null) return null;
|
||||
try {
|
||||
int pos = str.indexOf(':');
|
||||
return new InetSocketAddress(str.substring(0, pos), Integer.parseInt(str.substring(pos + 1)));
|
||||
} catch (Exception ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
* 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.json;
|
||||
|
||||
import org.redkale.util.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @see http://www.redkale.org
|
||||
* @author zhangjx
|
||||
*/
|
||||
public class DLongJsonSimpledCoder extends JsonSimpledCoder<DLong> {
|
||||
|
||||
public static final DLongJsonSimpledCoder instance = new DLongJsonSimpledCoder();
|
||||
|
||||
@Override
|
||||
public void convertTo(final JsonWriter out, final DLong value) {
|
||||
if (value == null) {
|
||||
out.writeNull();
|
||||
} else {
|
||||
out.writeSmallString(value.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public DLong convertFrom(JsonReader in) {
|
||||
final String str = in.readString();
|
||||
if (str == null) return null;
|
||||
return DLong.create(Utility.hexToBin(str));
|
||||
}
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
/*
|
||||
* 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.json;
|
||||
|
||||
import java.net.*;
|
||||
import org.redkale.convert.*;
|
||||
import org.redkale.convert.ext.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @see http://www.redkale.org
|
||||
* @author zhangjx
|
||||
* @param <R>
|
||||
* @param <W>
|
||||
*/
|
||||
public final class InetAddressJsonSimpledCoder<R extends Reader, W extends Writer> extends SimpledCoder<JsonReader, JsonWriter, InetAddress> {
|
||||
|
||||
public static final InetAddressJsonSimpledCoder instance = new InetAddressJsonSimpledCoder();
|
||||
|
||||
@Override
|
||||
public void convertTo(JsonWriter out, InetAddress value) {
|
||||
if (value == null) {
|
||||
out.writeNull();
|
||||
return;
|
||||
}
|
||||
StringSimpledCoder.instance.convertTo(out, value.getHostAddress());
|
||||
}
|
||||
|
||||
@Override
|
||||
public InetAddress convertFrom(JsonReader in) {
|
||||
String str = StringSimpledCoder.instance.convertFrom(in);
|
||||
if (str == null) return null;
|
||||
try {
|
||||
return InetAddress.getByName(str);
|
||||
} catch (Exception ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public final static class InetSocketAddressJsonSimpledCoder<R extends Reader, W extends Writer> extends SimpledCoder<JsonReader, JsonWriter, InetSocketAddress> {
|
||||
|
||||
public static final InetSocketAddressJsonSimpledCoder instance = new InetSocketAddressJsonSimpledCoder();
|
||||
|
||||
@Override
|
||||
public void convertTo(JsonWriter out, InetSocketAddress value) {
|
||||
if (value == null) {
|
||||
out.writeNull();
|
||||
return;
|
||||
}
|
||||
StringSimpledCoder.instance.convertTo(out, value.getHostString() + ":" + value.getPort());
|
||||
}
|
||||
|
||||
@Override
|
||||
public InetSocketAddress convertFrom(JsonReader in) {
|
||||
String str = StringSimpledCoder.instance.convertFrom(in);
|
||||
if (str == null) return null;
|
||||
try {
|
||||
int pos = str.indexOf(':');
|
||||
return new InetSocketAddress(str.substring(0, pos), Integer.parseInt(str.substring(pos + 1)));
|
||||
} catch (Exception ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import org.redkale.convert.ConvertType;
|
||||
import org.redkale.convert.Factory;
|
||||
import java.io.Serializable;
|
||||
import java.net.*;
|
||||
import org.redkale.convert.ext.*;
|
||||
import org.redkale.util.*;
|
||||
|
||||
/**
|
||||
@@ -21,9 +22,9 @@ public final class JsonFactory extends Factory<JsonReader, JsonWriter> {
|
||||
private static final JsonFactory instance = new JsonFactory(null, Boolean.getBoolean("convert.json.tiny"));
|
||||
|
||||
static {
|
||||
instance.register(InetAddress.class, InetAddressJsonSimpledCoder.instance);
|
||||
instance.register(InetSocketAddress.class, InetAddressJsonSimpledCoder.InetSocketAddressJsonSimpledCoder.instance);
|
||||
instance.register(DLong.class, DLongJsonSimpledCoder.instance);
|
||||
instance.register(InetAddress.class, InetAddressSimpledCoder.InetAddressJsonSimpledCoder.instance);
|
||||
instance.register(InetSocketAddress.class, InetAddressSimpledCoder.InetSocketAddressJsonSimpledCoder.instance);
|
||||
instance.register(DLong.class, DLongSimpledCoder.DLongJsonSimpledCoder.instance);
|
||||
instance.register(Serializable.class, instance.loadEncoder(Object.class));
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ import org.redkale.util.*;
|
||||
* @see http://www.redkale.org
|
||||
* @author zhangjx
|
||||
*/
|
||||
public final class JsonReader implements Reader {
|
||||
public class JsonReader implements Reader {
|
||||
|
||||
private int position = -1;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user