parent
694bafcd98
commit
947c13db1a
@ -0,0 +1,46 @@ |
||||
package me.bearns.fias.xml; |
||||
|
||||
import lombok.extern.slf4j.Slf4j; |
||||
|
||||
import javax.xml.bind.ValidationEventHandler; |
||||
import javax.xml.bind.annotation.adapters.XmlAdapter; |
||||
import java.math.BigInteger; |
||||
|
||||
@Slf4j |
||||
public class DecimalAdapter extends XmlAdapter<String, BigInteger> { |
||||
|
||||
/** |
||||
* Convert a value type to a bound type. |
||||
* |
||||
* @param v The value to be converted. Can be null. |
||||
* @throws Exception if there's an error during the conversion. The caller is responsible for |
||||
* reporting the error to the user through {@link ValidationEventHandler}. |
||||
*/ |
||||
@Override |
||||
public BigInteger unmarshal(String v) throws Exception { |
||||
if (v == null) return null; |
||||
if (v.isEmpty()) { |
||||
log.trace("BigInteger bug bypassed"); |
||||
return null; |
||||
} |
||||
|
||||
if (!v.matches("^\\d+$")) return null; |
||||
|
||||
return new BigInteger(v); |
||||
} |
||||
|
||||
/** |
||||
* Convert a bound type to a value type. |
||||
* |
||||
* @param v The value to be convereted. Can be null. |
||||
* @throws Exception if there's an error during the conversion. The caller is responsible for |
||||
* reporting the error to the user through {@link ValidationEventHandler}. |
||||
*/ |
||||
@Override |
||||
public String marshal(BigInteger v) throws Exception { |
||||
//TODO BigInteger marshaling impl
|
||||
//throw new Exception("Marshalling not implemented");
|
||||
|
||||
return v == null ? null : v.toString(); |
||||
} |
||||
} |
Loading…
Reference in new issue