Mybatis There is no getter for property - java

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.

Related

Jackson XML - Can't deserialize Boolean

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().

org.codehaus.jackson.map.JsonMappingException: Illegal type (de.db.kigbau.client.domain.Benutzer) to deserialize: prevented for security reasons

When sending the POST request from my angular client to my Rest API, I am getting the above error.
below is my request model coming from angular client:
{
"anmeldename":"KBBT765",
"nachname":"nach",
"vorname":"vor",
"telefonnummer":"4563",
"password":"szpi;ItM",
"rolle":"B",
"region":"Z",
"eiuname":"",
"zbname":"",
"evuname":"",
"spnv":false,
"spfv":false,
"sgv":false,
"fromEdit":false
}
Below is the rest API POST method to handle the request from angular client and parse the json fields to Benutzer Model:
#POST
#Path("speichern")
#Consumes(MediaType.APPLICATION_JSON)
public boolean speichern(Benutzer benutzerInfo) {
--------------
---------------
}
Rest API Benutzer Model is below:
#JsonIgnoreProperties(ignoreUnknown = true)
public class Benutzer implements Serializable {
private String nachname;
private String anmeldename;
private String vorname;
private String rolle;
private String region;
private String eiuname;
private String zbname;
private String evuname;
private String password;
private String telefonnummer;
private String defaultAnmeldname;
private Boolean spnv;
private Boolean spfv;
private Boolean sgv;
private Boolean fromEdit;
#JsonProperty("evuProfilelist")
private List<EvuProfilSelectedItem> evuProfilelist;
public void setRolle(String rolle) {
this.rolle = rolle;
}
public void setRegion(String region) {
this.region = region;
}
public void setEiuname(String eiuname) {
this.eiuname = eiuname;
}
public void setZbname(String zbname) {
this.zbname = zbname;
}
public void setEvuname(String evuname) {
this.evuname = evuname;
}
public void setSpnv(Boolean spnv) {
this.spnv = spnv;
}
public void setSpfv(Boolean spfv) {
this.spfv = spfv;
}
public void setSgv(Boolean sgv) {
this.sgv = sgv;
}
public String getRolle() {
return rolle;
}
public String getRegion() {
return region;
}
public String getEiuname() {
return eiuname;
}
public String getZbname() {
return zbname;
}
public String getEvuname() {
return evuname;
}
public Boolean isSpnv() {
return spnv;
}
public Boolean isSpfv() {
return spfv;
}
public Boolean isSgv() {
return sgv;
}
public void setPassword(String password) {
this.password = password;
}
public List<EvuProfilSelectedItem> getEvuProfilelist() {
return evuProfilelist;
}
public void setEvuProfilelist(List<EvuProfilSelectedItem> evuProfilelist) {
this.evuProfilelist = evuProfilelist;
}
public String getPassword() {
return password;
}
public String getTelefonnummer() {
return telefonnummer;
}
public void setTelefonnummer(String telefonnummer) {
this.telefonnummer = telefonnummer;
}
public String getNachname() {
return nachname;
}
public void setNachname(String nachname) {
this.nachname = nachname;
}
public String getAnmeldename() {
return anmeldename;
}
public void setAnmeldename(String anmeldename) {
this.anmeldename = anmeldename;
}
public String getVorname() {
return vorname;
}
public void setVorname(String vorname) {
this.vorname = vorname;
}
public Boolean isFromEdit() {
return fromEdit;
}
public void setFromEdit(Boolean fromEdit) {
this.fromEdit = fromEdit;
}
public String getDefaultAnmeldname() {
return defaultAnmeldname;
}
public void setDefaultAnmeldname(String defaultAnmeldname) {
this.defaultAnmeldname = defaultAnmeldname;
}
}
Stack Trace:
2020-03-05 06:42:57,017|ERROR|http-0.0.0.0:17206-4|kigbau.client.RestExceptionMapper||(Request-ID: 9fdG4mDBJWUqtjnqWhdx32) Propagating Exception to the client||| org.codehaus.jackson.map.JsonMappingException: Illegal type (de.db.kigbau.client.domain.Benutzer) to deserialize: prevented for security reasons at org.codehaus.jackson.map.deser.BeanDeserializerFactory.checkLegalTypes(BeanDeserializerFactory.java:1536) at org.codehaus.jackson.map.deser.BeanDeserializerFactory.createBeanDeserializer(BeanDeserializerFactory.java:668)
Is this due to blank or null values in the fields coming from angular client or some thing else?
Please help. Thank you in advance.

All JPA queries fail to find any result(even tho data is present in the MySQL DB)

I'm trying to set up javax.Persistence in my project, and I've started to use the basic approach:
EntityManagerGenerator
package olsa.amex.dao;
import javax.persistence.*;
public class EntityManagerGenerator {
private EntityManager currentSession;
private EntityTransaction currentTransaction;
public EntityManager openCurrentSession() {
if ((currentSession == null)||(currentSession != null && !currentSession.isOpen()))
currentSession = getSessionFactory().createEntityManager();
return currentSession;
}
public EntityManager openCurrentSessionwithTransaction() {
if ((currentSession == null)||(currentSession != null && !currentSession.isOpen()))
currentSession = getSessionFactory().createEntityManager();
currentTransaction = currentSession.getTransaction();
currentTransaction.begin();
return currentSession;
}
public void closeCurrentSession() {
if (currentSession != null && currentSession.isOpen())
currentSession.close();
}
public void closeCurrentSessionwithTransaction() {
if (currentSession != null && currentSession.isOpen()) {
currentTransaction.commit();
currentSession.close();
}
}
private static EntityManagerFactory getSessionFactory() {
EntityManagerFactory entityManager = Persistence.createEntityManagerFactory("JPAAmex");
return entityManager;
}
public EntityManager getCurrentSession() {
return currentSession;
}
public void setCurrentSession(EntityManager currentSession) {
this.currentSession = currentSession;
}
public EntityTransaction getCurrentTransaction() {
return currentTransaction;
}
public void setCurrentTransaction(EntityTransaction currentTransaction) {
this.currentTransaction = currentTransaction;
}
}
ViewAgentSsbDAO(for now I have only implemented findAll and findById)
package olsa.amex.dao;
import java.util.List;
import javax.persistence.TypedQuery;
import com.olsa.amex.entities.ViewAgentssb;
public class ViewAgentSsbDAO implements IGenericDAO<ViewAgentssb,Integer> {
private EntityManagerGenerator hibernateSessionGenerator;
public ViewAgentSsbDAO() {
this.hibernateSessionGenerator = new EntityManagerGenerator();
}
public EntityManagerGenerator getHibernateSessionGenerator() {
return hibernateSessionGenerator;
}
#Override
public void persist(ViewAgentssb entity) throws Exception{
throw new UnsupportedOperationException();
}
#Override
public void update(ViewAgentssb entity) throws Exception {
throw new UnsupportedOperationException();
}
#Override
public ViewAgentssb findById(Integer id) throws Exception{
TypedQuery<ViewAgentssb> query = hibernateSessionGenerator.getCurrentSession().createQuery("from com.olsa.amex.entities.ViewAgentssb as v where v.IDAgent = :id", ViewAgentssb.class);
query.setParameter("id", id);
ViewAgentssb view = query.getSingleResult();
return view;
}
#Override
public void delete(ViewAgentssb entity) throws Exception {
throw new UnsupportedOperationException();
}
#Override
public List<ViewAgentssb> findAll() throws Exception{
List<ViewAgentssb> views = hibernateSessionGenerator.getCurrentSession().createQuery("from com.olsa.amex.entities.ViewAgentssb", ViewAgentssb.class).getResultList();
return views;
}
#Override
public void deleteAll() throws Exception{
throw new UnsupportedOperationException();
}
}
The service class:
package olsa.amex.services;
import java.util.List;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import com.olsa.amex.entities.ViewAgentssb;
import olsa.amex.dao.ViewAgentSsbDAO;
public class ViewAgentSsbService implements IGenericService<ViewAgentssb,Integer> {
private ViewAgentSsbDAO viewAgentSsbDAO;
private Logger logger = LogManager.getLogger(ViewAgentSsbService.class);
public ViewAgentSsbService() {
this.viewAgentSsbDAO = new ViewAgentSsbDAO();
}
#Override
public void persist(ViewAgentssb entity) throws Exception{
throw new UnsupportedOperationException();
}
#Override
public void update(ViewAgentssb entity) throws Exception{
throw new UnsupportedOperationException();
}
#Override
public ViewAgentssb findById(Integer id) throws Exception {
viewAgentSsbDAO.getHibernateSessionGenerator().openCurrentSession();
ViewAgentssb object = viewAgentSsbDAO.findById(id);
viewAgentSsbDAO.getHibernateSessionGenerator().closeCurrentSession();
return object;
}
#Override
public void delete(ViewAgentssb entity) throws Exception{
throw new UnsupportedOperationException();
}
#Override
public List<ViewAgentssb> findAll() throws Exception{
logger.debug("Sto iniziando la query findAll() per l'entity + " + ViewAgentssb.class);
viewAgentSsbDAO.getHibernateSessionGenerator().openCurrentSession();
List<ViewAgentssb> views = viewAgentSsbDAO.findAll();
logger.debug("La query ha ritornato i seguenti risultati: + " + views.toString());
viewAgentSsbDAO.getHibernateSessionGenerator().closeCurrentSession();
return views;
}
#Override
public void deleteAll() throws Exception{
throw new UnsupportedOperationException();
}
}
the Entity:
package com.olsa.amex.entities;
import java.io.Serializable;
import javax.persistence.*;
/**
* The persistent class for the view_agentssbs database table.
*
*/
#Entity
#Table(name="view_agentssbs")
#NamedQuery(name="ViewAgentssb.findAll", query="SELECT v FROM ViewAgentssb v")
public class ViewAgentssb implements Serializable {
private static final long serialVersionUID = 1L;
private int active;
private String agencyName;
#Lob
private String agentCode;
#Lob
private String agentName;
#Lob
private String agentPassword;
#Lob
private String agentSurname;
#Lob
private String agentUsername;
private int bExist;
#Lob
private String buyed_visure;
#Lob
private String cervedCreation;
#Lob
private String cervedDisable;
#Lob
private String cervedPassword;
#Lob
private String cervedUsername;
#Lob
private String channel_Code;
private int checkBackOffice;
#Lob
private String codiceOAM;
#Lob
private String company_cancelled_counter;
#Lob
private String company_failed_counter;
#Lob
private String company_inactive_counter;
private String countryResidence;
#Id
private String deviceID;
private String documentExpiryDate;
private String documentIssueBy;
private String documentIssuedOn;
private String documentNumber;
private String documentType;
private String email;
private int enableCrif;
private int enableVisura;
private String expr1;
#Lob
private String failed_search;
#Lob
private String groupAvatar;
#Lob
private String groupName;
private int IDAgency;
private int IDAgent;
private int IDAreaRegion;
private int IDGroup;
private int IDSubRegion;
private byte isSimpleSignature;
#Lob
private String partnerID;
#Lob
private String photo;
private String pin;
#Lob
private String protestPrejudical;
private String regione;
private String role;
private String socialSecurityNumber;
private String subRegion;
private String telephoneCell;
#Lob
private String userActive;
#Lob
private String userBOAsAgent;
#Lob
private String userCreation;
#Lob
private String userDisable;
private int userHasSignature;
private String userID;
#Lob
private String userPasswordExpired;
private int userResetPassword;
#Lob
private String userToken;
#Lob
private String venueCode;
public ViewAgentssb() {
}
public int getActive() {
return this.active;
}
public void setActive(int active) {
this.active = active;
}
public String getAgencyName() {
return this.agencyName;
}
public void setAgencyName(String agencyName) {
this.agencyName = agencyName;
}
public String getAgentCode() {
return this.agentCode;
}
public void setAgentCode(String agentCode) {
this.agentCode = agentCode;
}
public String getAgentName() {
return this.agentName;
}
public void setAgentName(String agentName) {
this.agentName = agentName;
}
public String getAgentPassword() {
return this.agentPassword;
}
public void setAgentPassword(String agentPassword) {
this.agentPassword = agentPassword;
}
public String getAgentSurname() {
return this.agentSurname;
}
public void setAgentSurname(String agentSurname) {
this.agentSurname = agentSurname;
}
public String getAgentUsername() {
return this.agentUsername;
}
public void setAgentUsername(String agentUsername) {
this.agentUsername = agentUsername;
}
public int getBExist() {
return this.bExist;
}
public void setBExist(int bExist) {
this.bExist = bExist;
}
public String getBuyed_visure() {
return this.buyed_visure;
}
public void setBuyed_visure(String buyed_visure) {
this.buyed_visure = buyed_visure;
}
public String getCervedCreation() {
return this.cervedCreation;
}
public void setCervedCreation(String cervedCreation) {
this.cervedCreation = cervedCreation;
}
public String getCervedDisable() {
return this.cervedDisable;
}
public void setCervedDisable(String cervedDisable) {
this.cervedDisable = cervedDisable;
}
public String getCervedPassword() {
return this.cervedPassword;
}
public void setCervedPassword(String cervedPassword) {
this.cervedPassword = cervedPassword;
}
public String getCervedUsername() {
return this.cervedUsername;
}
public void setCervedUsername(String cervedUsername) {
this.cervedUsername = cervedUsername;
}
public String getChannel_Code() {
return this.channel_Code;
}
public void setChannel_Code(String channel_Code) {
this.channel_Code = channel_Code;
}
public int getCheckBackOffice() {
return this.checkBackOffice;
}
public void setCheckBackOffice(int checkBackOffice) {
this.checkBackOffice = checkBackOffice;
}
public String getCodiceOAM() {
return this.codiceOAM;
}
public void setCodiceOAM(String codiceOAM) {
this.codiceOAM = codiceOAM;
}
public String getCompany_cancelled_counter() {
return this.company_cancelled_counter;
}
public void setCompany_cancelled_counter(String company_cancelled_counter) {
this.company_cancelled_counter = company_cancelled_counter;
}
public String getCompany_failed_counter() {
return this.company_failed_counter;
}
public void setCompany_failed_counter(String company_failed_counter) {
this.company_failed_counter = company_failed_counter;
}
public String getCompany_inactive_counter() {
return this.company_inactive_counter;
}
public void setCompany_inactive_counter(String company_inactive_counter) {
this.company_inactive_counter = company_inactive_counter;
}
public String getCountryResidence() {
return this.countryResidence;
}
public void setCountryResidence(String countryResidence) {
this.countryResidence = countryResidence;
}
public String getDeviceID() {
return this.deviceID;
}
public void setDeviceID(String deviceID) {
this.deviceID = deviceID;
}
public String getDocumentExpiryDate() {
return this.documentExpiryDate;
}
public void setDocumentExpiryDate(String documentExpiryDate) {
this.documentExpiryDate = documentExpiryDate;
}
public String getDocumentIssueBy() {
return this.documentIssueBy;
}
public void setDocumentIssueBy(String documentIssueBy) {
this.documentIssueBy = documentIssueBy;
}
public String getDocumentIssuedOn() {
return this.documentIssuedOn;
}
public void setDocumentIssuedOn(String documentIssuedOn) {
this.documentIssuedOn = documentIssuedOn;
}
public String getDocumentNumber() {
return this.documentNumber;
}
public void setDocumentNumber(String documentNumber) {
this.documentNumber = documentNumber;
}
public String getDocumentType() {
return this.documentType;
}
public void setDocumentType(String documentType) {
this.documentType = documentType;
}
public String getEmail() {
return this.email;
}
public void setEmail(String email) {
this.email = email;
}
public int getEnableCrif() {
return this.enableCrif;
}
public void setEnableCrif(int enableCrif) {
this.enableCrif = enableCrif;
}
public int getEnableVisura() {
return this.enableVisura;
}
public void setEnableVisura(int enableVisura) {
this.enableVisura = enableVisura;
}
public String getExpr1() {
return this.expr1;
}
public void setExpr1(String expr1) {
this.expr1 = expr1;
}
public String getFailed_search() {
return this.failed_search;
}
public void setFailed_search(String failed_search) {
this.failed_search = failed_search;
}
public String getGroupAvatar() {
return this.groupAvatar;
}
public void setGroupAvatar(String groupAvatar) {
this.groupAvatar = groupAvatar;
}
public String getGroupName() {
return this.groupName;
}
public void setGroupName(String groupName) {
this.groupName = groupName;
}
public int getIDAgency() {
return this.IDAgency;
}
public void setIDAgency(int IDAgency) {
this.IDAgency = IDAgency;
}
public int getIDAgent() {
return this.IDAgent;
}
public void setIDAgent(int IDAgent) {
this.IDAgent = IDAgent;
}
public int getIDAreaRegion() {
return this.IDAreaRegion;
}
public void setIDAreaRegion(int IDAreaRegion) {
this.IDAreaRegion = IDAreaRegion;
}
public int getIDGroup() {
return this.IDGroup;
}
public void setIDGroup(int IDGroup) {
this.IDGroup = IDGroup;
}
public int getIDSubRegion() {
return this.IDSubRegion;
}
public void setIDSubRegion(int IDSubRegion) {
this.IDSubRegion = IDSubRegion;
}
public byte getIsSimpleSignature() {
return this.isSimpleSignature;
}
public void setIsSimpleSignature(byte isSimpleSignature) {
this.isSimpleSignature = isSimpleSignature;
}
public String getPartnerID() {
return this.partnerID;
}
public void setPartnerID(String partnerID) {
this.partnerID = partnerID;
}
public String getPhoto() {
return this.photo;
}
public void setPhoto(String photo) {
this.photo = photo;
}
public String getPin() {
return this.pin;
}
public void setPin(String pin) {
this.pin = pin;
}
public String getProtestPrejudical() {
return this.protestPrejudical;
}
public void setProtestPrejudical(String protestPrejudical) {
this.protestPrejudical = protestPrejudical;
}
public String getRegione() {
return this.regione;
}
public void setRegione(String regione) {
this.regione = regione;
}
public String getRole() {
return this.role;
}
public void setRole(String role) {
this.role = role;
}
public String getSocialSecurityNumber() {
return this.socialSecurityNumber;
}
public void setSocialSecurityNumber(String socialSecurityNumber) {
this.socialSecurityNumber = socialSecurityNumber;
}
public String getSubRegion() {
return this.subRegion;
}
public void setSubRegion(String subRegion) {
this.subRegion = subRegion;
}
public String getTelephoneCell() {
return this.telephoneCell;
}
public void setTelephoneCell(String telephoneCell) {
this.telephoneCell = telephoneCell;
}
public String getUserActive() {
return this.userActive;
}
public void setUserActive(String userActive) {
this.userActive = userActive;
}
public String getUserBOAsAgent() {
return this.userBOAsAgent;
}
public void setUserBOAsAgent(String userBOAsAgent) {
this.userBOAsAgent = userBOAsAgent;
}
public String getUserCreation() {
return this.userCreation;
}
public void setUserCreation(String userCreation) {
this.userCreation = userCreation;
}
public String getUserDisable() {
return this.userDisable;
}
public void setUserDisable(String userDisable) {
this.userDisable = userDisable;
}
public int getUserHasSignature() {
return this.userHasSignature;
}
public void setUserHasSignature(int userHasSignature) {
this.userHasSignature = userHasSignature;
}
public String getUserID() {
return this.userID;
}
public void setUserID(String userID) {
this.userID = userID;
}
public String getUserPasswordExpired() {
return this.userPasswordExpired;
}
public void setUserPasswordExpired(String userPasswordExpired) {
this.userPasswordExpired = userPasswordExpired;
}
public int getUserResetPassword() {
return this.userResetPassword;
}
public void setUserResetPassword(int userResetPassword) {
this.userResetPassword = userResetPassword;
}
public String getUserToken() {
return this.userToken;
}
public void setUserToken(String userToken) {
this.userToken = userToken;
}
public String getVenueCode() {
return this.venueCode;
}
public void setVenueCode(String venueCode) {
this.venueCode = venueCode;
}
}
persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns /persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="JPAAmex" transaction- type="RESOURCE_LOCAL">
<class>com.olsa.amex.entities.Agency</class>
<class>com.olsa.amex.entities.AgencyRegionView</class>
<class>com.olsa.amex.entities.Agent</class>
<class>com.olsa.amex.entities.AgentAgencyRegionAndSubRegionRel</class>
<class>com.olsa.amex.entities.AgentGroup</class>
<class>com.olsa.amex.entities.AgentsInfo</class>
<class>com.olsa.amex.entities.AmexStatoPriorita</class>
<class>com.olsa.amex.entities.AmexXEROXField</class>
<class>com.olsa.amex.entities.AmexXEROXSection</class>
<class>com.olsa.amex.entities.Application</class>
<class>com.olsa.amex.entities.ApplicationField</class>
<class>com.olsa.amex.entities.ApplicationFieldStatus</class>
<class>com.olsa.amex.entities.ApplicationFieldTemplate</class>
<class>com.olsa.amex.entities.ApplicationFieldTemplateFixedValue</class>
<class>com.olsa.amex.entities.ApplicationOfferAndRegionRel</class>
<class>com.olsa.amex.entities.ApplicationOfferSuppBaseRel</class>
<class>com.olsa.amex.entities.ApplicationPacakge</class>
<class>com.olsa.amex.entities.ApplicationPackageArkDap</class>
<class>com.olsa.amex.entities.ApplicationSection</class>
<class>com.olsa.amex.entities.ApplicationSectionPdf</class>
<class>com.olsa.amex.entities.ApplicationSectionTemplate</class>
<class>com.olsa.amex.entities.ApplicationSignaturePDF</class>
<class>com.olsa.amex.entities.ApplicationStatus</class>
<class>com.olsa.amex.entities.ApplicationTemplate</class>
<class>com.olsa.amex.entities.ApplicationTrace</class>
<class>com.olsa.amex.entities.Applicationproductoffer</class>
<class>com.olsa.amex.entities.AreaRegion</class>
<class>com.olsa.amex.entities.AreaSubRegion</class>
<class>com.olsa.amex.entities.AreamanagerAgent</class>
<class>com.olsa.amex.entities.BankList</class>
<class>com.olsa.amex.entities.Cab</class>
<class>com.olsa.amex.entities.CabList</class>
<class>com.olsa.amex.entities.CervedCredenzial</class>
<class>com.olsa.amex.entities.Comuni</class>
<class>com.olsa.amex.entities.ConfigurazioneSegnalazione</class>
<class>com.olsa.amex.entities.Cordinate_Firma_Agente</class>
<class>com.olsa.amex.entities.Crif</class>
<class>com.olsa.amex.entities.ErrorSqlTrace</class>
<class>com.olsa.amex.entities.InternationalTelPrefix</class>
<class>com.olsa.amex.entities.Level_Rule</class>
<class>com.olsa.amex.entities.Nazionalita</class>
<class>com.olsa.amex.entities.NazioniIso</class>
<class>com.olsa.amex.entities.New</class>
<class>com.olsa.amex.entities.SBS_OfferList</class>
<class>com.olsa.amex.entities.SbsOfferlist</class>
<class>com.olsa.amex.entities.SectionStatus</class>
<class>com.olsa.amex.entities.SegnalazioneApplicationSection</class>
<class>com.olsa.amex.entities.Segnalazioni</class>
<class>com.olsa.amex.entities.StorageCervedVisure</class>
<class>com.olsa.amex.entities.Sysdiagram</class>
<class>com.olsa.amex.entities.Teamleader_AM</class>
<class>com.olsa.amex.entities.TempSignersInfo</class>
<class>com.olsa.amex.entities.TemplateAppkeyStore</class>
<class>com.olsa.amex.entities.TipologiaSegnalazione</class>
<class>com.olsa.amex.entities.TokenPushService</class>
<class>com.olsa.amex.entities.UsedPassword</class>
<class>com.olsa.amex.entities.VersionMobile</class>
<class>com.olsa.amex.entities.ViewAgencyareaandsubareaofferrelation</class>
<class>com.olsa.amex.entities.ViewAgentagencyregionandsubregionrel</class>
<class>com.olsa.amex.entities.ViewAgentsOfAreamanager</class>
<class>com.olsa.amex.entities.ViewAgentssb</class>
<class>com.olsa.amex.entities.ViewApplicationagent</class>
<class>com.olsa.amex.entities.ViewApplicationsegnalazionibackoffice</class>
<class>com.olsa.amex.entities.ViewAreamanagersOfTeamleader</class>
<class>com.olsa.amex.entities.ViewArearegionsubregionrel</class>
<class>com.olsa.amex.entities.ViewControlloallegati</class>
<class>com.olsa.amex.entities.ViewControlloesistenzaagente</class>
<class>com.olsa.amex.entities.ViewGetagentscompleteWoutfk</class>
<class>com.olsa.amex.entities.ViewGetnew</class>
<class>com.olsa.amex.entities.ViewGetsectionandstatus</class>
<class>com.olsa.amex.entities.ViewSection_field</class>
<class>com.olsa.amex.entities.ViewSectioncbsu</class>
<class>com.olsa.amex.entities.ViewXroxsectionandfield</class>
<class>com.olsa.amex.entities.VisureType</class>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://rmarjboss-001c.customer.olsa:3306/amex_digital_test_dev"/>
<property name="javax.persistence.jdbc.user" value="user"/>
<property name="javax.persistence.jdbc.password" value="*******"/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.cj.jdbc.Driver"/>
<property name="hibernate.show_sql" value="true"/>
</properties>
</persistence-unit>
And here's the code I used to test out everything:
try {
logger.info("Hibernate test");
ViewAgentSsbService service = new ViewAgentSsbService();
List<ViewAgentssb> entities = service.findAll();
logger.info(entities.toString());
} catch (Exception e1) {
logger.info("Failed... " + e1.getMessage());
ErrorUtility.getError(e1);
}
And the query successfully starts, but it always returns an empty list, even tho there is data present in the MySQL DB.
EDIT: I know I can use the Repositories, but for now I just want to check if everything works as it should.
I found the problem, apparently it was all caused by the wrong jdbc connection string.
In order to generate the entities I used the following string:
jdbc:mysql://rmarjboss-001c.customer.olsa:3306/amex_digital_sbs_dev?useUnicode=yes&characterEncoding=UTF-8
What I used in my persistence.xml is this:
jdbc:mysql://rmarjboss-001c.customer.olsa:3306/amex_digital_sbs_dev
In order for everything to work correctly, I had to set the correct string in my persistence.xml:
jdbc:mysql://rmarjboss-001c.customer.olsa:3306/amex_digital_sbs_dev?useUnicode=yes&characterEncoding=UTF-8

Assigning multiple Retrofit response values to an arraylist

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?

JAXB Unmarshaller not processing lists in XML correctly

I'm using the JAXB Unmarshaller to convert an XML string into a Java object structure (using Java 7; Java 8 is not an option at this time). I'm having a problem with lists of objects though. (I apologize in advance for all the code included.) This is the input XML string:
<claimImportCompositeDTO>
<claimId>900</claimId>
<claimNumber>AT0000000000018</claimNumber>
<claimDTO>
<recordId>900</recordId>
<version>1</version>
<clmAddress>
<recordId>900</recordId>
<version>0</version>
</clmAddress>
<claimStatus>
<expired class="list">
<claimStatusDTO>
<recordId>900</recordId>
<version>1</version>
</claimStatusDTO>
<claimStatusDTO>
<recordId>910</recordId>
<version>2</version>
</claimStatusDTO>
</expired>
<statusCompleteWorkItemFlag>false</statusCompleteWorkItemFlag>
</claimStatus>
</claimDTO>
<notes class="list">
<notepadDTO>
<recordId>3503</recordId>
<version>0</version>
<notepadText class="list">
<notepadTextDTO>
<recordId>3503</recordId>
<version>0</version>
</notepadTextDTO>
<notepadTextDTO>
<recordId>3504</recordId>
<version>0</version>
</notepadTextDTO>
</notepadText>
</notepadDTO>
</notes>
</claimImportCompositeDTO>
This is the definition for the various objects:
import java.util.List;
import javax.xml.bind.annotation.XmlRootElement;
#XmlRootElement
public class ClaimImportCompositeDTO {
private String _claimId;
private String _claimNumber;
private ClaimDTO _claimDTO;
private List<NotepadDTO> _notes;
public String getClaimId() {
return _claimId;
}
public String getClaimNumber() {
return _claimNumber;
}
public ClaimDTO getClaimDTO() {
return _claimDTO;
}
public List<NotepadDTO> getNotes() {
return _notes;
}
public void setClaimId(String claimId) {
this._claimId = claimId;
}
public void setClaimNumber(String claimNumber) {
this._claimNumber = claimNumber;
}
public void setClaimDTO(ClaimDTO claimDTO) {
this._claimDTO = claimDTO;
}
public void setNotes(List<NotepadDTO> notes) {
this._notes = notes;
}
}
public class ClaimDTO {
private String _recordId;
private String _version;
private ClmAddress _clmAddress;
private ClaimStatus _claimStatus;
public String getRecordId() {
return _recordId;
}
public String getVersion() {
return _version;
}
public ClmAddress getClmAddress() {
return _clmAddress;
}
public ClaimStatus getClaimStatus() {
return _claimStatus;
}
public void setRecordId(String recordId) {
this._recordId = recordId;
}
public void setVersion(String version) {
this._version = version;
}
public void setClmAddress(ClmAddress clmAddress) {
this._clmAddress = clmAddress;
}
public void setClaimStatus(ClaimStatus claimStatus) {
this._claimStatus = claimStatus;
}
}
public class ClmAddress {
private String _recordId;
private String _version;
public String getRecordId() {
return _recordId;
}
public String getVersion() {
return _version;
}
public void setRecordId(String recordId) {
this._recordId = recordId;
}
public void setVersion(String version) {
this._version = version;
}
}
import java.util.List;
public class ClaimStatus {
private List<ClaimStatusDTO> _expired;
private boolean _statusCompleteWorkItemFlag;
public List<ClaimStatusDTO> getExpired() {
return _expired;
}
public boolean isStatusCompleteWorkItemFlag() {
return _statusCompleteWorkItemFlag;
}
public void setExpired(List<ClaimStatusDTO> expired) {
this._expired = expired;
}
public void setStatusCompleteWorkItemFlag(boolean statusCompleteWorkItemFlag) {
this._statusCompleteWorkItemFlag = statusCompleteWorkItemFlag;
}
}
public class ClaimStatusDTO {
private String _recordId;
private String _version;
public String getRecordId() {
return _recordId;
}
public String getVersion() {
return _version;
}
public void setRecordId(String recordId) {
this._recordId = recordId;
}
public void setVersion(String version) {
this._version = version;
}
}
import java.util.List;
public class NotepadDTO {
private String _recordId;
private String _version;
private List<NotepadTextDTO> _notepadText;
public List<NotepadTextDTO> getNotepadText() {
return _notepadText;
}
public String getRecordId() {
return _recordId;
}
public String getVersion() {
return _version;
}
public void setNotepadText(List<NotepadTextDTO> notepadText) {
this._notepadText = notepadText;
}
public void setRecordId(String recordId) {
this._recordId = recordId;
}
public void setVersion(String version) {
this._version = version;
}
}
public class NotepadTextDTO {
private String _recordId;
private String _version;
public String getRecordId() {
return _recordId;
}
public String getVersion() {
return _version;
}
public void setRecordId(String recordId) {
this._recordId = recordId;
}
public void setVersion(String version) {
this._version = version;
}
}
This is the output:
<claimImportCompositeDTO>
<claimId>900</claimId>
<claimNumber>AT0000000000018</claimNumber>
<claimDTO>
<recordId>900</recordId>
<version>1</version>
<clmAddress>
<recordId>900</recordId>
<version>0</version>
</clmAddress>
<claimStatus>
<expired class="list">
<claimStatusDTO>
<recordId>null</recordId>
<version>null</version>
</claimStatusDTO>
</expired>
<statusCompleteWorkItemFlag>false</statusCompleteWorkItemFlag>
</claimStatus>
</claimDTO>
<notes class="list">
<notepadDTO>
<recordId>null</recordId>
<version>null</version>
<notepadText class="list"/>
</notepadDTO>
</notes>
</claimImportCompositeDTO>
When I run the unmarshaller, the non-list data is read correctly, but anything in a list is skipped. Well, one object is created (regardless of how many are in the list) and all of the fields are null (i.e., the claimsStatus -> expired list or the notes list).
I'm hoping I'm missing something fairly basic, but I've been unable to find what that may be. Any ideas?
The problem is that the xml provided does not correspond to the structure of the your POJOs. An easy way to fix it, following your existing setup and coding style is to add #XmlElementWrapper on the fields that are lists of items and change their names. You need to change the 3 following classes to how they look below and it will work:
#XmlRootElement
#XmlAccessorType(XmlAccessType.PROPERTY)
public class ClaimImportCompositeDTO {
private String _claimId;
private String _claimNumber;
private ClaimDTO _claimDTO;
private List<NotepadDTO> _notepadDTO;
public String getClaimId() {
return _claimId;
}
public String getClaimNumber() {
return _claimNumber;
}
public ClaimDTO getClaimDTO() {
return _claimDTO;
}
#XmlElementWrapper(name = "notes")
public List<NotepadDTO> getNotepadDTO() {
return _notepadDTO;
}
public void setClaimId(String claimId) {
this._claimId = claimId;
}
public void setClaimNumber(String claimNumber) {
this._claimNumber = claimNumber;
}
public void setClaimDTO(ClaimDTO claimDTO) {
this._claimDTO = claimDTO;
}
public void setNotepadDTO(List<NotepadDTO> notes) {
this._notepadDTO = notes;
}
}
ClaimStatus class would be:
#XmlAccessorType(XmlAccessType.PROPERTY)
public class ClaimStatus {
private List<ClaimStatusDTO> _claimStatusDTO;
private boolean _statusCompleteWorkItemFlag;
#XmlElementWrapper(name = "expired")
public List<ClaimStatusDTO> getClaimStatusDTO() {
return _claimStatusDTO;
}
public void setClaimStatusDTO(List<ClaimStatusDTO> claimStatusDto) {
this._claimStatusDTO = claimStatusDto;
}
public boolean isStatusCompleteWorkItemFlag() {
return _statusCompleteWorkItemFlag;
}
public void setStatusCompleteWorkItemFlag(boolean statusCompleteWorkItemFlag) {
this._statusCompleteWorkItemFlag = statusCompleteWorkItemFlag;
}
}
And NotepadDTO:
#XmlAccessorType(XmlAccessType.PROPERTY)
public class NotepadDTO {
private String _recordId;
private String _version;
private List<NotepadTextDTO> _notepadTextDTO;
#XmlElementWrapper(name = "notepadText")
public List<NotepadTextDTO> getNotepadTextDTO() {
return _notepadTextDTO;
}
public String getRecordId() {
return _recordId;
}
public String getVersion() {
return _version;
}
public void setNotepadTextDTO(List<NotepadTextDTO> notepadText) {
this._notepadTextDTO = notepadText;
}
public void setRecordId(String recordId) {
this._recordId = recordId;
}
public void setVersion(String version) {
this._version = version;
}
}
You need the #XmlElement annotation on the list. Something like this.
#XmlElement(name = "notepadDTO")
private List<NotepadDTO> _notes;
Here's a tutorial I used:
https://howtodoinjava.com/jaxb/jaxb-exmaple-marshalling-and-unmarshalling-list-or-set-of-objects/

Categories