how to implement Parcelable in android? - java

can you please tell me how to implement Parcelable in android? Actually I want to send an array list from one activity to another. So I google find in need to Parcelable the dot or model. But I have object of another class so how do I write in Parcelable? In other word
I have this object
DestinationStation destinationStation;
what should i write in this function public void writeToParcel
dest.writeString(destinationStation);
here is my code of both class
public class deparaturedaseboarddto implements Parcelable{
ArrayList<deparaturedaseboarddto> data;
public ArrayList<deparaturedaseboarddto> getData() {
return data;
}
public void setData(ArrayList<deparaturedaseboarddto> data) {
this.data = data;
}
#SerializedName("alertsId")
int alertsId;
#SerializedName("destExpArrival")
String destExpArrival;
#SerializedName("destSchArrival")
String destSchArrival;
#SerializedName("expDepart")
String expDepart;
#SerializedName("filteredStation")
String filteredStation;
#SerializedName("platformNo")
String platformNo;
#SerializedName("rid")
String rid;
#SerializedName("schDepart")
String schDepart;
#SerializedName("toc")
String toc;
#SerializedName("toExpArrival")
String toExpArrival;
#SerializedName("toSchArrival")
String toSchArrival;
#SerializedName("trainID")
String trainID;
#SerializedName("trainLastReportedAt")
String trainLastReportedAt;
#SerializedName("destinationStation")
DestinationStation destinationStation;
public deparaturedaseboarddto(String trainID,String toc,String trainLastReportedAt, String platformNo, String schDepart, String expDepart, int alertsId, String rid, String destSchArrival, String filteredStation, String destExpArrival, String toSchArrival, String toExpArrival,DestinationStation destinationStation){
super();
this.trainID=trainID;
this.toc=toc;
this.trainLastReportedAt=trainLastReportedAt;
this.platformNo=platformNo;
this.schDepart=schDepart;
this.expDepart=expDepart;
this.alertsId=alertsId;
this.destinationStation=destinationStation;
this.toExpArrival=toExpArrival;
this.toSchArrival=toSchArrival;
this.destExpArrival=destExpArrival;
this.filteredStation=filteredStation;
this.destSchArrival=destSchArrival;
this.rid=rid;
}
public DestinationStation getDestinationStation() {
return destinationStation;
}
public void setDestinationStation(DestinationStation destinationStation) {
this.destinationStation = destinationStation;
}
public int getAlertsId() {
return alertsId;
}
public void setAlertsId(int alertsId) {
this.alertsId = alertsId;
}
public String getDestExpArrival() {
return destExpArrival;
}
public void setDestExpArrival(String destExpArrival) {
this.destExpArrival = destExpArrival;
}
public String getDestSchArrival() {
return destSchArrival;
}
public void setDestSchArrival(String destSchArrival) {
this.destSchArrival = destSchArrival;
}
public String getExpDepart() {
return expDepart;
}
public void setExpDepart(String expDepart) {
this.expDepart = expDepart;
}
public String getFilteredStation() {
return filteredStation;
}
public void setFilteredStation(String filteredStation) {
this.filteredStation = filteredStation;
}
public String getPlatformNo() {
return platformNo;
}
public void setPlatformNo(String platformNo) {
this.platformNo = platformNo;
}
public String getRid() {
return rid;
}
public void setRid(String rid) {
this.rid = rid;
}
public String getSchDepart() {
return schDepart;
}
public void setSchDepart(String schDepart) {
this.schDepart = schDepart;
}
public String getToc() {
return toc;
}
public void setToc(String toc) {
this.toc = toc;
}
public String getToExpArrival() {
return toExpArrival;
}
public void setToExpArrival(String toExpArrival) {
this.toExpArrival = toExpArrival;
}
public String getToSchArrival() {
return toSchArrival;
}
public void setToSchArrival(String toSchArrival) {
this.toSchArrival = toSchArrival;
}
public String getTrainID() {
return trainID;
}
public void setTrainID(String trainID) {
this.trainID = trainID;
}
public String getTrainLastReportedAt() {
return trainLastReportedAt;
}
public void setTrainLastReportedAt(String trainLastReportedAt) {
this.trainLastReportedAt = trainLastReportedAt;
}
#Override
public int describeContents() {
// TODO Auto-generated method stub
return 0;
}
#Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(alertsId);
dest.writeString(destExpArrival);
dest.writeString(destSchArrival);
dest.writeString(expDepart);
dest.writeString(filteredStation);
dest.writeString(platformNo);
dest.writeString(rid);
dest.writeString(schDepart);
dest.writeString(toc);
dest.writeString(toExpArrival);
dest.writeString(toSchArrival);
dest.writeString(trainID);
dest.writeString(trainLastReportedAt);
dest.writeString(destinationStation);
}
public static final Parcelable.Creator<deparaturedaseboarddto> CREATOR = new Parcelable.Creator<deparaturedaseboarddto>() {
public deparaturedaseboarddto createFromParcel(Parcel in) {
return new deparaturedaseboarddto(in);
}
public deparaturedaseboarddto[] newArray(int size) {
return new deparaturedaseboarddto[size];
}
};
private deparaturedaseboarddto(Parcel in) {
this.alertsId=in.readInt();
this.destExpArrival=in.readString();
this.destSchArrival=in.readString();
this.expDepart=in.readString();
this.filteredStation=in.readString();
this.platformNo=in.readString();
this.rid=in.readString();
this.schDepart=in.readString();
this.toc=in.readString();
this.toExpArrival=in.readString();
this.toSchArrival=in.readString();
this.trainID=in.readString();
this.trainLastReportedAt=in.readString();
}
}
destinationstation:
import com.google.gson.annotations.SerializedName;
public class DestinationStation implements Parcelable {
#SerializedName("crsCode")
String crsCode;
#SerializedName("stationName")
String stationName;
public DestinationStation(String crsCode, String stationName) {
// TODO Auto-generated constructor stub
super();
this.crsCode=crsCode;
this.stationName=stationName;
}
public String getCrsCode() {
return crsCode;
}
public void setCrsCode(String crsCode) {
this.crsCode = crsCode;
}
public String getStationName() {
return stationName;
}
public void setStationName(String stationName) {
this.stationName = stationName;
}
#Override
public int describeContents() {
// TODO Auto-generated method stub
return 0;
}
#Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(crsCode);
dest.writeString(stationName);
}
public static final Parcelable.Creator<DestinationStation> CREATOR = new Parcelable.Creator<DestinationStation>() {
public DestinationStation createFromParcel(Parcel in) {
return new DestinationStation(in);
}
public DestinationStation[] newArray(int size) {
return new DestinationStation[size];
}
};
private DestinationStation(Parcel in) {
this.crsCode=in.readString();
this.stationName=in.readString();
}
}
I am getting error in this line
dest.writeString(destinationStation);
Could you please tell how to remove this error?

Related

How print the entire data structure created with Composite?

I have class-Composite:
public class CompositeText implements ComponentText {
private TypeComponent type;
private String value;
private final List<ComponentText> childComponents;
private CompositeText() {
childComponents = new ArrayList<>();
}
public CompositeText(String value, TypeComponent typeComponent) {
this.value = value;
this.type = typeComponent;
childComponents = new ArrayList<>();
}
#Override
public void add(ComponentText componentText) {
childComponents.add(componentText);
}
#Override
public void remove(ComponentText componentText) {
childComponents.remove(componentText);
}
#Override
public TypeComponent getComponentType() {
return this.type;
}
#Override
public ComponentText getChild(int index) {
return childComponents.get(index);
}
#Override
public int getCountChildElements() {
return childComponents.size();
}
#Override
public int getCountAllElements() {
return childComponents.stream()
.mapToInt(ComponentText::getCountAllElements)
.sum();
}
#Override
public String toString() {
return null;
}
}
I created classes that perform the same action - parsing, parsing text into paragraphs, into sentences, into tokens, into symbols.
public class IntoParagraphParser implements ActionParser {
// call IntoSentenceParser
}
public class IntoSentenceParser implements ActionParser {
// call IntoLexemeParser
}
public class IntoLexemeParser implements ActionParser {
// call IntoSymbolParser
}
public class IntoSymbolParser implements ActionParser {
}
All data is stored in List <ComponentText> childComponents in class-Composite - CompositeText.
How to properly create a method so that it prints all the data that is inside the composite?
I think this will be the method toString() in CompositeText.
Class IntoParagraphParser look:
public class IntoParagraphParser implements ActionParser {
private static final String PARAGRAPH_SPLIT_REGEX = "(?m)(?=^\\s{4})";
private static final IntoParagraphParser paragraphParser = new IntoParagraphParser();
private static final IntoSentenceParser sentenceParser = IntoSentenceParser.getInstance();
private IntoParagraphParser() {
}
public static IntoParagraphParser getInstance() {
return paragraphParser;
}
public ComponentText parse(String text) throws TextException {
ComponentText oneParagraph;
ComponentText componentParagraph = new CompositeText(text, TypeComponent.PARAGRAPH);
String[] arrayParagraph = text.split(PARAGRAPH_SPLIT_REGEX);
for(String element: arrayParagraph) {
oneParagraph = new CompositeText(element, TypeComponent.PARAGRAPH);
oneParagraph.add(sentenceParser.parse(element));
componentParagraph.add(oneParagraph);
}
return componentParagraph;
}
}
Need #Override the method toString() in CompositeText like this:
#Override
public String toString() {
StringBuilder builder = new StringBuilder();
for (ComponentText component : childComponents) {
builder.append(component.toString());
}
return builder.toString();
}
But how to write this code correctly with Stream API?
#Override
public String toString() {
StringBuilder builder = new StringBuilder();
childComponents.stream().map(...????
return builder.toString();
}

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

Realm and Expected BEGIN_OBJECT but was NUMBER at path $[0].location.coordinates[0]

I'm trying to store a coordnates (array of double) using Realm-java,but I'm not able to do it.
Here is an example of json that I'm trying to parse:
{"_id":"597cd98b3af0b6315576d717",
"comarca":"string",
"font":null,
"imatge":"string",
"location":{
"coordinates":[41.64642,1.1393],
"type":"Point"
},
"marca":"string",
"municipi":"string",
"publisher":"string",
"recursurl":"string",
"tematica":"string",
"titol":"string"
}
My global object code is like that
public class Images extends RealmObject implements Serializable {
#PrimaryKey
private String _id;
private String recursurl;
private String titol;
private String municipi;
private String comarca;
private String marca;
private String imatge;
#Nullable
private Location location;
private String tematica;
private String font;
private String parentRoute;
public Location getLocation() {return location;}
public void setLocation(Location location) {this.location = location;}
public String getParentRoute() {
return parentRoute;
}
public void setParentRoute(String parentRoute) {
this.parentRoute = parentRoute;
}
public String get_id() {
return _id;
}
public void set_id(String _id) {
this._id = _id;
}
public String getFont() {
return font;
}
public void setFont(String font) {
this.font = font;
}
public String getRecursurl() {
return recursurl;
}
public void setRecursurl(String recursurl) {
this.recursurl = recursurl;
}
public String getTitol() {
return titol;
}
public void setTitol(String titol) {
this.titol = titol;
}
public String getMunicipi() {
return municipi;
}
public void setMunicipi(String municipi) {
this.municipi = municipi;
}
public String getComarca() {
return comarca;
}
public void setComarca(String comarca) {
this.comarca = comarca;
}
public String getMarca() {
return marca;
}
public void setMarca(String marca) {
this.marca = marca;
}
public String getImatge() {
return imatge;
}
public void setImatge(String imatge) {
this.imatge = imatge;
}
public String getTematica() {
return tematica;
}
public void setTematica(String tematica) {
this.tematica = tematica;
}
And Location is a composite of type and a realmlist
Location.java
public class Location extends RealmObject implements Serializable {
private String type;
private RealmList<RealmDoubleObject> coordinates;
public Location() {
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public RealmList<RealmDoubleObject> getCoordinates() {
return coordinates;
}
public void setCoordinates(RealmList<RealmDoubleObject> coordinates) {
this.coordinates = coordinates;
}
}
RealmDoubleObject.java
public class RealmDoubleObject extends RealmObject implements Serializable{
private Double value;
public RealmDoubleObject() {
}
public Double getDoublevalue() {
return value;
}
public void setDoublevalue(Double value) {
this.value = value;
}
}
The error is com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was NUMBER at path $[0].location.coordinates[0] but I'm not able to figure out why this number is not "fitting" by RealmDoubleObject.
For those that not familiar with realm RealmList doesn't work and you have to build your own realm object.
Thank you. I hope to find some Realm experts here!
SOLVED:
using Gson deserializer it can be done
First we have to initialize the gson object like this
Gson gson = new GsonBuilder()
.setExclusionStrategies(new ExclusionStrategy() {
#Override
public boolean shouldSkipField(FieldAttributes f) {
return f.getDeclaringClass().equals(RealmObject.class);
}
#Override
public boolean shouldSkipClass(Class<?> clazz) {
return false;
}
})
.registerTypeAdapter(new TypeToken<RealmList<RealmDoubleObject>>() {}.getType(), new TypeAdapter<RealmList<RealmDoubleObject>>() {
#Override
public void write(JsonWriter out, RealmList<RealmDoubleObject> value) throws IOException {
// Ignore
}
#Override
public RealmList<RealmDoubleObject> read(JsonReader in) throws IOException {
RealmList<RealmDoubleObject> list = new RealmList<RealmDoubleObject>();
in.beginArray();
while (in.hasNext()) {
Double valor = in.nextDouble();
list.add(new RealmDoubleObject(valor));
}
in.endArray();
return list;
}
})
.create();
And then we have to put some other constructor method
public RealmDoubleObject(double v) {
this.value = v;
}
and this is all.
Thanks for the help #EpicPandaForce

Mybatis There is no getter for property

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.

Android Parcelable JsonArray in Side JsonObject

When i am trying Parce this json data with GSON. I am unable to get JsonArray in side of JsonObject. Below is my code, every suggestion will get appriciated.
JSON DATA FROM SERVER :
{
"GetJobDetails": {
"MaxAmount": 0,
"CreatorId": 1,
"JobImages": [
{
"ImagePath": "http://192.168.1.108:8088/Uploads/6e660c0c-4a2b- 42dc-ad97-82cc3efe87a0.jpg",
"JobImageId": 1
},
{
"ImagePath": "http://192.168.1.108:8088/Uploads/ccf1087d-9f7e-4c21-bc61-8aa3fd924e05.jpg",
"JobImageId": 2
},
{
"ImagePath": "http://192.168.1.108:8088/Uploads/4333e8b6-0079-457f-a225-fd7900ea81b1.jpg",
"JobImageId": 3
}
],
}
}
In ACTIVITY :
Gson gson = new Gson();
String response = new String(mresponce);
JobDetails jobDetails= gson.fromJson(response, JobDetails .class);
Log.e("JobDetails ",""+jobDetails.getJobImagesList());
this log prints allways null even when i have images list there in my data.
MODEL CLASS :
public class JobDetails implements Parcelable {
private int MaxAmount;
private int CreatorId;
private List<JobImage> JobImages;
public JobDetails() {
}
public JobDetails(Parcel parcel) {
this.MaxAmount = parcel.readInt();
this.CreatorId= parcel.readInt();
this.JobImages = new ArrayList<JobImage>();
parcel.readTypedList(JobImages, JobImage.CREATOR);
}
// Parcelable
#Override
public int describeContents() {
return 0;
}
#Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(this.MaxAmount);
dest.writeInt(this.CreatorId);
dest.writeList(this.JobImages);
// TODO: Not Parceling AddressList
}
public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
public JobDetails createFromParcel(Parcel in) {
return new JobDetails(in);
}
public JobDetails[] newArray(int size) {
return new JobDetails[size];
}
};
public List<JobImage> getJobImagesList() {
return JobImages;
}
public void setJobImagesList(List<JobImage> jobImages) {
JobImages = jobImages;
}
public int getMaxAmount() {
return MaxAmount;
}
public void setMaxAmount(int maxAmount) {
MaxAmount= maxAmount;
}
}
ANOTHER MODEL CLASS FOR JOBIMAGE:
public class JobImage implements Parcelable {
private String ImagePath;
private int JobImageId;
JobImage(){
}
public JobImage(Parcel in) {
this.ImagePath = in.readString();
this.JobImageId = in.readInt();
}
// Parcelable
#Override
public int describeContents() {
return 0;
}
#Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(this.ImagePath);
dest.writeInt(this.JobImageId);
// TODO: Not Parceling AddressList
}
public static final Creator CREATOR = new Creator() {
public JobImage createFromParcel(Parcel in) {
return new JobImage(in);
}
public JobImage[] newArray(int size) {
return new JobImage[size];
}
};
public String getImagePath() {
return ImagePath;
}
public void setImagePath(String imagePath) {
ImagePath = imagePath;
}
public int getJobImageId() {
return JobImageId;
}
public void setJobImageId(int jobImageId) {
JobImageId = jobImageId;
}
}
Please help me to find what i am doing wrong in this :
Your top-level JSON object is not a JobDetails object, it is an object that has JobDetails member name GetJobDetails. You need to handle this level of your JSON. You can do it with a custom TypeAdapter, or perhaps easier, just make a container object and deserialize it.
class JobDetailContainer {
private JobDetails GetJobDetails;
public JobDetails getJobDetails() {
return GetJobDetails;
}
}
then use --
Gson gson = new Gson();
String response = new String(mresponce);
GetJobDetails getJobDetails= gson.fromJson(response, GetJobDetails.class);
Log.e("JobDetails ",""+getJobDetails.getJobDetails().getJobImagesList());
Agreed with #iagreen ...I should handel top level json object too..this is what i have done after doing some R&D
public class GetJobDetails {
public GetJobDetailsResult getGetJobDetailsResult() {
return GetJobDetailsResult;
}
public void setGetJobDetailsResult(GetJobDetailsResult GetJobDetailsResult) {
this.GetJobDetailsResult = GetJobDetailsResult;
}
}
For Inner Json :
public class GetJobDetailsResult {
private Integer MaxAmount;
private Integer CreatorTotJobPosted;
private List<JobImage> JobImages = new ArrayList<JobImage>();
public Integer getMaxAmount() {
return MaxAmount;
}
public void setMaxAmount(Integer MaxAmount) {
this.MaxAmount = MaxAmount;
}
public Integer getCreatorTotJobPosted() {
return CreatorTotJobPosted;
}
public void setCreatorTotJobPosted(Integer CreatorTotJobPosted) {
this.CreatorTotJobPosted = CreatorTotJobPosted;
}
public List<JobImage> getJobImages() {
return JobImages;
}
public void setJobImages(List<JobImage> JobImages) {
this.JobImages = JobImages;
}
}
Finally For To Hold JobImages
public class JobImage {
private String ImagePath;
private Integer JobImageId;
public String getImagePath() {
return ImagePath;
}
public void setImagePath(String ImagePath) {
this.ImagePath = ImagePath;
}
public Integer getJobImageId() {
return JobImageId;
}
public void setJobImageId(Integer JobImageId) {
this.JobImageId = JobImageId;
}
}
Final Step :
Gson gson = new Gson();
String response = new String(jsonObjectresponce.toString());
GetJobDetails getJobDetails = gson.fromJson(response, GetJobDetails.class);
GetJobDetailsResult result = getJobDetails.getGetJobDetailsResult();
// now result object contains my json data.

Categories