I have created Spring MVC 4 with MyBatis. I am very sure I am all set up correctly. For Some reason I am getting this error. Any help is appreciated
Apr 30, 2015 7:22:56 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [myBatisServlet] in context with path [/APMS] threw exception [Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'one' not found. Available parameters are [0, 1, 2, param5, 3, 4, param3, param4, param1, param2]] with root cause
org.apache.ibatis.binding.BindingException: Parameter 'one' not found. Available parameters are [0, 1, 2, param5, 3, 4, param3, param4, param1, param2]
at org.apache.ibatis.binding.MapperMethod$ParamMap.get(MapperMethod.java:165)
at org.apache.ibatis.reflection.wrapper.MapWrapper.get(MapWrapper.java:44)
at org.apache.ibatis.reflection.MetaObject.getValue(MetaObject.java:116)
at org.apache.ibatis.executor.BaseExecutor.createCacheKey(BaseExecutor.java:186)
at org.apache.ibatis.executor.CachingExecutor.createCacheKey(CachingExecutor.java:129)
at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:76)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:108)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:102)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:358)
at com.sun.proxy.$Proxy17.selectList(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:198)
at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:119)
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:63)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:52)
at com.sun.proxy.$Proxy30.getResult(Unknown Source)
at com.gm.app.apms.service.WbbCodeService.getTableResult(WbbCodeService.java:24)
at com.gm.app.apms.controller.WbbOrderStatusController.getAllOrdersResults(WbbOrderStatusController.java:46)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:776)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:705)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:868)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:668)
at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:223)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1517)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1474)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
Controller class
package com.gm.app.apms.controller;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView;
import com.gm.app.apms.model.WbbOrderStatusForm;
import com.gm.app.apms.model.WbbOrderStatusResult;
import com.gm.app.apms.service.IWbbCodeService;
#Controller
#SessionAttributes("wbborderstatusform")
public class WbbOrderStatusController {
#Autowired
private IWbbCodeService iWbbCodeService;
#RequestMapping(value="/viewallorders", method=RequestMethod.POST)
public ModelAndView getAllOrdersResults (#ModelAttribute("wbbOrderStatusForm") WbbOrderStatusForm wbbOrderStatusForm) throws Exception
{
System.out.println(" I AM HERE");
String DateFrom = wbbOrderStatusForm.getDateFrom();
String DateTo = wbbOrderStatusForm.getDateTo();
String orderType = wbbOrderStatusForm.getOrderType();
String distCode = wbbOrderStatusForm.getDistCode();
String packingCode = wbbOrderStatusForm.getPackingCode();
System.out.println("DateFrom "+DateFrom);
System.out.println("DateTo "+DateTo);
System.out.println("orderType "+orderType);
System.out.println("distCode "+distCode);
System.out.println("packingCode "+packingCode);
ModelAndView showresult = new ModelAndView("showresults");
List <WbbOrderStatusResult> tablelist = new ArrayList<WbbOrderStatusResult>();
if (!DateFrom.isEmpty() && !DateTo.isEmpty() && !orderType.isEmpty() && !distCode.isEmpty() && !packingCode.isEmpty()){
tablelist = iWbbCodeService.getTableResult(DateFrom, DateTo, orderType, distCode, packingCode);
showresult.addObject("tablelist", tablelist);
}
return showresult;
}
#RequestMapping(value="/viewallorders", method=RequestMethod.GET)
public String signup(Model model) {
System.out.println("FIRST PART");
WbbOrderStatusForm wbbOrderStatusForm = new WbbOrderStatusForm();
model.addAttribute("wbbOrderStatusForm", wbbOrderStatusForm);
return "viewallorders";
}
}
Mapper class
package com.gm.app.apms.mappers;
import java.util.List;
import org.apache.ibatis.annotations.Select;
import com.gm.app.apms.model.WbbOrderStatusResult;
public interface WbbCodeMapper
{
#Select("SELECT p1.P3ORDRM0.BUYER_ORDR_NO as distOrderNo, p1.P3ORDRM0.ORDR_YEAR||p1.P3ORDRM0.ORDR_CUST_CD||p1.P3ORDRM0.ORDR_TYPE||p1.P3ORDRM0.ORDR_SEQ as gmdatOrderNo, "
+ "p1.P3ORDRM0.CNFM_DT as cnfmDt, p1.P3ORDRM0.PORT_DEST_CD as packingCode, p1.P9ORDRV1.ORDR_ITEM as orderedItem, "
+ "p1.P9ORDRV1.ORDR_QTY as orderedPcs, Round(p1.P9ORDRV1.ORDR_AMT*decode(p1.P3ORDRM0.MULTI_EXCH_RATE,1000,1,p1.P3ORDRM0.MULTI_EXCH_RATE),2) as orderedAmt, "
+ "p1.P9ORDRV1.DSTR_ITEM as allocationItem, p1.P9ORDRV1.DSTR_QTY as allocationPcs, Round(p1.P9ORDRV1.DSTR_AMT*decode(p1.P3ORDRM0.MULTI_EXCH_RATE,1000,1,p1.P3ORDRM0.MULTI_EXCH_RATE),2) as allocationAmt, "
+ "DECODE(p1.P9ORDRV1.ORDR_QTY,0,0,Round((p1.P9ORDRV1.DSTR_QTY / p1.P9ORDRV1.ORDR_QTY )*100,2)) as allocationRate, p1.P9ORDRV1.PICK_ITEM as pickItem, "
+ "p1.P9ORDRV1.PICK_QTY as pickPcs, Round(p1.P9ORDRV1.PICK_AMT*decode(p1.P3ORDRM0.MULTI_EXCH_RATE,1000,1,p1.P3ORDRM0.MULTI_EXCH_RATE),2) as pickAmt, "
+ "DECODE(p1.P9ORDRV1.ORDR_QTY,0,0,Round((p1.P9ORDRV1.PICK_QTY / p1.P9ORDRV1.ORDR_QTY )*100,2)) as pickRate, p1.P9ORDRV1.PACK_ITEM as packItem, "
+ "p1.P9ORDRV1.PACK_QTY as packPcs, Round(p1.P9ORDRV1.PACK_AMT*decode(p1.P3ORDRM0.MULTI_EXCH_RATE,1000,1,p1.P3ORDRM0.MULTI_EXCH_RATE),2) as packAmt, "
+ "DECODE(p1.P9ORDRV1.ORDR_QTY,0,0,Round((p1.P9ORDRV1.PICK_QTY / p1.P9ORDRV1.ORDR_QTY )*100,2)) as packRate, p1.P9ORDRV1.CASE_OUT_ITEM as cargoReadyItem, "
+ "p1.P9ORDRV1.CASE_OUT_QTY as cargoReadyPcs, Round(p1.P9ORDRV1.CASE_OUT_AMT*decode(p1.P3ORDRM0.MULTI_EXCH_RATE,1000,1,p1.P3ORDRM0.MULTI_EXCH_RATE),2) as cargoReadyAmt, "
+ "DECODE(p1.P9ORDRV1.ORDR_QTY,0,0,Round((p1.P9ORDRV1.CASE_OUT_QTY / p1.P9ORDRV1.ORDR_QTY )*100,2)) as cargoReadyRate, p1.P9ORDRV1.SHIP_PEND_ITEM as vanningItem, "
+ "p1.P9ORDRV1.SHIP_PEND_QTY as vanningPcs, Round(p1.P9ORDRV1.SHIP_PEND_AMT*decode(p1.P3ORDRM0.MULTI_EXCH_RATE,1000,1,p1.P3ORDRM0.MULTI_EXCH_RATE),2) as vanningAmt, "
+ "DECODE(p1.P9ORDRV1.ORDR_QTY,0,0,Round((p1.P9ORDRV1.SHIP_PEND_QTY / p1.P9ORDRV1.ORDR_QTY )*100,2)) as vanningRate, p1.P9ORDRV1.SHIP_ITEM as shippedItem, "
+ "p1.P9ORDRV1.SHIP_QTY as shippedPcs, Round(p1.P9ORDRV1.SHIP_AMT*decode(p1.P3ORDRM0.MULTI_EXCH_RATE,1000,1,p1.P3ORDRM0.MULTI_EXCH_RATE),2) as shippedAmt, "
+ "DECODE(p1.P9ORDRV1.ORDR_QTY,0,0,Round((p1.P9ORDRV1.SHIP_QTY / p1.P9ORDRV1.ORDR_QTY )*100,2)) as shippedRate, p1.P9ORDRV1.BACK_ORDR_ITEM as balanceItem, "
+ "p1.P9ORDRV1.BACK_ORDR_QTY as balancePcs, Round(p1.P9ORDRV1.BACK_ORDR_AMT*decode(p1.P3ORDRM0.MULTI_EXCH_RATE,1000,1,p1.P3ORDRM0.MULTI_EXCH_RATE),2) as balanceAmt, "
+ "DECODE(p1.P9ORDRV1.ORDR_QTY,0,0,Round((p1.P9ORDRV1.BACK_ORDR_QTY / p1.P9ORDRV1.ORDR_QTY )*100,2)) as balanceRate, decode(p1.P3ORDRM0.CURR,'KRW','USD',p1.P3ORDRM0.CURR) as cur FROM p1.P3ORDRM0, "
+ "p1.P9ORDRV1 WHERE p1.p3ordrm0.ordr_year = p1.P9ORDRV1.ordr_year(+) AND p1.p3ordrm0.ordr_cust_cd = p1.P9ORDRV1.ordr_cust_cd(+) AND p1.p3ordrm0.ordr_type = p1.P9ORDRV1.ordr_type(+) "
+ "AND p1.p3ordrm0.ordr_seq = p1.P9ORDRV1.ordr_seq (+) "
+ "AND p1.P3ORDRM0.CNFM_DT >= #{one} "
+ "AND p1.P3ORDRM0.CNFM_DT <= #{two} "
+ "AND p1.P3ORDRM0.ORDR_TYPE like '%#{three}%' "
+ "AND p1.P3ORDRM0.ORDR_CUST_CD = '#{four}' "
+ "AND p1.P3ORDRM0.ORDRM0_STAT in ('400','500','700') "
+ "AND p1.P3ORDRM0.PORT_DEST_CD LIKE '%#{five}%';")
public List <WbbOrderStatusResult> getResult(String one, String two, String three, String four, String five);
}
Model of form
package com.gm.app.apms.model;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
public class WbbOrderStatusForm
{
private String dateFrom;
private String dateTo;
private String orderType;
private String packingCode;
private String distCode;
private String partNo;
private String radioCond;
private String distOrderNo;
private String suppPartNo;
private String suppSrc;
private String caseStatus;
private String caseYear;
private String caseCustCd;
private String caseSm;
private String caseSeq;
private String chk;
private String mod;
private String gmPartNo;
private String suzukiPartNo;
private Collection orderTypeCollection;
private Collection packingCodeCollection;
public WbbOrderStatusForm() {}
public Collection getOrderTypeCollection()
{
ArrayList list = new ArrayList();
//list.add(new LabelValueBean("ALL", ""));
HashMap searchMap = new HashMap();
searchMap.put("cdNo", "E0001");
List result = null;
//List result = (List) WbbCodeService.getInstance().getCodeList(searchMap);
String str = "";
for (int i = 0; i < result.size(); i++)
{
HashMap resultMap = (HashMap) result.get(i);
str = (String) resultMap.get("cdItem");
//list.add(new LabelValueBean(str, (String) resultMap.get("cdValue")));
}
return list;
}
public void setOrderTypeCollection(Collection collection)
{
orderTypeCollection = collection;
}
public Collection getPackingCodeCollection()
{
ArrayList list = new ArrayList();
//list.add(new LabelValueBean("ALL", ""));
HashMap searchMap = new HashMap();
searchMap.put("distCode", distCode);
List result = null;
//List result = (List) WbbCodeService.getInstance().getPackingCodeList(searchMap);
String str = "";
for (int i = 0; i < result.size(); i++)
{
HashMap resultMap = (HashMap) result.get(i);
str = (String) resultMap.get("cdValue");
//list.add(new LabelValueBean(str, (String) resultMap.get("cdValue")));
}
// ������ ���� ��� 1�� ����
if (list.size() == 1)
{
//list.add(new LabelValueBean("1", "1"));
}
return list;
}
public void setPackingCodeCollection(Collection collection)
{
packingCodeCollection = collection;
}
public String getDateFrom()
{
return dateFrom;
}
public void setDateFrom(String dateFrom)
{
this.dateFrom = dateFrom;
}
public String getDateTo()
{
return dateTo;
}
public void setDateTo(String dateTo)
{
this.dateTo = dateTo;
}
public String getOrderType()
{
return orderType;
}
public void setOrderType(String orderType)
{
this.orderType = orderType;
}
public String getPackingCode()
{
return packingCode;
}
public void setPackingCode(String packingCode)
{
this.packingCode = packingCode;
}
public String getDistCode()
{
return distCode;
}
public void setDistCode(String distCode)
{
this.distCode = distCode;
}
public String getPartNo()
{
return partNo;
}
public void setPartNo(String partNo)
{
this.partNo = partNo;
}
public String getRadioCond()
{
return radioCond;
}
public void setRadioCond(String radioCond)
{
this.radioCond = radioCond;
}
public String getDistOrderNo()
{
return distOrderNo;
}
public void setDistOrderNo(String distOrderNo)
{
this.distOrderNo = distOrderNo;
}
public String getSuppPartNo()
{
return suppPartNo;
}
public void setSuppPartNo(String suppPartNo)
{
this.suppPartNo = suppPartNo;
}
public String getSuppSrc()
{
return suppSrc;
}
public void setSuppSrc(String suppSrc)
{
this.suppSrc = suppSrc;
}
public String getCaseStatus()
{
return caseStatus;
}
public void setCaseStatus(String caseStatus)
{
this.caseStatus = caseStatus;
}
public String getCaseYear()
{
return caseYear;
}
public void setCaseYear(String caseYear)
{
this.caseYear = caseYear;
}
public String getCaseCustCd()
{
return caseCustCd;
}
public void setCaseCustCd(String caseCustCd)
{
this.caseCustCd = caseCustCd;
}
public String getCaseSm()
{
return caseSm;
}
public void setCaseSm(String caseSm)
{
this.caseSm = caseSm;
}
public String getCaseSeq()
{
return caseSeq;
}
public void setCaseSeq(String caseSeq)
{
this.caseSeq = caseSeq;
}
public String getChk()
{
return chk;
}
public void setChk(String chk)
{
this.chk = chk;
}
public String getMod()
{
return mod;
}
public void setMod(String mod)
{
this.mod = mod;
}
public String getGmPartNo()
{
return gmPartNo;
}
public void setGmPartNo(String gmPartNo)
{
this.gmPartNo = gmPartNo;
}
public String getSuzukiPartNo()
{
return suzukiPartNo;
}
public void setSuzukiPartNo(String suzukiPartNo)
{
this.suzukiPartNo = suzukiPartNo;
}
}
Model of Result
package com.gm.app.apms.model;
public class WbbOrderStatusResult {
private String distOrderNo;
private String gmdatOrderNo;
private String cnfmDt;
private String packingCode;
private String orderedItem;
private String orderedPcs;
private String orderedAmt;
private String allocationItem;
private String allocationPcs;
private String allocationAmt;
private String allocationRate;
private String pickItem;
private String pickPcs;
private String pickAmt;
private String pickRate;
private String packItem;
private String packPcs;
private String packAmt;
private String packRate;
private String cargoReadyItem;
private String cargoReadyPcs;
private String cargoReadyAmt;
private String cargoReadyRate;
private String vanningItem;
private String vanningPcs;
private String vanningAmt;
private String vanningRate;
private String shippedItem;
private String shippedPcs;
private String shippedAmt;
private String shippedRate;
private String balanceItem;
private String balancePcs;
private String balanceAmt;
private String balanceRate;
private String cur;
public String getDistOrderNo() {
return distOrderNo;
}
public void setDistOrderNo(String distOrderNo) {
this.distOrderNo = distOrderNo;
}
public String getGmdatOrderNo() {
return gmdatOrderNo;
}
public void setGmdatOrderNo(String gmdatOrderNo) {
this.gmdatOrderNo = gmdatOrderNo;
}
public String getCnfmDt() {
return cnfmDt;
}
public void setCnfmDt(String cnfmDt) {
this.cnfmDt = cnfmDt;
}
public String getPackingCode() {
return packingCode;
}
public void setPackingCode(String packingCode) {
this.packingCode = packingCode;
}
public String getOrderedItem() {
return orderedItem;
}
public void setOrderedItem(String orderedItem) {
this.orderedItem = orderedItem;
}
public String getOrderedPcs() {
return orderedPcs;
}
public void setOrderedPcs(String orderedPcs) {
this.orderedPcs = orderedPcs;
}
public String getOrderedAmt() {
return orderedAmt;
}
public void setOrderedAmt(String orderedAmt) {
this.orderedAmt = orderedAmt;
}
public String getAllocationItem() {
return allocationItem;
}
public void setAllocationItem(String allocationItem) {
this.allocationItem = allocationItem;
}
public String getAllocationPcs() {
return allocationPcs;
}
public void setAllocationPcs(String allocationPcs) {
this.allocationPcs = allocationPcs;
}
public String getAllocationAmt() {
return allocationAmt;
}
public void setAllocationAmt(String allocationAmt) {
this.allocationAmt = allocationAmt;
}
public String getAllocationRate() {
return allocationRate;
}
public void setAllocationRate(String allocationRate) {
this.allocationRate = allocationRate;
}
public String getPickItem() {
return pickItem;
}
public void setPickItem(String pickItem) {
this.pickItem = pickItem;
}
public String getPickPcs() {
return pickPcs;
}
public void setPickPcs(String pickPcs) {
this.pickPcs = pickPcs;
}
public String getPickAmt() {
return pickAmt;
}
public void setPickAmt(String pickAmt) {
this.pickAmt = pickAmt;
}
public String getPickRate() {
return pickRate;
}
public void setPickRate(String pickRate) {
this.pickRate = pickRate;
}
public String getPackItem() {
return packItem;
}
public void setPackItem(String packItem) {
this.packItem = packItem;
}
public String getPackPcs() {
return packPcs;
}
public void setPackPcs(String packPcs) {
this.packPcs = packPcs;
}
public String getPackAmt() {
return packAmt;
}
public void setPackAmt(String packAmt) {
this.packAmt = packAmt;
}
public String getPackRate() {
return packRate;
}
public void setPackRate(String packRate) {
this.packRate = packRate;
}
public String getCargoReadyItem() {
return cargoReadyItem;
}
public void setCargoReadyItem(String cargoReadyItem) {
this.cargoReadyItem = cargoReadyItem;
}
public String getCargoReadyPcs() {
return cargoReadyPcs;
}
public void setCargoReadyPcs(String cargoReadyPcs) {
this.cargoReadyPcs = cargoReadyPcs;
}
public String getCargoReadyAmt() {
return cargoReadyAmt;
}
public void setCargoReadyAmt(String cargoReadyAmt) {
this.cargoReadyAmt = cargoReadyAmt;
}
public String getCargoReadyRate() {
return cargoReadyRate;
}
public void setCargoReadyRate(String cargoReadyRate) {
this.cargoReadyRate = cargoReadyRate;
}
public String getVanningItem() {
return vanningItem;
}
public void setVanningItem(String vanningItem) {
this.vanningItem = vanningItem;
}
public String getVanningPcs() {
return vanningPcs;
}
public void setVanningPcs(String vanningPcs) {
this.vanningPcs = vanningPcs;
}
public String getVanningAmt() {
return vanningAmt;
}
public void setVanningAmt(String vanningAmt) {
this.vanningAmt = vanningAmt;
}
public String getVanningRate() {
return vanningRate;
}
public void setVanningRate(String vanningRate) {
this.vanningRate = vanningRate;
}
public String getShippedItem() {
return shippedItem;
}
public void setShippedItem(String shippedItem) {
this.shippedItem = shippedItem;
}
public String getShippedPcs() {
return shippedPcs;
}
public void setShippedPcs(String shippedPcs) {
this.shippedPcs = shippedPcs;
}
public String getShippedAmt() {
return shippedAmt;
}
public void setShippedAmt(String shippedAmt) {
this.shippedAmt = shippedAmt;
}
public String getShippedRate() {
return shippedRate;
}
public void setShippedRate(String shippedRate) {
this.shippedRate = shippedRate;
}
public String getBalanceItem() {
return balanceItem;
}
public void setBalanceItem(String balanceItem) {
this.balanceItem = balanceItem;
}
public String getBalancePcs() {
return balancePcs;
}
public void setBalancePcs(String balancePcs) {
this.balancePcs = balancePcs;
}
public String getBalanceAmt() {
return balanceAmt;
}
public void setBalanceAmt(String balanceAmt) {
this.balanceAmt = balanceAmt;
}
public String getBalanceRate() {
return balanceRate;
}
public void setBalanceRate(String balanceRate) {
this.balanceRate = balanceRate;
}
public String getCur() {
return cur;
}
public void setCur(String cur) {
this.cur = cur;
}
}
Service Interface
package com.gm.app.apms.service;
import java.util.List;
import com.gm.app.apms.model.WbbOrderStatusResult;
public interface IWbbCodeService
{
public List<WbbOrderStatusResult> getTableResult(String one, String two, String three, String four, String five);
}
Service Implementation
package com.gm.app.apms.service;
import java.util.HashMap;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.gm.app.apms.mappers.StudentMapper;
import com.gm.app.apms.mappers.WbbCodeMapper;
import com.gm.app.apms.model.WbbOrderStatusResult;
#Service("IWbbCodeService")
public class WbbCodeService implements IWbbCodeService
{
#Autowired
private WbbCodeMapper wbbCodeMapper;
#Override
public List<WbbOrderStatusResult> getTableResult(String one, String two,
String three, String four, String five) {
return wbbCodeMapper.getResult(one, two, three, four, five);
}
}
Solutions was to use #Param annotation
public List <WbbOrderStatusResult> getResult(#Param("one")String one, #Param("two")String two, #Param("three")String three, #Param("four")String four, #Param("five")String five);
Kothari's own answer would work, but in your xml mapping you could just do
{param1,jdbcType=xxx} #{param2,jdbcType=xxx} etc.....
Related
Hi i am creating a service of Invoice PO to get the json reponse after verification from classes of service package.
First I have created a model package and classes according to json.
InvoiceRequest is like this--
package com.InvoicePO.newmodel;
import java.util.List;
public class InvoiceRequest {
private List<Records> records;
public List<Records> getRecords() {
return records;
}
public void setRecords(List<Records> records) {
this.records = records;
}
}
Records Class--
package com.InvoicePO.newmodel;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonProperty;
public class Records {
private String Vecv_plant;
private String DBM_Plant;
private String VECV_SO;
private String DBM_PO;
private String VBELN;
private String FKDAT;
private String LRDATE;
private String PFCHARGE;
private String OCHARGE;
private String DISC;
private String TAXTYPE;
private String TAX;
private String TAXAMT;
private String INVAMT;
private String WAERK;
private String INVCNT;
private String ODN;
private List<LineItemTable> lineItemTables;
public String getVecv_plant() {
return Vecv_plant;
}
public void setVecv_plant(String vecv_plant) {
Vecv_plant = vecv_plant;
}
public String getDBM_Plant() {
return DBM_Plant;
}
public void setDBM_Plant(String dBM_Plant) {
DBM_Plant = dBM_Plant;
}
public String getVECV_SO() {
return VECV_SO;
}
public void setVECV_SO(String vECV_SO) {
VECV_SO = vECV_SO;
}
public String getDBM_PO() {
return DBM_PO;
}
public void setDBM_PO(String dBM_PO) {
DBM_PO = dBM_PO;
}
public String getVBELN() {
return VBELN;
}
public void setVBELN(String vBELN) {
VBELN = vBELN;
}
public String getFKDAT() {
return FKDAT;
}
public void setFKDAT(String fKDAT) {
FKDAT = fKDAT;
}
public String getLRDATE() {
return LRDATE;
}
public void setLRDATE(String lRDATE) {
LRDATE = lRDATE;
}
public String getPFCHARGE() {
return PFCHARGE;
}
public void setPFCHARGE(String pFCHARGE) {
PFCHARGE = pFCHARGE;
}
public String getOCHARGE() {
return OCHARGE;
}
public void setOCHARGE(String oCHARGE) {
OCHARGE = oCHARGE;
}
public String getDISC() {
return DISC;
}
public void setDISC(String dISC) {
DISC = dISC;
}
public String getTAXTYPE() {
return TAXTYPE;
LineItemTable--
package com.InvoicePO.newmodel;
public class LineItemTable {
private String VBELN1;
private String DEALER1;
private String POSEX;
private String MATNR;
private String INVQTY;
private String RATE;
private String TOTAL;
private String DISC;
private String TAXTYPE;
private String PURCH_NO;
private String PURCH_DATE;
private String SALES_NO;
private String PGIX;
public String getVBELN1() {
return VBELN1;
}
public void setVBELN1(String vBELN1) {
VBELN1 = vBELN1;
}
public String getDEALER1() {
return DEALER1;
}
public void setDEALER1(String dEALER1) {
DEALER1 = dEALER1;
}
public String getPOSEX() {
return POSEX;
}
public void setPOSEX(String pOSEX) {
POSEX = pOSEX;
}
public String getMATNR() {
return MATNR;
}
public void setMATNR(String mATNR) {
MATNR = mATNR;
}
public String getINVQTY() {
return INVQTY;
}
public void setINVQTY(String iNVQTY) {
INVQTY = iNVQTY;
}
public String getRATE() {
return RATE;
}
public void setRATE(String rATE) {
RATE = rATE;
}
public String getTOTAL() {
return TOTAL;
}
public void setTOTAL(String tOTAL) {
TOTAL = tOTAL;
}
public String getDISC() {
return DISC;
}
public void setDISC(String dISC) {
DISC = dISC;
}
public String getTAXTYPE() {
return TAXTYPE;
}
public void setTAXTYPE(String tAXTYPE) {
TAXTYPE = tAXTYPE;
}
public String getPURCH_NO() {
return PURCH_NO;
}
public void setPURCH_NO(String pURCH_NO) {
PURCH_NO = pURCH_NO;
}
public String getPURCH_DATE() {
return PURCH_DATE;
}
public void setPURCH_DATE(String pURCH_DATE) {
PURCH_DATE = pURCH_DATE;
}
public String getSALES_NO() {
return SALES_NO;
}
public void setSALES_NO(String sALES_NO) {
SALES_NO = sALES_NO;
}
public String getPGIX() {
return PGIX;
}
public void setPGIX(String pGIX) {
PGIX = pGIX;
}
}
Invoice Controller--
package com.InvoicePO.controller;
import java.io.StringWriter;
import java.io.Writer;
import java.util.ArrayList;
import java.util.List;
import javax.xml.ws.BindingProvider;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import com.InvoicePO.newmodel.InvoiceRequest;
import com.InvoicePO.service.DTRECCPOVCPLINVOICE;
import com.InvoicePO.service.DTSVCPLINVOICETOECCPO;
import com.InvoicePO.service.DTSVCPLINVOICETOECCPO.Records;
import com.InvoicePO.service.DTSVCPLINVOICETOECCPO.Records.LineItemTable;
import com.InvoicePO.service.SISVCPLINVOICETOECCPO;
import com.InvoicePO.service.SISVCPLINVOICETOECCPOService;
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.ObjectMapper;
#RestController
public class InvoiceController {
public static String getJsonFromObject(Object obj) {
ObjectMapper Obj = new ObjectMapper();
Obj.setVisibility(PropertyAccessor.FIELD, Visibility.ANY);
Writer strWriter = new StringWriter();
try {
Obj.writeValue(strWriter,obj);
return strWriter.toString();
} catch (Exception e) {
return "";
}
}
#RequestMapping(value = "/invoicepo", method=RequestMethod.POST)
public #ResponseBody DTRECCPOVCPLINVOICE VerficationDetails(#RequestBody InvoiceRequest data) {
System.out.println("/Data Recieved" + getJsonFromObject(data));
DTRECCPOVCPLINVOICE response = null;
DTSVCPLINVOICETOECCPO soapobj = new DTSVCPLINVOICETOECCPO();
List<Records> objc = new ArrayList<>();
for(com.InvoicePO.newmodel.Records records : data.getRecords())
{
// RECORD records = data;
Records rec = new Records();
rec.setVecvPlant(records.getVecv_plant());
rec.setDBMPlant(records.getDBM_Plant());
rec.setVECVSO(records.getVECV_SO());
rec.setDBMPO(records.getDBM_PO());
rec.setVBELN(records.getVBELN());
rec.setFKDAT(records.getFKDAT());
rec.setLRDATE(records.getLRDATE());
rec.setPFCHARGE(records.getPFCHARGE());
rec.setOCHARGE(records.getOCHARGE());
rec.setDISC(records.getDISC());
rec.setTAXTYPE(records.getTAXTYPE());
rec.setTAX(records.getTAX());
rec.setTAXAMT(records.getTAXAMT());
rec.setINVAMT(records.getINVAMT());
rec.setWAERK(records.getWAERK());
rec.setINVCNT(records.getINVCNT());
rec.setODN(records.getODN());
List<LineItemTable> line = new ArrayList<>();
for(com.InvoicePO.newmodel.LineItemTable table : records.getLineItemTables()) {
// LineItemTable table = data;
LineItemTable lin = new LineItemTable();
lin.setDEALER1(table.getDEALER1());
lin.setPOSEX(table.getPOSEX());
lin.setMATNR(table.getMATNR());
lin.setINVQTY(table.getINVQTY());
lin.setRATE(table.getRATE());
lin.setTOTAL(table.getTOTAL());
lin.setDISC(table.getDISC());
lin.setTAXTYPE(table.getTAXTYPE());
lin.setPURCHNO(table.getPURCH_NO());
lin.setPURCHDATE(table.getPURCH_DATE());
lin.setSALESNO(table.getSALES_NO());
lin.setPGIX(table.getPGIX());
line.add(lin);
}
rec.setLineItemTable(line);
rec.setLineItemTable(line);
objc.add(rec);
}
System.out.println("\nRequest for PI:" +getJsonFromObject(soapobj));
SISVCPLINVOICETOECCPOService sisservice= new SISVCPLINVOICETOECCPOService();
SISVCPLINVOICETOECCPO port = sisservice.getHTTPSPort();
// DTSVCPLINVOICETOECCPO eccpo = new DTSVCPLINVOICETOECCPO();
// eccpo.setRecords(objc);
BindingProvider provider = (BindingProvider)port;
provider.getRequestContext().put("javax.xml.ws.security.auth.username", "pisuper");
provider.getRequestContext().put("javax.xml.ws.security.auth.password", "Xidvecv#123");
response = port.siSVCPLINVOICETOECCPO(soapobj);
System.out.println("\nResponse for PI:" +getJsonFromObject(soapobj));
return response ;
}
}
The json i am hitting in Postman --
{
"Records": {
"Vecv_plant": 1110,
"DBM_Plant": "C001",
"VECV_SO": 5110000139,
"DBM_PO": "5900000069",
"VBELN": 91297393,
"FKDAT": 20221208,
"LRDATE": 0,
"PFCHARGE": 0,
"OCHARGE": 0,
"DISC": 0,
"TAXTYPE": "IGST",
"TAX": 0,
"TAXAMT": 364.04,
"INVAMT": 2386.46,
"WAERK": "INR",
"INVCNT": 0,
"ODN": "IN9220800004",
"LineItemTable": [
{
"VBELN1": 91297393,
"DEALER1": "C001",
"POSEX": 10,
"MATNR": "IM300124L",
"INVQTY": 9,
"RATE": 2022,
"TOTAL": 2386,
"DISC": "",
"TAXTYPE": "IGST",
"PURCH_NO": 3000041178,
"PURCH_DATE": 20221121,
"SALES_NO": 1050022,
"PGIX": ""
},
{
"VBELN1": 91297393,
"DEALER1": "C001",
"POSEX": 20,
"MATNR": "IM300262L",
"INVQTY": 8,
"RATE": 1030,
"TOTAL": 1386,
"DISC": "",
"TAXTYPE": "IGST",
"PURCH_NO": 3000041178,
"PURCH_DATE": 20221121,
"SALES_NO": 1050022,
"PGIX": ""
}
]
}
}
The error I am getting = Cannot invoke java.util.List.iterator() because the return value of com.InvoicePO.newmodel.InvoiceRequest.getRecords() is null
Here's my API code:
#GET
#Path("/jobs")
#Produces(MediaType.APPLICATION_JSON)
public Stream<Annuncio> getAnnuncio() {
Stream<PropertyBox> stream = datastore.query(RecAnnuncio.TARGET).stream(RecAnnuncio.REC_ANNUNCIO);
return stream.map(row -> {
return new AnnuncioImpl(row.getValueIfPresent(RecAnnuncio.ID).orElse(null),
row.getValueIfPresent(RecAnnuncio.ID_REF_PRINC).orElseGet(null),
row.getValueIfPresent(RecAnnuncio.NOME_REF_PRINC).orElseGet(null),
row.getValueIfPresent(RecAnnuncio.COGNOME_REF_PRINC).orElseGet(null),
row.getValueIfPresent(RecAnnuncio.FOTO_REF_PRINC).orElseGet(null),
row.getValueIfPresent(RecAnnuncio.ID_SEDE).orElse(null),
row.getValueIfPresent(RecAnnuncio.DESC_SEDE).orElse(null),
row.getValueIfPresent(RecAnnuncio.NOME_INDIRIZZO).orElse(null),
row.getValueIfPresent(RecAnnuncio.DESC_INDIRIZZO).orElse(null),
row.getValueIfPresent(RecAnnuncio.INDIRIZZO).orElse(null),
row.getValueIfPresent(RecAnnuncio.CASELLA_POSTALE).orElse(null),
row.getValueIfPresent(RecAnnuncio.NAP).orElse(null),
row.getValueIfPresent(RecAnnuncio.LOCALITA).orElse(null),
row.getValueIfPresent(RecAnnuncio.ID_NAZIONE).orElse(null),
row.getValueIfPresent(RecAnnuncio.DESC_NAZIONE).orElse(null),
row.getValueIfPresent(RecAnnuncio.NO_TELEFONO).orElse(null),
row.getValueIfPresent(RecAnnuncio.E_MAIL_HR).orElse(null),
row.getValueIfPresent(RecAnnuncio.PAGINA_INTERNET).orElse(null),
row.getValueIfPresent(RecAnnuncio.PAGINA_LINKEDIN).orElse(null),
row.getValueIfPresent(RecAnnuncio.ID_SEZIONE).orElse(null),
row.getValueIfPresent(RecAnnuncio.ID_AREA).orElse(null),
row.getValueIfPresent(RecAnnuncio.DESC_AREA).orElse(null),
row.getValueIfPresent(RecAnnuncio.ID_REF_SECOND).orElse(null),
row.getValueIfPresent(RecAnnuncio.NOME_REF_SECOND).orElseGet(null),
row.getValueIfPresent(RecAnnuncio.COGNOME_REF_SECOND).orElseGet(null),
row.getValueIfPresent(RecAnnuncio.FOTO_REF_SECOND).orElseGet(null),
row.getValueIfPresent(RecAnnuncio.TITOLO).orElse(null),
row.getValueIfPresent(RecAnnuncio.DESCRIZIONE).orElse(null),
row.getValueIfPresent(RecAnnuncio.HOME_OFFICE).orElse(null),
row.getValueIfPresent(RecAnnuncio.OCCUP_MIN).orElse(null),
row.getValueIfPresent(RecAnnuncio.OCCUP_MAX).orElse(null),
row.getValueIfPresent(RecAnnuncio.INIZIO).orElse(null),
row.getValueIfPresent(RecAnnuncio.FINE).orElse(null),
row.getValueIfPresent(RecAnnuncio.DATA_INIZIO_CONTRATTO).orElse(null),
row.getValueIfPresent(RecAnnuncio.DURATA_CONTRATTO).orElse(null),
row.getValueIfPresent(RecAnnuncio.UNITA_DURATA_CONTRATTO).orElse(null));
});
}
Here's my Annuncio:
#JsonDeserialize(as = AnnuncioImpl.class)
public interface Annuncio extends Serializable {
Integer getAnnuncioId();
Integer getRefPrincId();
String getNomeRefPrinc();
String getConomeRefPrinc();
byte[] getFotoRefPrinc();
Integer getSedeId();
String getDescSede();
String getNomeIndirizzo();
String getDescIndirizzo();
String getIndirizzo();
String getCasellaPostale();
String getNap();
String getLocalita();
Integer getNazioneId();
String getDescNazione();
String getNoTelefono();
String getEmailHr();
String getPaginaInternet();
String getPaginaLinkedin();
Integer getSezioneId();
Integer getAreaId();
String getDescArea();
Integer getRefSecondId();
String getNomeRefSecond();
String getConomeRefSecond();
byte[] getFotoRefSecond();
String getTitolo();
String getDescrizione();
String getHomeOffice();
BigDecimal getOccupMin();
BigDecimal getOccupMax();
LocalDate getInizio();
LocalDate getFine();
LocalDate getDataInizioContratto();
Integer getDurataContratto();
String getUnitaDurataContratto();
}
Here's my AnnuncioImpl:
public class AnnuncioImpl implements Annuncio {
private static final long serialVersionUID = 7564964076463242656L;
private Integer annuncioId;
private Integer refPrincId;
private String nomeRefPrinc;
private String conomeRefPrinc;
private byte[] fotoRefPrinc;
private Integer sedeId;
private String descSede;
private String nomeIndirizzo;
private String descIndirizzo;
private String indirizzo;
private String casellaPostale;
private String nap;
private String localita;
private Integer nazioneId;
private String descNazione;
private String noTelefono;
private String emailHr;
private String paginaInternet;
private String paginaLinkedin;
private Integer sezioneId;
private Integer areaId;
private String descArea;
private Integer refSecondId;
private String nomeRefSecond;
private String conomeRefSecond;
private byte[] fotoRefSecond;
private String titolo;
private String descrizione;
private String homeOffice;
private BigDecimal occupMin;
private BigDecimal occupMax;
private LocalDate inizio;
private LocalDate fine;
private LocalDate dataInizioContratto;
private Integer durataContratto;
private String unitaDurataContratto;
public AnnuncioImpl() {
super();
}
public AnnuncioImpl(Integer annuncioId, Integer refPrincId, String nomeRefPrinc, String conomeRefPrinc,
byte[] fotoRefPrinc, Integer sedeId, String descSede, String nomeIndirizzo, String descIndirizzo,
String indirizzo, String casellaPostale, String nap, String localita, Integer nazioneId, String descNazione,
String noTelefono, String emailHr, String paginaInternet, String paginaLinkedin, Integer sezioneId,
Integer areaId, String descArea, Integer refSecondId, String nomeRefSecond, String conomeRefSecond,
byte[] fotoRefSecond, String titolo, String descrizione, String homeOffice, BigDecimal occupMin,
BigDecimal occupMax, LocalDate inizio, LocalDate fine, LocalDate dataInizioContratto,
Integer durataContratto, String unitaDurataContratto) {
super();
this.annuncioId = annuncioId;
this.refPrincId = refPrincId;
this.nomeRefPrinc = nomeRefPrinc;
this.conomeRefPrinc = conomeRefPrinc;
this.fotoRefPrinc = fotoRefPrinc;
this.sedeId = sedeId;
this.descSede = descSede;
this.nomeIndirizzo = nomeIndirizzo;
this.descIndirizzo = descIndirizzo;
this.indirizzo = indirizzo;
this.casellaPostale = casellaPostale;
this.nap = nap;
this.localita = localita;
this.nazioneId = nazioneId;
this.descNazione = descNazione;
this.noTelefono = noTelefono;
this.emailHr = emailHr;
this.paginaInternet = paginaInternet;
this.paginaLinkedin = paginaLinkedin;
this.sezioneId = sezioneId;
this.areaId = areaId;
this.descArea = descArea;
this.refSecondId = refSecondId;
this.nomeRefSecond = nomeRefSecond;
this.conomeRefSecond = conomeRefSecond;
this.fotoRefSecond = fotoRefSecond;
this.titolo = titolo;
this.descrizione = descrizione;
this.homeOffice = homeOffice;
this.occupMin = occupMin;
this.occupMax = occupMax;
this.inizio = inizio;
this.fine = fine;
this.dataInizioContratto = dataInizioContratto;
this.durataContratto = durataContratto;
this.unitaDurataContratto = unitaDurataContratto;
}
public Integer getAnnuncioId() {
return annuncioId;
}
public Integer getRefPrincId() {
return refPrincId;
}
public String getNomeRefPrinc() {
return nomeRefPrinc;
}
public String getConomeRefPrinc() {
return conomeRefPrinc;
}
public byte[] getFotoRefPrinc() {
return fotoRefPrinc;
}
public Integer getSedeId() {
return sedeId;
}
public String getDescSede() {
return descSede;
}
public String getNomeIndirizzo() {
return nomeIndirizzo;
}
public String getDescIndirizzo() {
return descIndirizzo;
}
public String getIndirizzo() {
return indirizzo;
}
public String getCasellaPostale() {
return casellaPostale;
}
public String getNap() {
return nap;
}
public String getLocalita() {
return localita;
}
public Integer getNazioneId() {
return nazioneId;
}
public String getDescNazione() {
return descNazione;
}
public String getNoTelefono() {
return noTelefono;
}
public String getEmailHr() {
return emailHr;
}
public String getPaginaInternet() {
return paginaInternet;
}
public String getPaginaLinkedin() {
return paginaLinkedin;
}
public Integer getSezioneId() {
return sezioneId;
}
public Integer getAreaId() {
return areaId;
}
public String getDescArea() {
return descArea;
}
public Integer getRefSecondId() {
return refSecondId;
}
public String getNomeRefSecond() {
return nomeRefSecond;
}
public String getConomeRefSecond() {
return conomeRefSecond;
}
public byte[] getFotoRefSecond() {
return fotoRefSecond;
}
public String getTitolo() {
return titolo;
}
public String getDescrizione() {
return descrizione;
}
public String getHomeOffice() {
return homeOffice;
}
public BigDecimal getOccupMin() {
return occupMin;
}
public BigDecimal getOccupMax() {
return occupMax;
}
public LocalDate getInizio() {
return inizio;
}
public LocalDate getFine() {
return fine;
}
public LocalDate getDataInizioContratto() {
return dataInizioContratto;
}
public Integer getDurataContratto() {
return durataContratto;
}
public String getUnitaDurataContratto() {
return unitaDurataContratto;
}
public void setAnnuncioId(Integer annuncioId) {
this.annuncioId = annuncioId;
}
public void setRefPrincId(Integer refPrincId) {
this.refPrincId = refPrincId;
}
public void setNomeRefPrinc(String nomeRefPrinc) {
this.nomeRefPrinc = nomeRefPrinc;
}
public void setConomeRefPrinc(String conomeRefPrinc) {
this.conomeRefPrinc = conomeRefPrinc;
}
public void setFotoRefPrinc(byte[] fotoRefPrinc) {
this.fotoRefPrinc = fotoRefPrinc;
}
public void setSedeId(Integer sedeId) {
this.sedeId = sedeId;
}
public void setDescSede(String descSede) {
this.descSede = descSede;
}
public void setNomeIndirizzo(String nomeIndirizzo) {
this.nomeIndirizzo = nomeIndirizzo;
}
public void setDescIndirizzo(String descIndirizzo) {
this.descIndirizzo = descIndirizzo;
}
public void setIndirizzo(String indirizzo) {
this.indirizzo = indirizzo;
}
public void setCasellaPostale(String casellaPostale) {
this.casellaPostale = casellaPostale;
}
public void setNap(String nap) {
this.nap = nap;
}
public void setLocalita(String localita) {
this.localita = localita;
}
public void setNazioneId(Integer nazioneId) {
this.nazioneId = nazioneId;
}
public void setDescNazione(String descNazione) {
this.descNazione = descNazione;
}
public void setNoTelefono(String noTelefono) {
this.noTelefono = noTelefono;
}
public void setEmailHr(String emailHr) {
this.emailHr = emailHr;
}
public void setPaginaInternet(String paginaInternet) {
this.paginaInternet = paginaInternet;
}
public void setPaginaLinkedin(String paginaLinkedin) {
this.paginaLinkedin = paginaLinkedin;
}
public void setSezioneId(Integer sezioneId) {
this.sezioneId = sezioneId;
}
public void setAreaId(Integer areaId) {
this.areaId = areaId;
}
public void setDescArea(String descArea) {
this.descArea = descArea;
}
public void setRefSecondId(Integer refSecondId) {
this.refSecondId = refSecondId;
}
public void setNomeRefSecond(String nomeRefSecond) {
this.nomeRefSecond = nomeRefSecond;
}
public void setConomeRefSecond(String conomeRefSecond) {
this.conomeRefSecond = conomeRefSecond;
}
public void setFotoRefSecond(byte[] fotoRefSecond) {
this.fotoRefSecond = fotoRefSecond;
}
public void setTitolo(String titolo) {
this.titolo = titolo;
}
public void setDescrizione(String descrizione) {
this.descrizione = descrizione;
}
public void setHomeOffice(String homeOffice) {
this.homeOffice = homeOffice;
}
public void setOccupMin(BigDecimal occupMin) {
this.occupMin = occupMin;
}
public void setOccupMax(BigDecimal occupMax) {
this.occupMax = occupMax;
}
public void setInizio(LocalDate inizio) {
this.inizio = inizio;
}
public void setFine(LocalDate fine) {
this.fine = fine;
}
public void setDataInizioContratto(LocalDate dataInizioContratto) {
this.dataInizioContratto = dataInizioContratto;
}
public void setDurataContratto(Integer durataContratto) {
this.durataContratto = durataContratto;
}
public void setUnitaDurataContratto(String unitaDurataContratto) {
this.unitaDurataContratto = unitaDurataContratto;
}
#Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + Arrays.hashCode(fotoRefPrinc);
result = prime * result + Arrays.hashCode(fotoRefSecond);
result = prime * result + Objects.hash(annuncioId, areaId, casellaPostale, conomeRefPrinc, conomeRefSecond,
dataInizioContratto, descArea, descIndirizzo, descNazione, descSede, descrizione, durataContratto,
emailHr, fine, homeOffice, indirizzo, inizio, localita, nap, nazioneId, noTelefono, nomeIndirizzo,
nomeRefPrinc, nomeRefSecond, paginaInternet, paginaLinkedin, refPrincId, refSecondId, sedeId, sezioneId,
titolo, unitaDurataContratto);
return result;
}
#Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
AnnuncioImpl other = (AnnuncioImpl) obj;
return Objects.equals(annuncioId, other.annuncioId) && Objects.equals(areaId, other.areaId)
&& Objects.equals(casellaPostale, other.casellaPostale)
&& Objects.equals(conomeRefPrinc, other.conomeRefPrinc)
&& Objects.equals(conomeRefSecond, other.conomeRefSecond)
&& Objects.equals(dataInizioContratto, other.dataInizioContratto)
&& Objects.equals(descArea, other.descArea) && Objects.equals(descIndirizzo, other.descIndirizzo)
&& Objects.equals(descNazione, other.descNazione) && Objects.equals(descSede, other.descSede)
&& Objects.equals(descrizione, other.descrizione)
&& Objects.equals(durataContratto, other.durataContratto) && Objects.equals(emailHr, other.emailHr)
&& Objects.equals(fine, other.fine) && Arrays.equals(fotoRefPrinc, other.fotoRefPrinc)
&& Arrays.equals(fotoRefSecond, other.fotoRefSecond) && Objects.equals(homeOffice, other.homeOffice)
&& Objects.equals(indirizzo, other.indirizzo) && Objects.equals(inizio, other.inizio)
&& Objects.equals(localita, other.localita) && Objects.equals(nap, other.nap)
&& Objects.equals(nazioneId, other.nazioneId) && Objects.equals(noTelefono, other.noTelefono)
&& Objects.equals(nomeIndirizzo, other.nomeIndirizzo)
&& Objects.equals(nomeRefPrinc, other.nomeRefPrinc)
&& Objects.equals(nomeRefSecond, other.nomeRefSecond)
&& Objects.equals(paginaInternet, other.paginaInternet)
&& Objects.equals(paginaLinkedin, other.paginaLinkedin) && Objects.equals(refPrincId, other.refPrincId)
&& Objects.equals(refSecondId, other.refSecondId) && Objects.equals(sedeId, other.sedeId)
&& Objects.equals(sezioneId, other.sezioneId) && Objects.equals(titolo, other.titolo)
&& Objects.equals(unitaDurataContratto, other.unitaDurataContratto);
}
}
When I test it with Postman with the following URL:
http://localhost:8080/api/rec/jobs/
Then I got this error:
2022-09-08 14:44:21,823 INFO [com.holonplatform.datastore.jdbc] - (TRACE) SQL: [SELECT v_re_0_0.ID_ANNUNCIO AS id_a1_0, v_re_0_0.ID_REF_PRINC AS id_r2_0, v_re_0_0.NOME_REF_PRINC AS nome3_0, v_re_0_0.COGNOME_REF_PRINC AS cogn4_0, v_re_0_0.FOTO_REF_PRINC AS foto5_0, v_re_0_0.ID_SEDE AS id_s6_0, v_re_0_0.DESC_SEDE AS desc7_0, v_re_0_0.NOME_INDIRIZZO AS nome8_0, v_re_0_0.DESC_INDIRIZZO AS desc9_0, v_re_0_0.INDIRIZZO AS indi10_0, v_re_0_0.CASELLA_POSTALE AS case11_0, v_re_0_0.NAP AS nap12_0, v_re_0_0.LOCALITA AS loca13_0, v_re_0_0.ID_NAZIONE AS id_n14_0, v_re_0_0.DESC_NAZIONE AS desc15_0, v_re_0_0.NO_TELEFONO AS no_t16_0, v_re_0_0.E_MAIL_HR AS e_ma17_0, v_re_0_0.PAGINA_INTERNET AS pagi18_0, v_re_0_0.PAGINA_LINKEDIN AS pagi19_0, v_re_0_0.ID_SEZIONE AS id_s20_0, v_re_0_0.ID_AREA AS id_a21_0, v_re_0_0.DESC_AREA AS desc22_0, v_re_0_0.ID_REF_SECOND AS id_r23_0, v_re_0_0.NOME_REF_SECOND AS nome24_0, v_re_0_0.COGNOME_REF_SECOND AS cogn25_0, v_re_0_0.FOTO_REF_SECOND AS foto26_0, v_re_0_0.TITOLO AS tito27_0, v_re_0_0.DESCRIZIONE AS desc28_0, v_re_0_0.HOME_OFFICE AS home29_0, v_re_0_0.OCCUP_MIN AS occu30_0, v_re_0_0.OCCUP_MAX AS occu31_0, v_re_0_0.INIZIO AS iniz32_0, v_re_0_0.FINE AS fine33_0, v_re_0_0.DATA_INIZIO_CONTRATTO AS data34_0, v_re_0_0.DURATA_CONTRATTO AS dura35_0, v_re_0_0.UNITA_DURATA_CONTRATTO AS unit36_0 FROM V_REC_API_ANNUNCIO v_re_0_0]
2022-09-08 14:44:21,935 ERROR [org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/].[org.glassfish.jersey.server.ResourceConfig]] - Servlet.service() for servlet [org.glassfish.jersey.server.ResourceConfig] in context with path [] threw exception [com.holonplatform.core.exceptions.DataAccessException: java.sql.SQLException: Failed to deserialize value [1] for required type [class java.lang.String]: Expected expression type [class java.lang.String] but got value type [java.math.BigDecimal]] with root cause
java.sql.SQLException: Failed to deserialize value [1] for required type [class java.lang.String]: Expected expression type [class java.lang.String] but got value type [java.math.BigDecimal]
at com.holonplatform.datastore.jdbc.composer.internal.DefaultSQLValueDeserializer.deserialize(DefaultSQLValueDeserializer.java:143)
at com.holonplatform.datastore.jdbc.composer.internal.converters.PropertyBoxSQLResultConverter.convert(PropertyBoxSQLResultConverter.java:117)
at com.holonplatform.datastore.jdbc.composer.internal.converters.PropertyBoxSQLResultConverter.convert(PropertyBoxSQLResultConverter.java:39)
at com.holonplatform.datastore.jdbc.internal.operations.JdbcQuery.lambda$stream$0(JdbcQuery.java:127)
at com.holonplatform.datastore.jdbc.internal.DefaultJdbcDatastore.withConnection(DefaultJdbcDatastore.java:384)
at com.holonplatform.datastore.jdbc.internal.DefaultJdbcDatastore.withConnection(DefaultJdbcDatastore.java:468)
at com.holonplatform.datastore.jdbc.internal.operations.JdbcQuery.stream(JdbcQuery.java:119)
at com.holonplatform.core.internal.query.QueryAdapterQuery.stream(QueryAdapterQuery.java:93)
at com.holonplatform.core.query.QueryResults.stream(QueryResults.java:115)
at ch.lombardi.spai.rec.endpoint.RecEndpoint.getAnnuncio(RecEndpoint.java:63)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory.lambda$static$0(ResourceMethodInvocationHandlerFactory.java:52)
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:124)
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:167)
at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$TypeOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:219)
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:79)
at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:469)
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:391)
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:80)
at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:253)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:248)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:244)
at org.glassfish.jersey.internal.Errors.process(Errors.java:292)
at org.glassfish.jersey.internal.Errors.process(Errors.java:274)
at org.glassfish.jersey.internal.Errors.process(Errors.java:244)
at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:265)
at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:232)
at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:680)
at org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:394)
at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:346)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:366)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:319)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:205)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:373)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1590)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.base/java.lang.Thread.run(Thread.java:834)
The problem is that the value [1] is not a BigDecimal as the error said.
I use Java 11.0.15, Vaadin 14 (Maven/Spring Boot) and my IDE is Eclipse 2022-06 (4.24.0).
I have a problem with setting up each field in my class by using the setter method.
For my Object Class i have
public class HealthDetails{
private String id;
private String name;
private String age;
private String height;
private String data0;
private String data1;
private String data2;
private String data3;
private String data4;
private String data5;
private String data6;
private String data7;
private String data8;
private String data9;
private String data10;
private String data11;
private String data12;
private String data13;
private String data14;
private String data15;
private String data16;
private String data17;
private String data18;
private String data19;
private String data20;
private String data21;
private String data22;
private String data23;
private String data24;
private String data25;
private String data26;
private String data27;
private String data28;
private String data29;
private String data30;
private String data31;
private String data32;
private String data33;
private String data34;
private String data35;
private String data36;
private String data37;
private String data38;
private String data39;
private String data40;
private String data41;
private String data42;
private String data43;
private String data44;
private String data45;
private String data46;
private String data47;
private String data48;
private String data49;
private String data50;
private String data51;
private String data52;
private String data53;
private String data54;
private String data55;
private String data56;
private String data57;
private String data58;
private String data59;
private String data60;
private String data61;
private String data62;
private String data63;
private String data64;
private String data65;
private String data66;
private String data67;
private String data68;
private String data69;
private String data70;
private String data71;
private String data72;
private String data73;
private String data74;
private String data75;
private String data76;
private String data77;
private String data78;
private String data79;
private String data80;
private String data81;
private String data82;
private String data83;
private String data84;
private String data85;
private String data86;
private String data87;
private String data88;
private String data89;
private String data90;
private String data91;
private String data92;
private String data93;
private String data94;
private String data95;
private String data96;
private String data97;
private String data98;
private String data99;
private String data100;
private String data101;
private String data102;
private String data103;
private String data104;
private String data105;
private String data106;
private String data107;
private String data108;
private String data109;
private String data110;
private String data111;
private String data112;
private String data113;
private String data114;
private String data115;
private String data116;
private String data117;
private String data118;
private String data119;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAge() {
return age;
}
public void setAge(String age) {
this.age = age;
}
public String getHeight() {
return height;
}
public void setHeight(String height) {
this.height = height;
}
public String getData0() {
return data0;
}
public void setData0(String data0) {
this.data0 = data0;
}
public String getData1() {
return data1;
}
public void setData1(String data1) {
this.data1 = data1;
}
public String getData2() {
return data2;
}
public void setData2(String data2) {
this.data2 = data2;
}
public String getData3() {
return data3;
}
public void setData3(String data3) {
this.data3 = data3;
}
public String getData4() {
return data4;
}
public void setData4(String data4) {
this.data4 = data4;
}
public String getData5() {
return data5;
}
public void setData5(String data5) {
this.data5 = data5;
}
public String getData6() {
return data6;
}
public void setData6(String data6) {
this.data6 = data6;
}
public String getData7() {
return data7;
}
public void setData7(String data7) {
this.data7 = data7;
}
public String getData8() {
return data8;
}
public void setData8(String data8) {
this.data8 = data8;
}
public String getData9() {
return data9;
}
public void setData9(String data9) {
this.data9 = data9;
}
public String getData10() {
return data10;
}
public void setData10(String data10) {
this.data10 = data10;
}
public String getData11() {
return data11;
}
public void setData11(String data11) {
this.data11 = data11;
}
public String getData12() {
return data12;
}
public void setData12(String data12) {
this.data12 = data12;
}
public String getData13() {
return data13;
}
public void setData13(String data13) {
this.data13 = data13;
}
public String getData14() {
return data14;
}
public void setData14(String data14) {
this.data14 = data14;
}
public String getData15() {
return data15;
}
public void setData15(String data15) {
this.data15 = data15;
}
public String getData16() {
return data16;
}
public void setData16(String data16) {
this.data16 = data16;
}
public String getData17() {
return data17;
}
public void setData17(String data17) {
this.data17 = data17;
}
public String getData18() {
return data18;
}
public void setData18(String data18) {
this.data18 = data18;
}
public String getData19() {
return data19;
}
public void setData19(String data19) {
this.data19 = data19;
}
public String getData20() {
return data20;
}
public void setData20(String data20) {
this.data20 = data20;
}
public String getData21() {
return data21;
}
public void setData21(String data21) {
this.data21 = data21;
}
public String getData22() {
return data22;
}
public void setData22(String data22) {
this.data22 = data22;
}
public String getData23() {
return data23;
}
public void setData23(String data23) {
this.data23 = data23;
}
public String getData24() {
return data24;
}
public void setData24(String data24) {
this.data24 = data24;
}
public String getData25() {
return data25;
}
public void setData25(String data25) {
this.data25 = data25;
}
public String getData26() {
return data26;
}
public void setData26(String data26) {
this.data26 = data26;
}
public String getData27() {
return data27;
}
public void setData27(String data27) {
this.data27 = data27;
}
public String getData28() {
return data28;
}
public void setData28(String data28) {
this.data28 = data28;
}
public String getData29() {
return data29;
}
public void setData29(String data29) {
this.data29 = data29;
}
public String getData30() {
return data30;
}
public void setData30(String data30) {
this.data30 = data30;
}
public String getData31() {
return data31;
}
public void setData31(String data31) {
this.data31 = data31;
}
public String getData32() {
return data32;
}
public void setData32(String data32) {
this.data32 = data32;
}
public String getData33() {
return data33;
}
public void setData33(String data33) {
this.data33 = data33;
}
public String getData34() {
return data34;
}
public void setData34(String data34) {
this.data34 = data34;
}
public String getData35() {
return data35;
}
public void setData35(String data35) {
this.data35 = data35;
}
public String getData36() {
return data36;
}
public void setData36(String data36) {
this.data36 = data36;
}
public String getData37() {
return data37;
}
public void setData37(String data37) {
this.data37 = data37;
}
public String getData38() {
return data38;
}
public void setData38(String data38) {
this.data38 = data38;
}
public String getData39() {
return data39;
}
public void setData39(String data39) {
this.data39 = data39;
}
public String getData40() {
return data40;
}
public void setData40(String data40) {
this.data40 = data40;
}
public String getData41() {
return data41;
}
public void setData41(String data41) {
this.data41 = data41;
}
public String getData42() {
return data42;
}
public void setData42(String data42) {
this.data42 = data42;
}
public String getData43() {
return data43;
}
public void setData43(String data43) {
this.data43 = data43;
}
public String getData44() {
return data44;
}
public void setData44(String data44) {
this.data44 = data44;
}
public String getData45() {
return data45;
}
public void setData45(String data45) {
this.data45 = data45;
}
public String getData46() {
return data46;
}
public void setData46(String data46) {
this.data46 = data46;
}
public String getData47() {
return data47;
}
public void setData47(String data47) {
this.data47 = data47;
}
public String getData48() {
return data48;
}
public void setData48(String data48) {
this.data48 = data48;
}
public String getData49() {
return data49;
}
public void setData49(String data49) {
this.data49 = data49;
}
public String getData50() {
return data50;
}
public void setData50(String data50) {
this.data50 = data50;
}
public String getData51() {
return data51;
}
public void setData51(String data51) {
this.data51 = data51;
}
public String getData52() {
return data52;
}
public void setData52(String data52) {
this.data52 = data52;
}
public String getData53() {
return data53;
}
public void setData53(String data53) {
this.data53 = data53;
}
public String getData54() {
return data54;
}
public void setData54(String data54) {
this.data54 = data54;
}
public String getData55() {
return data55;
}
public void setData55(String data55) {
this.data55 = data55;
}
public String getData56() {
return data56;
}
public void setData56(String data56) {
this.data56 = data56;
}
public String getData57() {
return data57;
}
public void setData57(String data57) {
this.data57 = data57;
}
public String getData58() {
return data58;
}
public void setData58(String data58) {
this.data58 = data58;
}
public String getData59() {
return data59;
}
public void setData59(String data59) {
this.data59 = data59;
}
public String getData60() {
return data60;
}
public void setData60(String data60) {
this.data60 = data60;
}
public String getData61() {
return data61;
}
public void setData61(String data61) {
this.data61 = data61;
}
public String getData62() {
return data62;
}
public void setData62(String data62) {
this.data62 = data62;
}
public String getData63() {
return data63;
}
public void setData63(String data63) {
this.data63 = data63;
}
public String getData64() {
return data64;
}
public void setData64(String data64) {
this.data64 = data64;
}
public String getData65() {
return data65;
}
public void setData65(String data65) {
this.data65 = data65;
}
public String getData66() {
return data66;
}
public void setData66(String data66) {
this.data66 = data66;
}
public String getData67() {
return data67;
}
public void setData67(String data67) {
this.data67 = data67;
}
public String getData68() {
return data68;
}
public void setData68(String data68) {
this.data68 = data68;
}
public String getData69() {
return data69;
}
public void setData69(String data69) {
this.data69 = data69;
}
public String getData70() {
return data70;
}
public void setData70(String data70) {
this.data70 = data70;
}
public String getData71() {
return data71;
}
public void setData71(String data71) {
this.data71 = data71;
}
public String getData72() {
return data72;
}
public void setData72(String data72) {
this.data72 = data72;
}
public String getData73() {
return data73;
}
public void setData73(String data73) {
this.data73 = data73;
}
public String getData74() {
return data74;
}
public void setData74(String data74) {
this.data74 = data74;
}
public String getData75() {
return data75;
}
public void setData75(String data75) {
this.data75 = data75;
}
public String getData76() {
return data76;
}
public void setData76(String data76) {
this.data76 = data76;
}
public String getData77() {
return data77;
}
public void setData77(String data77) {
this.data77 = data77;
}
public String getData78() {
return data78;
}
public void setData78(String data78) {
this.data78 = data78;
}
public String getData79() {
return data79;
}
public void setData79(String data79) {
this.data79 = data79;
}
public String getData80() {
return data80;
}
public void setData80(String data80) {
this.data80 = data80;
}
public String getData81() {
return data81;
}
public void setData81(String data81) {
this.data81 = data81;
}
public String getData82() {
return data82;
}
public void setData82(String data82) {
this.data82 = data82;
}
public String getData83() {
return data83;
}
public void setData83(String data83) {
this.data83 = data83;
}
public String getData84() {
return data84;
}
public void setData84(String data84) {
this.data84 = data84;
}
public String getData85() {
return data85;
}
public void setData85(String data85) {
this.data85 = data85;
}
public String getData86() {
return data86;
}
public void setData86(String data86) {
this.data86 = data86;
}
public String getData87() {
return data87;
}
public void setData87(String data87) {
this.data87 = data87;
}
public String getData88() {
return data88;
}
public void setData88(String data88) {
this.data88 = data88;
}
public String getData89() {
return data89;
}
public void setData89(String data89) {
this.data89 = data89;
}
public String getData90() {
return data90;
}
public void setData90(String data90) {
this.data90 = data90;
}
public String getData91() {
return data91;
}
public void setData91(String data91) {
this.data91 = data91;
}
public String getData92() {
return data92;
}
public void setData92(String data92) {
this.data92 = data92;
}
public String getData93() {
return data93;
}
public void setData93(String data93) {
this.data93 = data93;
}
public String getData94() {
return data94;
}
public void setData94(String data94) {
this.data94 = data94;
}
public String getData95() {
return data95;
}
public void setData95(String data95) {
this.data95 = data95;
}
public String getData96() {
return data96;
}
public void setData96(String data96) {
this.data96 = data96;
}
public String getData97() {
return data97;
}
public void setData97(String data97) {
this.data97 = data97;
}
public String getData98() {
return data98;
}
public void setData98(String data98) {
this.data98 = data98;
}
public String getData99() {
return data99;
}
public void setData99(String data99) {
this.data99 = data99;
}
public String getData100() {
return data100;
}
public void setData100(String data100) {
this.data100 = data100;
}
public String getData101() {
return data101;
}
public void setData101(String data101) {
this.data101 = data101;
}
public String getData102() {
return data102;
}
public void setData102(String data102) {
this.data102 = data102;
}
public String getData103() {
return data103;
}
public void setData103(String data103) {
this.data103 = data103;
}
public String getData104() {
return data104;
}
public void setData104(String data104) {
this.data104 = data104;
}
public String getData105() {
return data105;
}
public void setData105(String data105) {
this.data105 = data105;
}
public String getData106() {
return data106;
}
public void setData106(String data106) {
this.data106 = data106;
}
public String getData107() {
return data107;
}
public void setData107(String data107) {
this.data107 = data107;
}
public String getData108() {
return data108;
}
public void setData108(String data108) {
this.data108 = data108;
}
public String getData109() {
return data109;
}
public void setData109(String data109) {
this.data109 = data109;
}
public String getData110() {
return data110;
}
public void setData110(String data110) {
this.data110 = data110;
}
public String getData111() {
return data111;
}
public void setData111(String data111) {
this.data111 = data111;
}
public String getData112() {
return data112;
}
public void setData112(String data112) {
this.data112 = data112;
}
public String getData113() {
return data113;
}
public void setData113(String data113) {
this.data113 = data113;
}
public String getData114() {
return data114;
}
public void setData114(String data114) {
this.data114 = data114;
}
public String getData115() {
return data115;
}
public void setData115(String data115) {
this.data115 = data115;
}
public String getData116() {
return data116;
}
public void setData116(String data116) {
this.data116 = data116;
}
public String getData117() {
return data117;
}
public void setData117(String data117) {
this.data117 = data117;
}
public String getData118() {
return data118;
}
public void setData118(String data118) {
this.data118 = data118;
}
public String getData119() {
return data119;
}
public void setData119(String data119) {
this.data119 = data119;
}
}
On the other hand I have a method call setListToPOJO
public class Utility{
public static void setListToPOJO(List<String> objList, HealthDetails healthDetails){
Methods[] methods = healthDetails.getClass().getDeclaredMethods();
int i = 0;
for(Method method : methods){
if(method.getName().startsWith("set"){
method.invoke(healthDetails, objList.get(i++));
}
}
//include all the try catch methods IllegalArgumentException /
//IllegalArgumentException / InvocationTargetException
}
however i caught an argumentTypeMissmatch
Any Idea how do i solve this without modifying the access Field?
this is the method use to make it work the main class
public class RunMethod{
public static void main(String[] args){
List<String> data = Arrays.asList("object0", "object1", "object2", "object3", "object4", "object5", "object6", "object7", "object8", "object9", "object10", "object11", "object12", "object13", "object14", "object15", "object16", "object17", "object18", "object19", "object20", "object21", "object22", "object23", "object24", "object25", "object26", "object27", "object28", "object29", "object30", "object31", "object32", "object33", "object34", "object35", "object36", "object37", "object38", "object39", "object40", "object41", "object42", "object43", "object44", "object45", "object46", "object47", "object48", "object49", "object50", "object51", "object52", "object53", "object54", "object55", "object56", "object57", "object58", "object59", "object60", "object61", "object62", "object63", "object64", "object65", "object66", "object67", "object68", "object69", "object70", "object71", "object72", "object73", "object74", "object75", "object76", "object77", "object78", "object79", "object80", "object81", "object82", "object83", "object84", "object85", "object86", "object87", "object88", "object89", "object90", "object91", "object92", "object93", "object94", "object95", "object96", "object97", "object98", "object99", "object100", "object101", "object102", "object103", "object104", "object105", "object106", "object107", "object108", "object109", "object110", "object111", "object112", "object113", "object114", "object115", "object116", "object117", "object118", "object119");
HealthDeatils healthDetails = new HealthDetails();
Utility.setListToPOJO(data,healthDetails);
}
}
Below is the output
Error Message (Edited):
java.lang.IllegalArgumentException: argument type mismatch
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
atsun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:592)
The cause is that the parameter you passed, objList.get(i++) is not the type the method you invoke required.
modify you code to
for(Method method : methods){
String value = objList.get(i);
try {
if(method.getName().startsWith("set"){
method.invoke(healthDetails, value);
i++;
}
} catch (Exception e) {
e.printStackTrace();
System.out.println("Value is: " + value); // show which value is wrong
}
}
This would check which value type is wrong.
On the other hand, for the wrong order of methods. I suggest you change objList from List<String> to Map<String, Obj>, the key is the name of the method you want to invoke, like Id, Name. Then you invoke it by just add set in front of it.
for (Map.Entry<String, String> entry : map.entrySet())
{
Object value = entry.getValue();
Method method = healthDetails.getClass().getDeclaredMethod("set"+entry.getKey(), value.getClass());
method.invoke(healthDetails, value);
}
Your HealthDetails class have 124 properties and 124 setter methods but you are populating data list with only 120 elements causing ArrayIndexOutOfBoundsException while calling the setter methods through reflection.
If we provide arguments for all the setter methods in that list your code will work without any issue.
Below is the working modified code:
public class RunMethod {
public static void main(String[] args) {
List<String> data = Arrays.asList("id", "name", "age", "height", " object0", "object1", "object2", "object3", "object4", "object5", "object6", "object7", "object8", "object9", "object10", "object11", "object12", "object13", "object14", "object15", "object16", "object17", "object18", "object19", "object20", "object21", "object22", "object23", "object24", "object25", "object26", "object27", "object28", "object29", "object30", "object31", "object32", "object33", "object34", "object35", "object36", "object37", "object38", "object39", "object40", "object41", "object42", "object43", "object44", "object45", "object46", "object47", "object48", "object49", "object50", "object51", "object52", "object53", "object54", "object55", "object56", "object57", "object58", "object59", "object60", "object61", "object62", "object63", "object64", "object65", "object66", "object67", "object68", "object69", "object70", "object71", "object72", "object73", "object74", "object75", "object76", "object77", "object78", "object79", "object80", "object81", "object82", "object83", "object84", "object85", "object86", "object87", "object88", "object89", "object90", "object91", "object92", "object93", "object94", "object95", "object96", "object97", "object98", "object99", "object100", "object101", "object102", "object103", "object104", "object105", "object106", "object107", "object108", "object109", "object110", "object111", "object112", "object113", "object114", "object115", "object116", "object117", "object118", "object119");
HealthDetails healthDetails = new HealthDetails();
Utility.setListToPOJO(data, healthDetails);
}
}
Utility Class
public class Utility{
public static void setListToPOJO(List objList, HealthDetails healthDetails) {
System.out.println(objList.size());
Method[] methods = healthDetails.getClass().getDeclaredMethods();
System.out.println("methods array size " +methods.length);
int i = 0;
for (Method method : methods) {
if (method.getName().startsWith("set")) {
System.out.println(method.getName());
try {
method.invoke(healthDetails, objList.get(i++));
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
}
}
}
A different approach.
Currently, your code reads:
Methods[] methods = healthDetails.getClass().getDeclaredMethods();
int i = 0;
for(Method method : methods){
if(method.getName().startsWith("set"){
method.invoke(healthDetails, objList.get(i++));
}
}
The implicit assumption here is: the setter methods returned by getDeclaredMethods() are in the same order as your parameters (List<String> objList).
First of all, that assumption is wrong. There is no guaranteed order in that array.
But beyond that: when you know the order of elements in your list you simply don't need to use reflection at all.
You just do:
for (int i=0; i < objList.size(); i++) {
String parm = objList.get(i);
switch (i) {
case 0: healthDetails.setId(parm); break;
case 1: healthDetails.set...(parm); break;
and so on.
The point is, as stated multiple times: using a flat list means that you (somehow) must know in which order the arguments come in. And then you can simply use that order to determine the required setter method.
In other words: the code example you are showing implies that you do not need to use reflection to solve this problem. At all. Your idea to use reflection only buys you complexity, nothing else.
( of course: when the input would be a Map<String, String> that provided the field names, things would be different. but as long as you use a list with a fixed order, there is no need and point using reflection! )
Given the update, the only real answer there is: don't use 100+ fields named data1, data2, ... that is what arrays/list are for.
In my logic, I am attempting to map a JDBCRDD - TopologyRDD over to a JavaBean of JavaRDD.
TopologyRDD.count() returns the CORRECT number of rows, so I know the data was loaded in correctly. I also mapped TopologyRDD to a List just to confirm the data was loaded in, and it loaded in the data just fine.
Problem: When mapping TopologyRDD to MODEL_TOPOLOGYRDD, the MODEL_TOPOLOGYRDD.count() action is returning a nullpointer exception error.
Model:
public class modelTopology implements Serializable {
private String A_TYPE;
private String Z_TYPE;
private String A_CLLI;
private String Z_CLLI;
private String A_HOSTNAME;
private String Z_HOSTNAME;
private String A_LOCATION;
private String A_LOC_TYPE;
private String Z_LOCATION;
private String Z_LOC_TYPE;
private String A_SHELF;
private String A_SLOT;
private String A_CARD;
private String A_PORT;
private String A_INTERFACE;
private String A_IF_DESC;
private String Z_SHELF;
private String Z_SLOT;
private String Z_CARD;
private String Z_PORT;
private String Z_INTERFACE;
private String Z_IF_DESC;
private String A_CARD_NAME;
private String Z_CARD_NAME;
private String PHY_CIRCUIT_ID;
private String LAG_CIRCUIT_ID;
private String PHY_CIRCUIT_ALIAS;
private String A_VENDOR;
private String A_MODEL;
private String A_TECHNOLOGY;
private String Z_VENDOR;
private String Z_MODEL;
private String Z_TECHNOLOGY;
private String A_EH_ELEMENT_ID;
private String A_EH_MACHINE_ID;
private String Z_EH_ELEMENT_ID;
private String Z_EH_MACHINE_ID;
private String A_EH_SPEED;
private String Z_EH_SPEED;
private String A_EH_SPEED1;
private String Z_EH_SPEED1;
private String A_EH_EHEALTH_DOMAIN;
private String Z_EH_EHEALTH_DOMAIN;
private String A_MRTG_HOSTID;
private String A_MRTG_GRPID;
private String A_MRTG_IFID;
private String Z_MRTG_HOSTID;
private String Z_MRTG_GRPID;
private String Z_MRTG_IFID;
private String A_MGMT_IP;
private String Z_MGMT_IP;
private String A_IF_INDEX;
private String Z_IF_INDEX;
private String IS_PROD;
private String TOPOLOGY_KEY;
private String COMMIT_TS;
public void setA_TYPE(String A_TYPE) {
this.A_TYPE = A_TYPE;
}
public void setZ_TYPE(String Z_TYPE) {
this.Z_TYPE = Z_TYPE;
}
public void setA_CLLI(String A_CLLI) {
this.A_CLLI = A_CLLI;
}
public void setZ_CLLI(String Z_CLLI) {
this.Z_CLLI = Z_CLLI;
}
public void setA_HOSTNAME(String A_HOSTNAME) {
this.A_HOSTNAME = A_HOSTNAME;
}
public void setZ_HOSTNAME(String Z_HOSTNAME) {
this.Z_HOSTNAME = Z_HOSTNAME;
}
public void setA_LOCATION(String A_LOCATION) {
this.A_LOCATION = A_LOCATION;
}
public void setA_LOC_TYPE(String A_LOC_TYPE) {
this.A_LOC_TYPE = A_LOC_TYPE;
}
public void setZ_LOCATION(String Z_LOCATION) {
this.Z_LOCATION = Z_LOCATION;
}
public void setZ_LOC_TYPE(String Z_LOC_TYPE) {
this.Z_LOC_TYPE = Z_LOC_TYPE;
}
public void setA_SHELF(String A_SHELF) {
this.A_SHELF = A_SHELF;
}
public void setA_SLOT(String A_SLOT) {
this.A_SLOT = A_SLOT;
}
public void setA_CARD(String A_CARD) {
this.A_CARD = A_CARD;
}
public void setA_PORT(String A_PORT) {
this.A_PORT = A_PORT;
}
public void setA_INTERFACE(String A_INTERFACE) {
this.A_INTERFACE = A_INTERFACE;
}
public void setA_IF_DESC(String A_IF_DESC) {
this.A_IF_DESC = A_IF_DESC;
}
public void setZ_SHELF(String Z_SHELF) {
this.Z_SHELF = Z_SHELF;
}
public void setZ_SLOT(String Z_SLOT) {
this.Z_SLOT = Z_SLOT;
}
public void setZ_CARD(String Z_CARD) {
this.Z_CARD = Z_CARD;
}
public void setZ_PORT(String Z_PORT) {
this.Z_PORT = Z_PORT;
}
public void setZ_INTERFACE(String Z_INTERFACE) {
this.Z_INTERFACE = Z_INTERFACE;
}
public void setZ_IF_DESC(String Z_IF_DESC) {
this.Z_IF_DESC = Z_IF_DESC;
}
public void setA_CARD_NAME(String A_CARD_NAME) {
this.A_CARD_NAME = A_CARD_NAME;
}
public void setZ_CARD_NAME(String Z_CARD_NAME) {
this.Z_CARD_NAME = Z_CARD_NAME;
}
public void setPHY_CIRCUIT_ID(String PHY_CIRCUIT_ID) {
this.PHY_CIRCUIT_ID = PHY_CIRCUIT_ID;
}
public void setLAG_CIRCUIT_ID(String LAG_CIRCUIT_ID) {
this.LAG_CIRCUIT_ID = LAG_CIRCUIT_ID;
}
public void setPHY_CIRCUIT_ALIAS(String PHY_CIRCUIT_ALIAS) {
this.PHY_CIRCUIT_ALIAS = PHY_CIRCUIT_ALIAS;
}
public void setA_VENDOR(String A_VENDOR) {
this.A_VENDOR = A_VENDOR;
}
public void setA_MODEL(String A_MODEL) {
this.A_MODEL = A_MODEL;
}
public void setA_TECHNOLOGY(String A_TECHNOLOGY) {
this.A_TECHNOLOGY = A_TECHNOLOGY;
}
public void setZ_VENDOR(String Z_VENDOR) {
this.Z_VENDOR = Z_VENDOR;
}
public void setZ_MODEL(String Z_MODEL) {
this.Z_MODEL = Z_MODEL;
}
public void setZ_TECHNOLOGY(String Z_TECHNOLOGY) {
this.Z_TECHNOLOGY = Z_TECHNOLOGY;
}
public void setA_EH_ELEMENT_ID(String A_EH_ELEMENT_ID) {
this.A_EH_ELEMENT_ID = A_EH_ELEMENT_ID;
}
public void setA_EH_MACHINE_ID(String A_EH_MACHINE_ID) {
this.A_EH_MACHINE_ID = A_EH_MACHINE_ID;
}
public void setZ_EH_ELEMENT_ID(String Z_EH_ELEMENT_ID) {
this.Z_EH_ELEMENT_ID = Z_EH_ELEMENT_ID;
}
public void setZ_EH_MACHINE_ID(String Z_EH_MACHINE_ID) {
this.Z_EH_MACHINE_ID = Z_EH_MACHINE_ID;
}
public void setA_EH_SPEED(String A_EH_SPEED) {
this.A_EH_SPEED = A_EH_SPEED;
}
public void setZ_EH_SPEED(String Z_EH_SPEED) {
this.Z_EH_SPEED = Z_EH_SPEED;
}
public void setA_EH_SPEED1(String A_EH_SPEED1) {
this.A_EH_SPEED1 = A_EH_SPEED1;
}
public void setZ_EH_SPEED1(String Z_EH_SPEED1) {
this.Z_EH_SPEED1 = Z_EH_SPEED1;
}
public void setA_EH_EHEALTH_DOMAIN(String A_EH_EHEALTH_DOMAIN) {
this.A_EH_EHEALTH_DOMAIN = A_EH_EHEALTH_DOMAIN;
}
public void setZ_EH_EHEALTH_DOMAIN(String Z_EH_EHEALTH_DOMAIN) {
this.Z_EH_EHEALTH_DOMAIN = Z_EH_EHEALTH_DOMAIN;
}
public void setA_MRTG_HOSTID(String A_MRTG_HOSTID) {
this.A_MRTG_HOSTID = A_MRTG_HOSTID;
}
public void setA_MRTG_GRPID(String A_MRTG_GRPID) {
this.A_MRTG_GRPID = A_MRTG_GRPID;
}
public void setA_MRTG_IFID(String A_MRTG_IFID) {
this.A_MRTG_IFID = A_MRTG_IFID;
}
public void setZ_MRTG_HOSTID(String Z_MRTG_HOSTID) {
this.Z_MRTG_HOSTID = Z_MRTG_HOSTID;
}
public void setZ_MRTG_GRPID(String Z_MRTG_GRPID) {
this.Z_MRTG_GRPID = Z_MRTG_GRPID;
}
public void setZ_MRTG_IFID(String Z_MRTG_IFID) {
this.Z_MRTG_IFID = Z_MRTG_IFID;
}
public void setA_MGMT_IP(String A_MGMT_IP) {
this.A_MGMT_IP = A_MGMT_IP;
}
public void setZ_MGMT_IP(String Z_MGMT_IP) {
this.Z_MGMT_IP = Z_MGMT_IP;
}
public void setA_IF_INDEX(String A_IF_INDEX) {
this.A_IF_INDEX = A_IF_INDEX;
}
public void setZ_IF_INDEX(String Z_IF_INDEX) {
this.Z_IF_INDEX = Z_IF_INDEX;
}
public void setIS_PROD(String IS_PROD) {
this.IS_PROD = IS_PROD;
}
public void setTOPOLOGY_KEY(String TOPOLOGY_KEY) {
this.TOPOLOGY_KEY = TOPOLOGY_KEY;
}
public void setCOMMIT_TS(String COMMIT_TS) {
this.COMMIT_TS = COMMIT_TS;
}
public String getA_TYPE() {
return A_TYPE;
}
public String getZ_TYPE() {
return Z_TYPE;
}
public String getA_CLLI() {
return A_CLLI;
}
public String getZ_CLLI() {
return Z_CLLI;
}
public String getA_HOSTNAME() {
return A_HOSTNAME;
}
public String getZ_HOSTNAME() {
return Z_HOSTNAME;
}
public String getA_LOCATION() {
return A_LOCATION;
}
public String getA_LOC_TYPE() {
return A_LOC_TYPE;
}
public String getZ_LOCATION() {
return Z_LOCATION;
}
public String getZ_LOC_TYPE() {
return Z_LOC_TYPE;
}
public String getA_SHELF() {
return A_SHELF;
}
public String getA_SLOT() {
return A_SLOT;
}
public String getA_CARD() {
return A_CARD;
}
public String getA_PORT() {
return A_PORT;
}
public String getA_INTERFACE() {
return A_INTERFACE;
}
public String getA_IF_DESC() {
return A_IF_DESC;
}
public String getZ_SHELF() {
return Z_SHELF;
}
public String getZ_SLOT() {
return Z_SLOT;
}
public String getZ_CARD() {
return Z_CARD;
}
public String getZ_PORT() {
return Z_PORT;
}
public String getZ_INTERFACE() {
return Z_INTERFACE;
}
public String getZ_IF_DESC() {
return Z_IF_DESC;
}
public String getA_CARD_NAME() {
return A_CARD_NAME;
}
public String getZ_CARD_NAME() {
return Z_CARD_NAME;
}
public String getPHY_CIRCUIT_ID() {
return PHY_CIRCUIT_ID;
}
public String getLAG_CIRCUIT_ID() {
return LAG_CIRCUIT_ID;
}
public String getPHY_CIRCUIT_ALIAS() {
return PHY_CIRCUIT_ALIAS;
}
public String getA_VENDOR() {
return A_VENDOR;
}
public String getA_MODEL() {
return A_MODEL;
}
public String getA_TECHNOLOGY() {
return A_TECHNOLOGY;
}
public String getZ_VENDOR() {
return Z_VENDOR;
}
public String getZ_MODEL() {
return Z_MODEL;
}
public String getZ_TECHNOLOGY() {
return Z_TECHNOLOGY;
}
public String getA_EH_ELEMENT_ID() {
return A_EH_ELEMENT_ID;
}
public String getA_EH_MACHINE_ID() {
return A_EH_MACHINE_ID;
}
public String getZ_EH_ELEMENT_ID() {
return Z_EH_ELEMENT_ID;
}
public String getZ_EH_MACHINE_ID() {
return Z_EH_MACHINE_ID;
}
public String getA_EH_SPEED() {
return A_EH_SPEED;
}
public String getZ_EH_SPEED() {
return Z_EH_SPEED;
}
public String getA_EH_SPEED1() {
return A_EH_SPEED1;
}
public String getZ_EH_SPEED1() {
return Z_EH_SPEED1;
}
public String getA_EH_EHEALTH_DOMAIN() {
return A_EH_EHEALTH_DOMAIN;
}
public String getZ_EH_EHEALTH_DOMAIN() {
return Z_EH_EHEALTH_DOMAIN;
}
public String getA_MRTG_HOSTID() {
return A_MRTG_HOSTID;
}
public String getA_MRTG_GRPID() {
return A_MRTG_GRPID;
}
public String getA_MRTG_IFID() {
return A_MRTG_IFID;
}
public String getZ_MRTG_HOSTID() {
return Z_MRTG_HOSTID;
}
public String getZ_MRTG_GRPID() {
return Z_MRTG_GRPID;
}
public String getZ_MRTG_IFID() {
return Z_MRTG_IFID;
}
public String getA_MGMT_IP() {
return A_MGMT_IP;
}
public String getZ_MGMT_IP() {
return Z_MGMT_IP;
}
public String getA_IF_INDEX() {
return A_IF_INDEX;
}
public String getZ_IF_INDEX() {
return Z_IF_INDEX;
}
public String getIS_PROD() {
return IS_PROD;
}
public String getTOPOLOGY_KEY() {
return TOPOLOGY_KEY;
}
public String getCOMMIT_TS() {
return COMMIT_TS;
}
}
Code:
//Push into JDBC RDD Object
JdbcRDD<Object[]> TopologyJDBCRDD = new JdbcRDD(sc.sc(),oraclecon,"SELECT * FROM NPIDWUAT.FIOS_TOPOLOGY_STG WHERE ? = ?",1,1,1, new MapResult(),ClassManifestFactory$.MODULE$.fromClass(Object[].class));
//Convert to JavaRDD
JavaRDD<Object[]> TopologyRDD = JavaRDD.fromRDD(TopologyJDBCRDD, ClassManifestFactory$.MODULE$.fromClass(Object[].class));
System.out.println("Number of Records: " + TopologyRDD.count());
JavaRDD<modelTopology> MODEL_TOPOLOGYRDD = TopologyRDD.map(
new Function<Object[], modelTopology>() {
#Override
public modelTopology call(final Object[] line) throws Exception {
Object[] line2 = line;
for(int i=0;i<line2.length;i++){
if(line2[i].toString() == null){
line2[i] = "";
}
else{
line2[i] = line2[i].toString();
}
}
modelTopology toporow = new modelTopology();
toporow.setA_TYPE(line2[0].toString());
toporow.setZ_TYPE(line2[1].toString());
toporow.setA_CLLI(line2[2].toString());
toporow.setZ_CLLI(line2[3].toString());
toporow.setA_HOSTNAME(line2[4].toString());
toporow.setZ_HOSTNAME(line2[5].toString());
toporow.setA_LOCATION(line2[6].toString());
toporow.setA_LOC_TYPE(line2[7].toString());
toporow.setZ_LOCATION(line2[8].toString());
toporow.setZ_LOC_TYPE(line2[9].toString());
toporow.setA_SHELF(line2[10].toString());
toporow.setA_SLOT(line2[11].toString());
toporow.setA_CARD(line2[12].toString());
toporow.setA_PORT(line2[13].toString());
toporow.setA_INTERFACE(line2[14].toString());
toporow.setA_IF_DESC(line2[15].toString());
toporow.setZ_SHELF(line2[16].toString());
toporow.setZ_SLOT(line2[17].toString());
toporow.setZ_CARD(line2[18].toString());
toporow.setZ_PORT(line2[19].toString());
toporow.setZ_INTERFACE(line2[20].toString());
toporow.setZ_IF_DESC(line2[21].toString());
toporow.setA_CARD_NAME(line2[22].toString());
toporow.setZ_CARD_NAME(line2[23].toString());
toporow.setPHY_CIRCUIT_ID(line2[24].toString());
toporow.setLAG_CIRCUIT_ID(line2[25].toString());
toporow.setPHY_CIRCUIT_ALIAS(line2[26].toString());
toporow.setA_VENDOR(line2[27].toString());
toporow.setA_MODEL(line2[28].toString());
toporow.setA_TECHNOLOGY(line2[29].toString());
toporow.setZ_VENDOR(line2[30].toString());
toporow.setZ_MODEL(line2[31].toString());
toporow.setZ_TECHNOLOGY(line2[32].toString());
toporow.setA_EH_ELEMENT_ID(line2[33].toString());
toporow.setA_EH_MACHINE_ID(line2[34].toString());
toporow.setZ_EH_ELEMENT_ID(line2[35].toString());
toporow.setZ_EH_MACHINE_ID(line2[36].toString());
toporow.setA_EH_SPEED(line2[37].toString());
toporow.setZ_EH_SPEED(line2[38].toString());
toporow.setA_EH_SPEED1(line2[39].toString());
toporow.setZ_EH_SPEED1(line2[40].toString());
toporow.setA_EH_EHEALTH_DOMAIN(line2[41].toString());
toporow.setZ_EH_EHEALTH_DOMAIN(line2[42].toString());
toporow.setA_MRTG_HOSTID(line2[43].toString());
toporow.setA_MRTG_GRPID(line2[44].toString());
toporow.setA_MRTG_IFID(line2[45].toString());
toporow.setZ_MRTG_HOSTID(line2[46].toString());
toporow.setZ_MRTG_GRPID(line2[47].toString());
toporow.setZ_MRTG_IFID(line2[48].toString());
toporow.setA_MGMT_IP(line2[49].toString());
toporow.setZ_MGMT_IP(line2[50].toString());
toporow.setA_IF_INDEX(line2[51].toString());
toporow.setZ_IF_INDEX(line2[52].toString());
toporow.setIS_PROD(line2[53].toString());
toporow.setTOPOLOGY_KEY(line2[54].toString());
toporow.setCOMMIT_TS(line2[55].toString());
return toporow;
}
});
System.out.println("MODEL_TOPOLOGYRDD COUNT: " + MODEL_TOPOLOGYRDD.count());
Stacktrace:
Application Failed...org.apache.spark.SparkException: Job aborted due to stage failure: Task 0 in stage 1.0 failed 1 times, most recent failure: Lost task 0.0 in stage 1.0 (TID 1, localhost): java.lang.NullPointerException
at com.verizon.npi.MainApp$1.call(MainApp.java:103)
at com.verizon.npi.MainApp$1.call(MainApp.java:96)
at org.apache.spark.api.java.JavaPairRDD$$anonfun$toScalaFunction$1.apply(JavaPairRDD.scala:999)
at scala.collection.Iterator$$anon$11.next(Iterator.scala:328)
at org.apache.spark.storage.MemoryStore.unrollSafely(MemoryStore.scala:249)
at org.apache.spark.CacheManager.putInBlockManager(CacheManager.scala:163)
at org.apache.spark.CacheManager.getOrCompute(CacheManager.scala:70)
at org.apache.spark.rdd.RDD.iterator(RDD.scala:243)
at org.apache.spark.scheduler.ResultTask.runTask(ResultTask.scala:61)
at org.apache.spark.scheduler.Task.run(Task.scala:56)
at org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:200)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
The only problem I can see with this code is if any line2[i] are null.
And if(line2[i].toString() == null) won't work because toString() never returns null for the Object class.
I see that you want any null values to become empty strings, so try this as your for-loop instead
for(int i = 0; i < line2.length; i++){
line2[i] = (line2[i] == null) ? "" : String.valueOf(line2[i]);
}
Note the use of String.valueOf, which altogether avoids the NullPointerException when trying to get the String value of objects.
I have the following Json string.How to parse this kind of Json using Gson in Java?Any help would be appreciated.
{
"acclst":[{
"accountInfoData":[{
"userId":9,
"rid":"1-Z5S3",
"acnme":"acc_1234.",
"actpe":"Fabricator / Distributor",
"mph":"2660016354",
"euse":"Biofuels",
"com":"0",
"sta":"Active",
"stem":"BBUSER5",
"wsite":"",
"fax":"",
"zone":"",
"crted":"BBUSER4",
"statusX":1,
"partyId":0,
"address":[]
}
]
}
],
"conlst":[],
"actlst":[],
"prolst":[],
"code":"200"
}
your Gson getter/Setter class will be
sample.java
public class sample {
public String code="";
ArrayList<String> conlst;
ArrayList<String> actlst;
ArrayList<innerObject> prolst;
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public ArrayList<String> getConlst() {
return conlst;
}
public void setConlst(ArrayList<String> conlst) {
this.conlst = conlst;
}
public ArrayList<String> getActlst() {
return actlst;
}
public void setActlst(ArrayList<String> actlst) {
this.actlst = actlst;
}
public ArrayList<innerObject> getProlst() {
return prolst;
}
public void setProlst(ArrayList<innerObject> prolst) {
this.prolst = prolst;
}
}
innerObject.java
public class innerObject {
ArrayList<String> accountInfoData;
public ArrayList<String> getAccountInfoData() {
return accountInfoData;
}
public void setAccountInfoData(ArrayList<String> accountInfoData) {
this.accountInfoData = accountInfoData;
}
}
secondInnerObject.java
public class secondInnerObject {
public String userId="";
public String rid="";
public String acme="";
public String actpe="";
public String mph="";
public String euse="";
public String com="";
public String sta="";
public String stem="";
public String wsite="";
public String fax="";
public String zone="";
public String crted="";
public String statusX="";
public String partyId="";
ArrayList<String> address;
ArrayList<String> accountInfoData;
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public String getRid() {
return rid;
}
public void setRid(String rid) {
this.rid = rid;
}
public String getAcme() {
return acme;
}
public void setAcme(String acme) {
this.acme = acme;
}
public String getActpe() {
return actpe;
}
public void setActpe(String actpe) {
this.actpe = actpe;
}
public String getMph() {
return mph;
}
public void setMph(String mph) {
this.mph = mph;
}
public String getEuse() {
return euse;
}
public void setEuse(String euse) {
this.euse = euse;
}
public String getCom() {
return com;
}
public void setCom(String com) {
this.com = com;
}
public String getSta() {
return sta;
}
public void setSta(String sta) {
this.sta = sta;
}
public String getStem() {
return stem;
}
public void setStem(String stem) {
this.stem = stem;
}
public String getWsite() {
return wsite;
}
public void setWsite(String wsite) {
this.wsite = wsite;
}
public String getFax() {
return fax;
}
public void setFax(String fax) {
this.fax = fax;
}
public String getZone() {
return zone;
}
public void setZone(String zone) {
this.zone = zone;
}
public String getCrted() {
return crted;
}
public void setCrted(String crted) {
this.crted = crted;
}
public String getStatusX() {
return statusX;
}
public void setStatusX(String statusX) {
this.statusX = statusX;
}
public String getPartyId() {
return partyId;
}
public void setPartyId(String partyId) {
this.partyId = partyId;
}
public ArrayList<String> getAddress() {
return address;
}
public void setAddress(ArrayList<String> address) {
this.address = address;
}
public ArrayList<String> getAccountInfoData() {
return accountInfoData;
}
public void setAccountInfoData(ArrayList<String> accountInfoData) {
this.accountInfoData = accountInfoData;
}
}
to fetch
String json= "your_json_string";
Gson gson= new Gson();
sample objSample=gson.fromJson(json,sample.getClass());
thats it
You have to use JSONObject to parse this json in android.
Take a look at the following link.
http://developer.android.com/reference/org/json/JSONObject.html
Android already contains the required JSON libraries. You can use a valid string or a file for input. Here is code and explanation taken from here:
import org.json.JSONArray;
import org.json.JSONObject;
import android.app.Activity;
import android.os.Bundle;
public class JsonParser extends Activity {
private JSONObject jObject;
private String jString = "{\"menu\": {\"id\": \"file\", \"value\": \"File\", \"popup\": { \"menuitem\": [ {\"value\": \"New\", \"onclick\": \"CreateNewDoc()\"}, {\"value\": \"Open\", \"onclick\": \"OpenDoc()\"}, {\"value\": \"Close\", \"onclick\": \"CloseDoc()\"}]}}}";//write your JSON String here
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
try {
parse();
} catch (Exception e) {
e.printStackTrace();
}
}
private void parse() throws Exception {
jObject = new JSONObject(jString);
JSONObject menuObject = jObject.getJSONObject("menu");
String attributeId = menuObject.getString("id");
System.out.println(attributeId);
String attributeValue = menuObject.getString("value");
System.out.println(attributeValue);
JSONObject popupObject = menuObject.getJSONObject("popup");
JSONArray menuitemArray = popupObject.getJSONArray("menuitem");
for (int i = 0; i < 3; i++) {
System.out.println(menuitemArray.getJSONObject(i)
.getString("value").toString());
System.out.println(menuitemArray.getJSONObject(i).getString(
"onclick").toString());
}
}
}
Here you have a tutorial which answers your needs - Android + Gson