diff --git a/src/main/java/me/bearns/fias/domain/Addrobj.java b/src/main/java/me/bearns/fias/domain/Addrobj.java index ae21499..8c4eab4 100644 --- a/src/main/java/me/bearns/fias/domain/Addrobj.java +++ b/src/main/java/me/bearns/fias/domain/Addrobj.java @@ -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; diff --git a/src/main/java/me/bearns/fias/xml/DecimalAdapter.java b/src/main/java/me/bearns/fias/xml/DecimalAdapter.java new file mode 100644 index 0000000..eaef388 --- /dev/null +++ b/src/main/java/me/bearns/fias/xml/DecimalAdapter.java @@ -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 { + + /** + * 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(); + } +}