增加BigDecimal的序列化和反序列化
This commit is contained in:
@@ -7,7 +7,7 @@ package org.redkale.convert;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.*;
|
||||
import java.math.BigInteger;
|
||||
import java.math.*;
|
||||
import java.net.*;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.CompletionHandler;
|
||||
@@ -89,6 +89,7 @@ public abstract class ConvertFactory<R extends Reader, W extends Writer> {
|
||||
this.register(CharSequence.class, CharSequenceSimpledCoder.instance);
|
||||
this.register(java.util.Date.class, DateSimpledCoder.instance);
|
||||
this.register(BigInteger.class, BigIntegerSimpledCoder.instance);
|
||||
this.register(BigDecimal.class, BigDecimalSimpledCoder.instance);
|
||||
this.register(InetAddress.class, InetAddressSimpledCoder.instance);
|
||||
this.register(DLong.class, DLongSimpledCoder.instance);
|
||||
this.register(Class.class, TypeSimpledCoder.instance);
|
||||
|
||||
44
src/org/redkale/convert/ext/BigDecimalSimpledCoder.java
Normal file
44
src/org/redkale/convert/ext/BigDecimalSimpledCoder.java
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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 org.redkale.convert.SimpledCoder;
|
||||
import org.redkale.convert.Writer;
|
||||
import org.redkale.convert.Reader;
|
||||
import java.math.BigDecimal;
|
||||
import org.redkale.util.Utility;
|
||||
|
||||
/**
|
||||
* BigDecimal 的SimpledCoder实现
|
||||
*
|
||||
* <p>
|
||||
* 详情见: https://redkale.org
|
||||
*
|
||||
* @author zhangjx
|
||||
* @param <R> Reader输入的子类型
|
||||
* @param <W> Writer输出的子类型
|
||||
*/
|
||||
public final class BigDecimalSimpledCoder<R extends Reader, W extends Writer> extends SimpledCoder<R, W, BigDecimal> {
|
||||
|
||||
public static final BigDecimalSimpledCoder instance = new BigDecimalSimpledCoder();
|
||||
|
||||
@Override
|
||||
public void convertTo(W out, BigDecimal value) {
|
||||
if (value == null) {
|
||||
out.writeNull();
|
||||
return;
|
||||
}
|
||||
out.writeSmallString(value.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigDecimal convertFrom(R in) {
|
||||
String value = in.readSmallString();
|
||||
if (value == null) return null;
|
||||
return new BigDecimal(Utility.charArray(value));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user