parent
c2a3417f0c
commit
9fae8eb95c
@ -0,0 +1,39 @@ |
|||||||
|
package me.bearns.fias.xml; |
||||||
|
|
||||||
|
import me.bearns.fias.domain.Addrobj; |
||||||
|
import me.bearns.fias.repository.AddrobjRepository; |
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.stereotype.Component; |
||||||
|
|
||||||
|
import javax.xml.bind.annotation.adapters.XmlAdapter; |
||||||
|
import java.util.Optional; |
||||||
|
import java.util.UUID; |
||||||
|
|
||||||
|
@Component |
||||||
|
public class AddrObjAdapter extends XmlAdapter<String, Addrobj> { |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private static AddrobjRepository repository; |
||||||
|
|
||||||
|
@Override |
||||||
|
public Addrobj unmarshal(String v) throws Exception { |
||||||
|
|
||||||
|
final UUID aoguid = UUID.fromString(v); |
||||||
|
final Addrobj addrobj = repository.findByAoguid(aoguid).orElseGet(Addrobj::new); |
||||||
|
addrobj.aoguid = aoguid; |
||||||
|
|
||||||
|
return addrobj; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public String marshal(Addrobj v) throws Exception { |
||||||
|
|
||||||
|
if(v!=null){ |
||||||
|
final UUID aoguid = v.aoguid; |
||||||
|
|
||||||
|
if(aoguid!=null) return aoguid.toString(); |
||||||
|
} |
||||||
|
|
||||||
|
return null; |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue