fix BigInteger bug
This commit is contained in:
@@ -3,6 +3,7 @@ package me.bearns.fias.domain;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import me.bearns.fias.xml.DecimalAdapter;
|
||||
|
||||
import javax.persistence.*;
|
||||
import javax.xml.bind.annotation.*;
|
||||
@@ -144,6 +145,8 @@ public class Addrobj implements Serializable {
|
||||
@XmlAttribute(name = "OPERSTATUS", required = true)
|
||||
protected BigInteger operstatus;
|
||||
|
||||
//FIAS bug, attribute is empty
|
||||
@XmlJavaTypeAdapter(DecimalAdapter.class)
|
||||
@XmlAttribute(name = "CURRSTATUS", required = true)
|
||||
protected BigInteger currstatus;
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user