fix BigInteger bug

apache_commons_compress
Terekhin Alexander 5 years ago
parent 694bafcd98
commit 947c13db1a
  1. 3
      src/main/java/me/bearns/fias/domain/Addrobj.java
  2. 46
      src/main/java/me/bearns/fias/xml/DecimalAdapter.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;

@ -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…
Cancel
Save