Just trying to learn and understand Jaxb and how xml binding works, so thank you very very much! I do not understand how or if it does blocks or sections that reoccur? in below, the MM block can be 1 or many, how does this get asorbed to pojo? how does Jaxb or other engines bind multiple sections, say the MM section? thank you!!!
I have an XML file I need to UnMarshal to Java POJO's.
A 018912111835030108XXXXXXXXXX
<RTR>
<HEAD>
<IDCMS pn="ABF31A6FNCL0004" vers="4.0"/>
<DA>2018/12/11 01:07:37</DA>
<ACD MSN="0149" tail="N503DN" type="A350-900"/>
<TID>C00000011</TID>
</HEAD>
<HEADRTR>
<FROM>KDTW</FROM>
<TO>ZBAA</TO>
<FNBR>DAL189 </FNBR>
</HEADRTR>
<ITD>
<CB>A</CB>
<NFDE>
<MC>3166X001</MC>
<MD>INDICATING-OIS CAPT-"OIS NOT AVAIL" displayed instead of the requested video</MD>
</NFDE>
<MM hdi="y" fo="A" occ="1">
<MC>4612F11W</MC>
<MD>VGM-1(107TC1) / AVM-1(103TC1) / OSFC RESET</MD>
<DA>2018/12/11 00:57:39</DA>
<ATA>4612</ATA>
<FPH>8</FPH>
<FCL>1</FCL>
<PRIO>high</PRIO>
<STA>1</STA>
<SYS name="ASF" bite_id="107" side="0"/>
</MM>
<MM hdi="y" occ="1">
<MC>3166F8TT</MC>
<MD>VGM-1(107TC1) / CMV-2(1TE2) / WRG TO CMV-2(1TE2) PIN AEDD</MD>
<DA>2018/12/11 00:57:36</DA>
<CDA>2018/12/11 00:57:37</CDA>
<ATA>3166</ATA>
<FPH>8</FPH>
<FCL>1</FCL>
<PRIO>low</PRIO>
<STA>2</STA>
<SYS name="CMV2" bite_id="31" side="2"/>
</MM>
</ITD>
</RTR>
created the classes for the XML structure minus how to consume reoccuring sections. I won't post them all. I think help on one will do the others. thanks!
#XmlRootElement( name = "MM" )
public class Mm {
private String mc;
private String md;
private String da;
private String ata;
private String fph;
private String prio;
Mm(){
super();
}
Mm( #XmlElement(name="MC") String mc,
#XmlElement(name="MD") String md,
#XmlElement(name="DA") String da,
#XmlElement(name="FPH") String fph,
#XmlElement(name="PRIO") String prio) {
this.mc = mc;
this.md = md;
this.da = da;
this.fph = fph;
this.prio = prio;
}
public String getMc() {
return mc;
}
public String getMd() {
return md;
}
public String getDa() {
return da;
}
public String getAta() {
return ata;
}
public String getFph() {
return fph;
}
public String getPrio() {
return prio;
}
#Override
public String toString() {
final StringBuilder sb = new StringBuilder("MC=");
sb.append(getMc()).append(",");
sb.append("MD=").append(getMd()).append(",");
sb.append("DA=").append(getDa()).append(",");
sb.append("ATA=").append(getAta()).append(",");
sb.append("FPH=").append(getFph()).append(",");
sb.append("PRIO=").append(getPrio());
return sb.toString();
}
}
#XmlRootElement( name = "FDE" )
public class Fde {
private String mc;
private String md;
private String da;
private String fph;
Fde(){
super();
}
Fde( #XmlElement(name="MC") String mc,
#XmlElement(name="MD") String md,
#XmlElement(name="DA") String da,
#XmlElement(name="FPH") String fph) {
this.mc = mc;
this.md = md;
this.da = da;
this.fph = fph;
}
public String getMc() {
return mc;
}
public String getMd() {
return md;
}
public String getDa() {
return da;
}
public String getFph() {
return fph;
}
#Override
public String toString() {
final StringBuilder sb = new StringBuilder("MC=");
sb.append(getMc()).append(",");
sb.append("MD=").append(getMd()).append(",");
sb.append("DA=").append(getDa()).append(",");
sb.append("FPH=").append(getFph());
return sb.toString();
}
}
#XmlRootElement( name = "HEADRTR" )
public class HeadRtr {
private String from;
private String to;
private String fnbr;
HeadRtr(){
super();
}
HeadRtr(#XmlElement(name="FROM") String from,
#XmlElement(name="TO") String to,
#XmlElement(name="FNBR") String fnbr) {
this.from = from;
this.to = to;
this.fnbr = fnbr;
}
public String getFrom() {
return from;
}
public String getTo() {
return to;
}
public String getFnbr() {
return fnbr;
}
#Override
public String toString() {
final StringBuilder sb = new StringBuilder("FROM=");
sb.append(getFrom()).append(",");
sb.append("TO=").append(getTo()).append(",");
sb.append("FNBR=").append(getFnbr());
return sb.toString();
}
}
I'm thinking a list of these objects
From the look of the xml.
You'd want ITD, FDE, MM as objects. with ITD having a List, and FDE as a member.
Thanks to Mavriksc here is the result to decode an HTML XML document.
This is a sample HTML XML document we need to Unmarshal.
<RTR>
<HEAD>
<IDCMS pn="ABF31A6FNCL0004" vers="4.0"/>
<DA>2018/12/11 00:15:42</DA>
<ACD MSN="0160" tail="N504DN" type="A350-900"/>
<TID>C00000023</TID>
</HEAD>
<HEADRTR>
<FROM>ZSPD</FROM>
<TO>KLAX</TO>
<FNBR>DAL88 </FNBR>
</HEADRTR>
<ITD>
<CB>A</CB>
<FDE disp="n" dm="y">
<MC>3031H050</MC>
<MD>A-ICE // > A-ICE SIDESLIP PROBE 2 HEATG</MD>
<DA>2018/12/11 00:12:42</DA>
<CDA>2018/12/11 00:14:17</CDA>
<FPH>8</FPH>
<LAB>1</LAB>
</FDE>
<MM fo="A" occ="5">
<MC>3413F7EV</MC>
<MD>PROBE-SSA,2(11FP2)</MD>
<DA>2018/12/11 00:08:43</DA>
<ATA>3413</ATA>
<FPH>8</FPH>
<FCL>1</FCL>
<PRIO>high</PRIO>
<STA>1</STA>
<SYS name="ADR2" bite_id="3" side="2"/>
</MM>
</ITD>
</RTR>
here is the Jaxb POJO's mapping the XML to POJO.
RTR
#XmlRootElement(name = "RTR", namespace="com.ge.ip.infra.fadec.jaxb.decoder")
public class Rtr implements Serializable {
private static final long serialVersionUID = 1L;
public Rtr() {
super();
}
private Itd itd;
private HeadRtr headRtr;
private Head head;
public Itd getItd() {
return itd;
}
public void setItd(Itd itd) {
this.itd = itd;
}
public HeadRtr getHeadRtr() {
return headRtr;
}
public void setHeadRtr(HeadRtr headRtr) {
this.headRtr = headRtr;
}
public Head getHead() {
return head;
}
public void setHead(Head head) {
this.head = head;
}
#Override
public String toString()
{
return "RTR ITD = " + itd + ", HEADRTR = " + headRtr + ", HEAD = " + head;
}
}
HEAD
#XmlRootElement(name = "HEAD")
public class Head implements Serializable {
private static final long serialVersionUID = 1L;
#XmlElement(name = "IDCMS") private Idcms idcms;
#XmlElement(name = "DA") private String da;
#XmlElement(name = "ACD") private Acd acd;
#XmlElement(name = "TID") private String tid;
public String getDa() {
return da;
}
public String getTid() {
return tid;
}
public void setDa(String da) {
this.da = da;
}
public void setTid(String tid) {
this.tid = tid;
}
public Acd getAcd () {
return acd;
}
public void setAcd (Acd acd) {
this.acd = acd;
}
public Idcms getIdcms () {
return idcms;
}
public void setIdcms (Idcms idcms) {
this.idcms = idcms;
}
#Override
public String toString() {
final StringBuilder sb = new StringBuilder("DA=");
sb.append(getDa()).append(",");
sb.append("TID=").append(getTid()).append(",");
sb.append(acd.toString());
sb.append(idcms.toString());
return sb.toString();
}
//}
public class Idcms implements Serializable {
private static final long serialVersionUID = 1L;
#XmlAttribute(name = "pn") private String pn;
#XmlAttribute(name = "vers") private String vers;
public String getPn() {
return pn;
}
public String getVers() {
return vers;
}
public void setPn(String pn) {
this.pn = pn;
}
public void setVers(String vers) {
this.vers = vers;
}
#Override
public String toString() {
final StringBuilder sb = new StringBuilder("PN=");
sb.append(getPn()).append(",");
sb.append("VERS=").append(getVers());
return sb.toString();
}
}
public class Acd implements Serializable {
private static final long serialVersionUID = 1L;
#XmlAttribute(name = "MSN") private String msn;
#XmlAttribute(name = "tail") private String tail;
#XmlAttribute(name = "type") private String type;
public String getMsn() {
return msn;
}
public String getTail() {
return tail;
}
public String getType() {
return type;
}
public void setMsn(String msn) {
this.msn = msn;
}
public void setTail(String tail) {
this.tail = tail;
}
public void setType(String type) {
this.type = type;
}
#Override
public String toString() {
final StringBuilder sb = new StringBuilder("MSN=");
sb.append(getMsn()).append(",");
sb.append("TAIL=").append(getTail()).append(",");
sb.append("TYPE=").append(getType());
return sb.toString();
}
}
}
HEADRTR
#XmlRootElement( name = "HEADRTR" )
public class HeadRtr implements Serializable {
private static final long serialVersionUID = 1L;
private String from;
private String to;
private String fnbr;
HeadRtr(){
super();
}
HeadRtr(#XmlElement(name="FROM") String from,
#XmlElement(name="TO") String to,
#XmlElement(name="FNBR") String fnbr) {
this.from = from;
this.to = to;
this.fnbr = fnbr;
}
public String getFrom() {
return from;
}
public String getTo() {
return to;
}
public String getFnbr() {
return fnbr;
}
#Override
public String toString() {
final StringBuilder sb = new StringBuilder("FROM=");
sb.append(getFrom()).append(",");
sb.append("TO=").append(getTo()).append(",");
sb.append("FNBR=").append(getFnbr());
return sb.toString();
}
}
ITD
#XmlRootElement( name = "ITD" )
#XmlAccessorType (XmlAccessType.FIELD)
public class Itd implements Serializable {
private static final long serialVersionUID = 1L;
private Mm mm;
private Fde fde;
private Nfde nfde;
public Mm getMm() {
return mm;
}
public void setMm (Mm mm)
{
this.mm = mm;
}
#XmlElement(name="CB")
private String cb;
public String getCb() {
return cb;
}
public void setCb(String cb) {
this.cb = cb;
}
public Fde getFde ()
{
return fde;
}
public void setFde (Fde fde)
{
this.fde = fde;
}
public Nfde getNfde() {
return nfde;
}
public void setNfde (Nfde nfde)
{
this.nfde = nfde;
}
#Override
public String toString()
{
return "ITD MM = " + mm + ", CB = " + cb + ", FDE = " + fde + ", NFDE = " + nfde;
}
}
NFDE
#XmlRootElement( name = "NFDE" )
#XmlAccessorType (XmlAccessType.FIELD)
public class Nfde implements Serializable {
private static final long serialVersionUID = 1L;
private String mc;
private String md;
public String getMc() {
if ( !mc.isEmpty() && null != mc ) {
return mc;
} else {
return "NFDE";
}
}
public String getMd() {
if ( !md.isEmpty() && null != md ) {
return md;
} else {
return "NFDE";
}
}
#XmlElement(name="MC")
public void setMc(String mc) {
this.mc = mc;
}
#XmlElement(name="MD")
public void setMd(String md) {
this.md = md;
}
}
FDE
#XmlRootElement( name = "FDE" )
#XmlAccessorType (XmlAccessType.FIELD)
public class Fde implements Serializable {
private static final long serialVersionUID = 1L;
private String mc;
private String md;
private String da;
private String fph;
Fde(){
super();
}
Fde( #XmlElement(name="MC") String mc,
#XmlElement(name="MD") String md,
#XmlElement(name="DA") String da,
#XmlElement(name="FPH") String fph) {
this.mc = mc;
this.md = md;
this.da = da;
this.fph = fph;
}
public String getMc() {
return mc;
}
public String getMd() {
return md;
}
public String getDa() {
return da;
}
public String getFph() {
return fph;
}
#Override
public String toString() {
final StringBuilder sb = new StringBuilder("MC=");
sb.append(getMc()).append(",");
sb.append("MD=").append(getMd()).append(",");
sb.append("DA=").append(getDa()).append(",");
sb.append("FPH=").append(getFph());
return sb.toString();
}
}
MM
#XmlRootElement( name = "MM" )
#XmlAccessorType (XmlAccessType.FIELD)
public class Mm implements Serializable {
private static final long serialVersionUID = 1L;
private String mc;
private String md;
private String da;
private String ata;
private String fph;
private String prio;
Mm(){
super();
}
Mm( #XmlElement(name="MC") String mc,
#XmlElement(name="MD") String md,
#XmlElement(name="DA") String da,
#XmlElement(name="FPH") String fph,
#XmlElement(name="PRIO") String prio) {
this.mc = mc;
this.md = md;
this.da = da;
this.fph = fph;
this.prio = prio;
}
public String getMc() {
return mc;
}
public String getMd() {
return md;
}
public String getDa() {
return da;
}
public String getAta() {
return ata;
}
public String getFph() {
return fph;
}
public String getPrio() {
return prio;
}
#Override
public String toString() {
final StringBuilder sb = new StringBuilder("MC=");
sb.append(getMc()).append(",");
sb.append("MD=").append(getMd()).append(",");
sb.append("DA=").append(getDa()).append(",");
sb.append("ATA=").append(getAta()).append(",");
sb.append("FPH=").append(getFph()).append(",");
sb.append("PRIO=").append(getPrio());
return sb.toString();
}
}
Decoder POJO
public class A350Decoder implements Serializable {
private static final long serialVersionUID = 1L;
public A350Decoder() {
super();
}
private Rtr rtr;
public Rtr getRtr() {
return rtr;
}
public void setRtr(Rtr rtr) {
this.rtr = rtr;
}
#Override
public String toString()
{
return "A350Decoder RTR = " + rtr;
}
}
Related
I'm trying to parse XML content with Jackson but I have some difficulties with Boolean value.
This is a part of my XML content :
<?xml version="1.0" encoding="UTF-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body xmlns:ns1="http://somecontent">
<wsResponse xmlns="http://somecontent">
<responseType>SUCCESS</responseType>
<response>
<successfullResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="InterchangeSearchResponse">
<totalResult>1</totalResult>
<returnedResults>1</returnedResults>
<pageIndex>1</pageIndex>
<interchanges>
<interchange>
<depositId>somecontent</depositId>
<interchangeId>somecontent</interchangeId>
<depositDate>2021-03-26T11:45:05.000+01:00</depositDate>
<depositSubject>dépôt WS</depositSubject>
<numADS>number</numADS>
<adsDate>2021-03-26T11:45:05.000+01:00</adsDate>
<alias>contentAsString</alias>
<version xsi:nil="true"/>
<isTest>false</isTest>
<deposantAccount>
<name>someString</name>
</deposantAccount>
<teleProcedure>someString</teleProcedure>
<statesHistory>
This is my XML structure as class :
#JacksonXmlProperty(localName = "Body")
private Body body;
public Body getBody() {
return body;
}
public void setBody(Body body) {
this.body = body;
}
}
#JacksonXmlRootElement
public class Body {
#JacksonXmlProperty(localName = "Fault")
private Fault fault;
private WsResponse wsResponse;
public Fault getFault() {
return fault;
}
public void setFault(Fault fault) {
this.fault = fault;
}
public WsResponse getWsResponse() {
return wsResponse;
}
public void setWsResponse(WsResponse wsResponse) {
this.wsResponse = wsResponse;
}
}
#JacksonXmlRootElement(localName = "wsResponse")
public class WsResponse {
private String responseType;
private Response response;
public String getResponseType() {
return responseType;
}
public void setResponseType(String responseType) {
this.responseType = responseType;
}
public Response getResponse() {
return response;
}
public void setResponse(Response response) {
this.response = response;
}
}
#JacksonXmlRootElement
public class Response {
private SuccessfulResponse successfullResponse;
private ErrorResponse errorResponse;
public SuccessfulResponse getSuccessfullResponse() {
return successfullResponse;
}
public void setSuccessfullResponse(SuccessfulResponse successfullResponse) {
this.successfullResponse = successfullResponse;
}
public ErrorResponse getErrorResponse() {
return errorResponse;
}
public void setErrorResponse(ErrorResponse errorResponse) {
this.errorResponse = errorResponse;
}
}
#JacksonXmlRootElement
public class SuccessfulResponse {
/**
* Response when add document success
*/
private String depositId;
/**
* Response when get interchanges by deposit id success
*/
private String type;
private Integer totalResult;
private Integer returnedResults;
private Integer pageIndex;
private Interchanges interchanges;
/**
* Response when get declaration details success
*/
private DeclarationTdfc declarationTdfc;
public SuccessfulResponse() {}
public SuccessfulResponse(String depositId) {
this.depositId = depositId;
}
public SuccessfulResponse(String type, Integer totalResult, Integer returnedResults, Integer pageIndex, Interchanges interchanges) {
this.type = type;
this.totalResult = totalResult;
this.returnedResults = returnedResults;
this.pageIndex = pageIndex;
this.interchanges = interchanges;
}
public SuccessfulResponse(DeclarationTdfc declarationTdfc) {
this.declarationTdfc = declarationTdfc;
}
public SuccessfulResponse(String depositId, String type, Integer totalResult, Integer returnedResults,
Integer pageIndex, Interchanges interchanges, DeclarationTdfc declarationTdfc) {
super();
this.depositId = depositId;
this.type = type;
this.totalResult = totalResult;
this.returnedResults = returnedResults;
this.pageIndex = pageIndex;
this.interchanges = interchanges;
this.declarationTdfc = declarationTdfc;
}
public String getDepositId() {
return depositId;
}
public void setDepositId(String depositId) {
this.depositId = depositId;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public Integer getTotalResult() {
return totalResult;
}
public void setTotalResult(Integer totalResult) {
this.totalResult = totalResult;
}
public Integer getReturnedResults() {
return returnedResults;
}
public void setReturnedResults(Integer returnedResults) {
this.returnedResults = returnedResults;
}
public Integer getPageIndex() {
return pageIndex;
}
public void setPageIndex(Integer pageIndex) {
this.pageIndex = pageIndex;
}
public Interchanges getInterchanges() {
return interchanges;
}
public void setInterchanges(Interchanges interchanges) {
this.interchanges = interchanges;
}
public DeclarationTdfc getDeclarationTdfc() {
return declarationTdfc;
}
public void setDeclarationTdfc(DeclarationTdfc declarationTdfc) {
this.declarationTdfc = declarationTdfc;
}
}
public class Interchanges {
#JacksonXmlProperty(localName = "interchange")
#JacksonXmlElementWrapper(useWrapping = false)
private List<Interchange> interchange;
public Interchanges() { super(); }
public Interchanges(List<Interchange> interchange) {
super();
this.interchange = interchange;
}
public List<Interchange> getInterchange() {
return interchange;
}
public void setInterchange(List<Interchange> interchange) {
this.interchange = interchange;
}
}
public class Interchange {
private String depositId;
private Integer interchangeId;
//#JsonFormat(shape = JsonFormat.Shape.STRING, pattern = SelfmedConstants.Dates.ENGLISH_DATETIME_PATTERN)
private String depositDate;
private String depositSubject;
private String numADS;
//#JsonFormat(shape = JsonFormat.Shape.STRING, pattern = SelfmedConstants.Dates.ENGLISH_DATETIME_PATTERN)
private String adsDate;
private String alias;
//#JacksonXmlProperty(isAttribute = true)
private String version;
#JsonSerialize(using = BooleanSerializer.class)
#JsonDeserialize(using = BooleanDeserializer.class)
#JacksonXmlProperty(localName = "isTest")
private Boolean isTest;
#JacksonXmlProperty(localName = "name")
#JacksonXmlElementWrapper(localName = "deposantAccount")
private List<String> name;
private String teleProcedure;
private StatesHistory statesHistory;
#JacksonXmlProperty(localName = "declarationId")
#JacksonXmlElementWrapper(localName = "declarationIds")
private List<String> declarationId;
public Interchange() {
}
public Interchange(String depositId, Integer interchangeId, String depositDate, String depositSubject, String numADS,
String adsDate, String alias, String version, Boolean isTest, List<String> name, String teleProcedure,
StatesHistory statesHistory, List<String> declarationId) {
this();
this.depositId = depositId;
this.interchangeId = interchangeId;
this.depositDate = depositDate;
this.depositSubject = depositSubject;
this.numADS = numADS;
this.adsDate = adsDate;
this.alias = alias;
this.version = version;
this.isTest = isTest;
this.name = name;
this.teleProcedure = teleProcedure;
this.statesHistory = statesHistory;
this.declarationId = declarationId;
}
public String getDepositId() {
return depositId;
}
public void setDepositId(String depositId) {
this.depositId = depositId;
}
public Integer getInterchangeId() {
return interchangeId;
}
public void setInterchangeId(Integer interchangeId) {
this.interchangeId = interchangeId;
}
public String getDepositDate() {
return depositDate;
}
public void setDepositDate(String depositDate) {
this.depositDate = depositDate;
}
public String getDepositSubject() {
return depositSubject;
}
public void setDepositSubject(String depositSubject) {
this.depositSubject = depositSubject;
}
public String getNumADS() {
return numADS;
}
public void setNumADS(String numADS) {
this.numADS = numADS;
}
public String getAdsDate() {
return adsDate;
}
public void setAdsDate(String adsDate) {
this.adsDate = adsDate;
}
public String getAlias() {
return alias;
}
public void setAlias(String alias) {
this.alias = alias;
}
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
public Boolean getIsTest() {
return isTest;
}
public void setIsTest(Boolean isTest) {
this.isTest = isTest;
}
public void setIsTest(String isTest) {
this.isTest = Boolean.valueOf(isTest);
}
public List<String> getName() {
return name;
}
public void setName(List<String> name) {
this.name = name;
}
public String getTeleProcedure() {
return teleProcedure;
}
public void setTeleProcedure(String teleProcedure) {
this.teleProcedure = teleProcedure;
}
public StatesHistory getStatesHistory() {
return statesHistory;
}
public void setStatesHistory(StatesHistory statesHistory) {
this.statesHistory = statesHistory;
}
public List<String> getDeclarationId() {
return declarationId;
}
public void setDeclarationId(List<String> declarationId) {
this.declarationId = declarationId;
}
}
As you can see in the Interchange class, I try some stuff but nothing work.
I generate my class like that :
JacksonXmlModule xmlModule = new JacksonXmlModule();
xmlModule.setDefaultUseWrapper(false);
XmlMapper xmlMapper = new XmlMapper(xmlModule);
xmlMapper.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, true);
xmlMapper.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_VALUES);
System.out.println(responseAsString);
Envelope envelope = xmlMapper.readValue(responseAsString, new TypeReference<>() {
But when I try to parse my content, I got this exception :
Cannot construct instance of payload.response.Interchange (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('false')
at [Source: (StringReader); line: 20, column: 28] (through reference chain: payload.response.Envelope["Body"]->payload.response.Body["wsResponse"]->payload.response.WsResponse["response"]->payload.response.Response["successfullResponse"]->payload.response.SuccessfulResponse["interchanges"]->payload.response.Interchanges["interchange"]->java.util.ArrayList[1])
I try a lot of things but nothing work so I'm wondering if the problem may be not here...
If you have any solution or leads to explore, please let me know !
Thank.
According to JavaBean spec you have to name getter isTest().
I am doing a liferay project which use ejb at back end. so my ejb method looks like this:-
#Override
public List<RmisPaymentDetailsDto> getEpaymentDetails(String ebpCode) {
Query q = entityManager.createQuery("select s from EpaymentBo s where s.ebpCode=:ebpcode")
.setParameter("ebpcode",ebpCode);
#SuppressWarnings("unchecked")
List<ProductBo> list = q.getResultList();
Iterator<ProductBo> i = list.iterator();
List<RmisPaymentDetailsDto> rList = new ArrayList<RmisPaymentDetailsDto>();
while(i.hasNext()){
EpaymentBo ep =(EpaymentBo) i.next();
RmisPaymentDetailsDto dto = new RmisPaymentDetailsDto();
dto.setAdvertisementcode(ep.getAdvertisementcode());
dto.setAmount(ep.getAmount());
dto.setStudentmasterid(ep.getStudentmasterid());
dto.setEbpgendate(ep.getEbp_gen_date());
dto.setEbpcode(ep.getEbpCode());
dto.setPaymentstatus(ep.getPaymentstatus());
dto.setCandidatenameinnepali(ep.getCandidatenameinnepali());
rList.add(dto);
}
return rList;
}
the above method successfully fetches data from database and sets it to my RmisPaymentDetailsDto.
like this:-
now i am calling same method from my liferay controlller.
PreExaminationRemote preRef = (PreExaminationRemote) jndiContext
.lookup("PreExamination/remote");
List<RmisPaymentDetailsDto> rDto = preRef.getEpaymentDetails(ebpCode);
I am wondering how my one property(candidatenameinnepali) is lost as i return same dto from my ejb.
My dto looks like this:-
public class RmisPaymentDetailsDto implements Serializable {
private static final long serialVersionUID = 1L;
private String advertisementcode;
private String ebpcode;
private String amount;
private String studentmasterid;
private Date ebpgendate;
private String paymentstatus;
private String candidatenameinnepali;
public String getCandidatenameinnepali() {
return candidatenameinnepali;
}
public void setCandidatenameinnepali(String candidatenameinnepali) {
this.candidatenameinnepali = candidatenameinnepali;
}
public String getAdvertisementcode() {
return advertisementcode;
}
public void setAdvertisementcode(String advertisementcode) {
this.advertisementcode = advertisementcode;
}
public String getEbpcode() {
return ebpcode;
}
public void setEbpcode(String ebpcode) {
this.ebpcode = ebpcode;
}
public String getAmount() {
return amount;
}
public void setAmount(String amount) {
this.amount = amount;
}
public String getStudentmasterid() {
return studentmasterid;
}
public void setStudentmasterid(String studentmasterid) {
this.studentmasterid = studentmasterid;
}
public Date getEbpgendate() {
return ebpgendate;
}
public void setEbpgendate(Date ebpgendate) {
this.ebpgendate = ebpgendate;
}
public String getPaymentstatus() {
return paymentstatus;
}
public void setPaymentstatus(String paymentstatus) {
this.paymentstatus = paymentstatus;
}
public static long getSerialversionuid() {
return serialVersionUID;
}
}
I'm struggling to implement a solution to retrieve multiple values from my api response ( https://www.thecocktaildb.com/api/json/v1/1/lookup.php?i=13060 ) and assign specific values to an array. Specifically values, strIngredient1, strIngredient2, strIngredient3 etc...
At present i created a POJO cocktail class as follows:
public class Cocktail implements Serializable {
#SerializedName("idDrink")
#Expose
private String idDrink;
#SerializedName("strDrink")
#Expose
private String strDrink;
#SerializedName("strVideo")
#Expose
private Object strVideo;
#SerializedName("strCategory")
#Expose
private String strCategory;
#SerializedName("strIBA")
#Expose
private Object strIBA;
#SerializedName("strAlcoholic")
#Expose
private String strAlcoholic;
#SerializedName("strGlass")
#Expose
private String strGlass;
#SerializedName("strInstructions")
#Expose
private String strInstructions;
#SerializedName("strDrinkThumb")
#Expose
private String strDrinkThumb;
#SerializedName("strIngredient1")
#Expose
private String strIngredient1;
#SerializedName("strIngredient2")
#Expose
private String strIngredient2;
#SerializedName("strIngredient3")
#Expose
private String strIngredient3;
#SerializedName("strIngredient4")
#Expose
private String strIngredient4;
#SerializedName("strIngredient5")
#Expose
private String strIngredient5;
#SerializedName("strIngredient6")
#Expose
private String strIngredient6;
#SerializedName("strIngredient7")
#Expose
private String strIngredient7;
#SerializedName("strIngredient8")
#Expose
private String strIngredient8;
#SerializedName("strIngredient9")
#Expose
private String strIngredient9;
#SerializedName("strIngredient10")
#Expose
private String strIngredient10;
#SerializedName("strIngredient11")
#Expose
private String strIngredient11;
#SerializedName("strIngredient12")
#Expose
private String strIngredient12;
#SerializedName("strIngredient13")
#Expose
private String strIngredient13;
#SerializedName("strIngredient14")
#Expose
private String strIngredient14;
#SerializedName("strIngredient15")
#Expose
private String strIngredient15;
#SerializedName("strMeasure1")
#Expose
private String strMeasure1;
#SerializedName("strMeasure2")
#Expose
private String strMeasure2;
#SerializedName("strMeasure3")
#Expose
private String strMeasure3;
#SerializedName("strMeasure4")
#Expose
private String strMeasure4;
#SerializedName("strMeasure5")
#Expose
private String strMeasure5;
#SerializedName("strMeasure6")
#Expose
private String strMeasure6;
#SerializedName("strMeasure7")
#Expose
private String strMeasure7;
#SerializedName("strMeasure8")
#Expose
private String strMeasure8;
#SerializedName("strMeasure9")
#Expose
private String strMeasure9;
#SerializedName("strMeasure10")
#Expose
private String strMeasure10;
#SerializedName("strMeasure11")
#Expose
private String strMeasure11;
#SerializedName("strMeasure12")
#Expose
private String strMeasure12;
#SerializedName("strMeasure13")
#Expose
private String strMeasure13;
#SerializedName("strMeasure14")
#Expose
private String strMeasure14;
#SerializedName("strMeasure15")
#Expose
private String strMeasure15;
#SerializedName("dateModified")
#Expose
private String dateModified;
public String getIdDrink() {
return idDrink;
}
public void setIdDrink(String idDrink) {
this.idDrink = idDrink;
}
public String getStrDrink() {
return strDrink;
}
public void setStrDrink(String strDrink) {
this.strDrink = strDrink;
}
public Object getStrVideo() {
return strVideo;
}
public void setStrVideo(Object strVideo) {
this.strVideo = strVideo;
}
public String getStrCategory() {
return strCategory;
}
public void setStrCategory(String strCategory) {
this.strCategory = strCategory;
}
public Object getStrIBA() {
return strIBA;
}
public void setStrIBA(Object strIBA) {
this.strIBA = strIBA;
}
public String getStrAlcoholic() {
return strAlcoholic;
}
public void setStrAlcoholic(String strAlcoholic) {
this.strAlcoholic = strAlcoholic;
}
public String getStrGlass() {
return strGlass;
}
public void setStrGlass(String strGlass) {
this.strGlass = strGlass;
}
public String getStrInstructions() {
return strInstructions;
}
public void setStrInstructions(String strInstructions) {
this.strInstructions = strInstructions;
}
public String getStrDrinkThumb() {
return strDrinkThumb;
}
public void setStrDrinkThumb(String strDrinkThumb) {
this.strDrinkThumb = strDrinkThumb;
}
public String getStrIngredient1() {
return strIngredient1;
}
public void setStrIngredient1(String strIngredient1) {
this.strIngredient1 = strIngredient1;
}
public String getStrIngredient2() {
return strIngredient2;
}
public void setStrIngredient2(String strIngredient2) {
this.strIngredient2 = strIngredient2;
}
public String getStrIngredient3() {
return strIngredient3;
}
public void setStrIngredient3(String strIngredient3) {
this.strIngredient3 = strIngredient3;
}
public String getStrIngredient4() {
return strIngredient4;
}
public void setStrIngredient4(String strIngredient4) {
this.strIngredient4 = strIngredient4;
}
public String getStrIngredient5() {
return strIngredient5;
}
public void setStrIngredient5(String strIngredient5) {
this.strIngredient5 = strIngredient5;
}
public String getStrIngredient6() {
return strIngredient6;
}
public void setStrIngredient6(String strIngredient6) {
this.strIngredient6 = strIngredient6;
}
public String getStrIngredient7() {
return strIngredient7;
}
public void setStrIngredient7(String strIngredient7) {
this.strIngredient7 = strIngredient7;
}
public String getStrIngredient8() {
return strIngredient8;
}
public void setStrIngredient8(String strIngredient8) {
this.strIngredient8 = strIngredient8;
}
public String getStrIngredient9() {
return strIngredient9;
}
public void setStrIngredient9(String strIngredient9) {
this.strIngredient9 = strIngredient9;
}
public String getStrIngredient10() {
return strIngredient10;
}
public void setStrIngredient10(String strIngredient10) {
this.strIngredient10 = strIngredient10;
}
public String getStrIngredient11() {
return strIngredient11;
}
public void setStrIngredient11(String strIngredient11) {
this.strIngredient11 = strIngredient11;
}
public String getStrIngredient12() {
return strIngredient12;
}
public void setStrIngredient12(String strIngredient12) {
this.strIngredient12 = strIngredient12;
}
public String getStrIngredient13() {
return strIngredient13;
}
public void setStrIngredient13(String strIngredient13) {
this.strIngredient13 = strIngredient13;
}
public String getStrIngredient14() {
return strIngredient14;
}
public void setStrIngredient14(String strIngredient14) {
this.strIngredient14 = strIngredient14;
}
public String getStrIngredient15() {
return strIngredient15;
}
public void setStrIngredient15(String strIngredient15) {
this.strIngredient15 = strIngredient15;
}
public String getStrMeasure1() {
return strMeasure1;
}
public void setStrMeasure1(String strMeasure1) {
this.strMeasure1 = strMeasure1;
}
public String getStrMeasure2() {
return strMeasure2;
}
public void setStrMeasure2(String strMeasure2) {
this.strMeasure2 = strMeasure2;
}
public String getStrMeasure3() {
return strMeasure3;
}
public void setStrMeasure3(String strMeasure3) {
this.strMeasure3 = strMeasure3;
}
public String getStrMeasure4() {
return strMeasure4;
}
public void setStrMeasure4(String strMeasure4) {
this.strMeasure4 = strMeasure4;
}
public String getStrMeasure5() {
return strMeasure5;
}
public void setStrMeasure5(String strMeasure5) {
this.strMeasure5 = strMeasure5;
}
public String getStrMeasure6() {
return strMeasure6;
}
public void setStrMeasure6(String strMeasure6) {
this.strMeasure6 = strMeasure6;
}
public String getStrMeasure7() {
return strMeasure7;
}
public void setStrMeasure7(String strMeasure7) {
this.strMeasure7 = strMeasure7;
}
public String getStrMeasure8() {
return strMeasure8;
}
public void setStrMeasure8(String strMeasure8) {
this.strMeasure8 = strMeasure8;
}
public String getStrMeasure9() {
return strMeasure9;
}
public void setStrMeasure9(String strMeasure9) {
this.strMeasure9 = strMeasure9;
}
public String getStrMeasure10() {
return strMeasure10;
}
public void setStrMeasure10(String strMeasure10) {
this.strMeasure10 = strMeasure10;
}
public String getStrMeasure11() {
return strMeasure11;
}
public void setStrMeasure11(String strMeasure11) {
this.strMeasure11 = strMeasure11;
}
public String getStrMeasure12() {
return strMeasure12;
}
public void setStrMeasure12(String strMeasure12) {
this.strMeasure12 = strMeasure12;
}
public String getStrMeasure13() {
return strMeasure13;
}
public void setStrMeasure13(String strMeasure13) {
this.strMeasure13 = strMeasure13;
}
public String getStrMeasure14() {
return strMeasure14;
}
public void setStrMeasure14(String strMeasure14) {
this.strMeasure14 = strMeasure14;
}
public String getStrMeasure15() {
return strMeasure15;
}
public void setStrMeasure15(String strMeasure15) {
this.strMeasure15 = strMeasure15;
}
public String getDateModified() {
return dateModified;
}
public void setDateModified(String dateModified) {
this.dateModified = dateModified;
}
And my API call is as follows:
#Override
protected Cocktail doInBackground(Cocktail... cocktails) {
Call<Cocktails> call = mApiService.getCocktail(id);
try {
Response<Cocktails> response = call.execute();
this.cocktails = response.body();
this.cocktail = this.cocktails.getCocktail().get(0);
Log.i(TAG, "Success: " + response.body().toString());
} catch (IOException e) {
Log.e(TAG, "IOException: " + e);
e.printStackTrace();
} catch (IllegalStateException e) {
Log.e(TAG, "IllegalStateException: " + e);
e.printStackTrace();
}
return cocktail;
}
I know enough to realise that a large number of variables, ingredients and measures (many of which are empty) is the wrong approach but i'm struggling to find a solution with retrofit to create an array of these values. I've not found any way to assign multiple SerializedNames to a single array variable?
The option that jumps out at me is looping through the response pulling out the key values in onSuccess but this seems to go against the simplicity of using retrofit?
I'm working with Mybatis to batch insert data,specifically my parameterType is a class,which has a List property,so I use foreach to do the traversal.But it didn't work,here are the debug and codes.Thanks.
DEBUG
here is the sql:
<insert id="batchInsertSn" parameterType="domain.collectSn.IbSnTransit">
insert into
ib_sn_transit (
sn, inbound_no, container_no,
goods_no,goods_name, owner_no,
owner_name,create_user,update_user,
create_time,update_time,yn,
org_no,org_name,distribute_no,
warehouse_no,receiving_no,supplier_no
,out_wave_no)
values
<foreach collection="snList" item="item" index="index" separator="," >
(
#{item.sn,jdbcType=VARCHAR}, #{inboundNo,jdbcType=VARCHAR}, #{containerNo,jdbcType=VARCHAR},
#{goodsNo,jdbcType=VARCHAR},#{goodsName,jdbcType=VARCHAR},#{ownerNo,jdbcType=VARCHAR},
#{ownerName,jdbcType=VARCHAR}, #{createUser,jdbcType=VARCHAR}, #{updateUser,jdbcType=VARCHAR},
now(),now(),#{yn,jdbcType=TINYINT},
#{orgNo,jdbcType=VARCHAR},#{orgName,jdbcType=VARCHAR},#{distributeNo,jdbcType=VARCHAR},
#{warehouseNo,jdbcType=VARCHAR},#{receivingNo,jdbcType=VARCHAR},#{supplierNo,jdbcType=VARCHAR}
,#{outWaveNo,jdbcType=VARCHAR}
)
</foreach>
</insert>
here is the class
public class IbSnTransit {
private String outWaveNo;
private String queryUser;
private String finishFlag;
private Integer id;
private String inboundNo;
private String sn;
private String snStart;
private String snEnd;
private String containerNo;
private String goodsNo;
private String goodsName;
private String ownerNo;
private String ownerName;
private String createUser;
private Date createTime;
private String updateUser;
private Date updateTime;
private Integer yn;
private String orgNo;
private String orgName;
private String distributeNo;
private String warehouseNo;
private String receivingNo;
private String supplierNo;
private List<String> snList;
public String getSupplierNo() {
return supplierNo;
}
public void setSupplierNo(String supplierNo) {
this.supplierNo = supplierNo;
}
public Integer getId() {
return id;
}
public void setId(Integer id){
this.id = id;
}
public String getOwnerName() {
return ownerName;
}
public void setOwnerName(String ownerName) {
this.ownerName = ownerName;
}
public String getOrgName() {
return orgName;
}
public void setOrgName(String orgName) {
this.orgName = orgName;
}
public String getSn() {
return sn;
}
public void setSn(String sn){
this.sn = sn;
}
public String getInboundNo() {
return inboundNo;
}
public void setInboundNo(String inboundNo) {
this.inboundNo = inboundNo;
}
public String getGoodsNo() {
return goodsNo;
}
public void setGoodsNo(String goodsNo) {
this.goodsNo = goodsNo;
}
public String getGoodsName() {
return goodsName;
}
public void setGoodsName(String goodsName) {
this.goodsName = goodsName;
}
public String getContainerNo() {
return containerNo;
}
public void setContainerNo(String containerNo) {
this.containerNo = containerNo;
}
public String getOwnerNo() {
return ownerNo;
}
public void setOwnerNo(String ownerNo) {
this.ownerNo = ownerNo;
}
public String getCreateUser() {
return createUser;
}
public void setCreateUser(String createUser) {
this.createUser = createUser;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public String getUpdateUser() {
return updateUser;
}
public void setUpdateUser(String updateUser) {
this.updateUser = updateUser;
}
public Date getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
public Integer getYn() {
return yn;
}
public void setYn(Integer yn) {
this.yn = yn;
}
public String getDistributeNo() {
return distributeNo;
}
public void setDistributeNo(String distributeNo) {
this.distributeNo = distributeNo;
}
public String getOrgNo() {
return orgNo;
}
public void setOrgNo(String orgNo) {
this.orgNo = orgNo;
}
public String getWarehouseNo() {
return warehouseNo;
}
public void setWarehouseNo(String warehouseNo) {
this.warehouseNo = warehouseNo;
}
public String getSnStart() {
return snStart;
}
public void setSnStart(String snStart) {
this.snStart = snStart;
}
public String getSnEnd() {
return snEnd;
}
public void setSnEnd(String snEnd) {
this.snEnd = snEnd;
}
public String getReceivingNo() {
return receivingNo;
}
public void setReceivingNo(String receivingNo) {
this.receivingNo = receivingNo;
}
public String getFinishFlag() {
return finishFlag;
}
public void setFinishFlag(String finishFlag) {
this.finishFlag = finishFlag;
}
public String getQueryUser() {
return queryUser;
}
public void setQueryUser(String queryUser) {
this.queryUser = queryUser;
}
public String getOutWaveNo() {
return outWaveNo;
}
public void setOutWaveNo(String outWaveNo) {
this.outWaveNo = outWaveNo;
}
public List<String> getSnList() {
return snList;
}
public void setSnList(List<String> snList) {
this.snList = snList;
}
}
the result
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named '' in 'class java.lang.String'
IbSnTransit.snList is declared as List of String.class objects so, when you use #{item.sn,jdbcType=VARCHAR} in your mapper you are asked for a property sn in the String.class. Maybe you must use #{item,jdbcType=VARCHAR} instead.
I have an object with these attributes:
public final class CaseNote {
private final Long caseNoteId;
private final Long subGroupId;
private final String title;
private final String caseNoteTypeCode;
private final Date contactDate;
private final Date completedDateTime;
private final Long personVisitId;
private final Date createdDateTime;
private final Long createdByWorkerId;
private final Long createdByTeamId;
private final List<CaseNoteDetailsDTO> noteDetails = new ArrayList<CaseNoteDetailsDTO>();
private final List<GroupMemberDetailsDTO> selectedMembers = new ArrayList<GroupMemberDetailsDTO>();
private final ReferenceProvider referenceProvider;
private final Date timeOutDate;
public CaseNote(final CaseNotesDTO caseNoteDto, final List<CaseNoteDetailsDTO> noteDetails,
final List<GroupMemberDetailsDTO> selectedMembers, final ReferenceProvider referenceProvider) {
this.caseNoteId = caseNoteDto.getCaseNoteId();
this.subGroupId = caseNoteDto.getSubGroupId();
this.title = caseNoteDto.getTitle();
this.caseNoteTypeCode = caseNoteDto.getCaseNoteTypeCode();
this.contactDate = caseNoteDto.getContactDateTime();
this.completedDateTime = caseNoteDto.getCompletedDateTime();
this.personVisitId = caseNoteDto.getPersonVisitId();
this.createdDateTime = caseNoteDto.getCreatedDateTime();
this.createdByWorkerId = caseNoteDto.getCreatedByWorkerId();
this.createdByTeamId = caseNoteDto.getCreatedByTeamId();
this.timeOutDate = caseNoteDto.getTimeOutDate();
this.noteDetails.clear();
this.selectedMembers.clear();
this.noteDetails.addAll(noteDetails);
Collections.sort(this.noteDetails, new CaseNoteDetailCreatedDateComparator());
this.selectedMembers.addAll(selectedMembers);
this.referenceProvider = referenceProvider;
}
private class CaseNoteDetailCreatedDateComparator implements Comparator<CaseNoteDetailsDTO> {
#Override
public int compare(final CaseNoteDetailsDTO firstCaseNoteDetail, final CaseNoteDetailsDTO secondCaseNoteDetail) {
return firstCaseNoteDetail.getCreatedDateTime().compareTo(secondCaseNoteDetail.getCreatedDateTime());
}
}
public Long getCaseNoteId() {
return caseNoteId;
}
public Long getSubGroupId() {
return subGroupId;
}
public String getTitle() {
return title;
}
public String getCaseNoteTypeCode() {
return caseNoteTypeCode;
}
public Date getContactDate() {
return contactDate;
}
public Date getCompletedDateTime() {
return completedDateTime;
}
public Long getPersonVisitId() {
return personVisitId;
}
public Date getCreatedDateTime() {
return createdDateTime;
}
public Long getCreatedByWorkerId() {
return createdByWorkerId;
}
public Long getCreatedByTeamId() {
return createdByTeamId;
}
public List<CaseNoteDetailsDTO> getNoteDetails() {
return Collections.unmodifiableList(noteDetails);
}
public List<GroupMemberDetailsDTO> getSelectedMembers() {
return Collections.unmodifiableList(selectedMembers);
}
public boolean isSignificant() {
boolean significantEvent = false;
for (final CaseNoteDetailsDTO detail : this.getNoteDetails()) {
significantEvent = significantEvent || detail.isSignificantEvent();
}
return significantEvent;
}
public String getCaseNoteTypeDescription() {
return referenceProvider.provide(ReferenceDomain.CASENOTE_TYPE, getCaseNoteTypeCode());
}
public CaseNoteDetailsDTO getRootNoteDetails() {
validateCaseNoteDetailsExists();
return getNoteDetails().get(0);
}
public List<CaseNoteDetailsDTO> getAppendments() {
validateCaseNoteDetailsExists();
return getNoteDetails().subList(1, getNoteDetails().size());
}
private void validateCaseNoteDetailsExists() {
if (getNoteDetails() == null || getNoteDetails().isEmpty()) {
throw new IllegalStateException("No case note details found");
}
}
public List<String> getMemberNames() {
final List<String> memberNames = new ArrayList<String>();
final List<GroupMemberDetailsDTO> selectedMembers = getSelectedMembers();
for (final GroupMemberDetailsDTO memberDetails : selectedMembers) {
memberNames.add(memberDetails.getName());
}
return memberNames;
}
public Date getTimeOutDate() {
return timeOutDate;
}
public boolean isTimedOut() {
return completedDateTime == null && new Date().after(this.timeOutDate);
}
}
From a JSP file, I would like to print the attribute 'createdWorkerId', but it's not working. I tried to print the title and it works, but not with the createdWorkerId. The line is the following:
<span class="highlighted"><%=noteClassDescription%>: <c:out value="${casenote.createdByWorkerId}"/> </span>
Should I parse the createdWorkerId to a String before or the problem is other? Any help appreciated.
Thanks.