I saw that when kept in a map or list the Wrapped object is returned as original type and not the wrapper.
(MyMap) {WEB_SRM_Response=(WEBSRM_Response) ca.logichic.foframework.WEBSRM_Response@2422fc3b, SUCCESS=true, ResponseCertificats=ca.logichic.foframework.ResponseCertificats@26b97e48}
When passed to events they work properly.
I have this class and it's wrapper.
The wrapper.
I've been using this for a while now. I now have an issue returning the wrapper to B4J in a map or a list. It complains of a classcast wrapper cannot be casted to wrapped class.
this is how I use it.
When I try getting it as athe wrapped object in B4Jas this I get.
How to solve this issue ?
(MyMap) {WEB_SRM_Response=(WEBSRM_Response) ca.logichic.foframework.WEBSRM_Response@2422fc3b, SUCCESS=true, ResponseCertificats=ca.logichic.foframework.ResponseCertificats@26b97e48}
When passed to events they work properly.
I have this class and it's wrapper.
Java:
package ca.logichic.foframework;
import okhttp3.Response;
import anywheresoftware.b4a.BA.Hide;
@Hide
public class WEBSRM_Response {
/**
* HTTP response status code
*/
public int StatusCode = 0;
/**
* Description of HTTP status returned
*/
public String StatusDescription = "";
/**
* Contains the JSON document received from the WEB-SRM
* Contient le document JSON reçu du MEVWEB
*/
public String ResponseJsonWEBSRM = "";
/**
* Exception caused by a communication problem with the WEB-SRM and managed by the SEV
* Exception provoquée par un problème de communication avec le MEV-WEB et gérée par le SEV
*/
public Exception ResponseExceptionWEBSRM;
/**
* HTTP response from WEB-SRM containing success or error codes
* Réponse HTTP du MEV-WEB contenant les codes de succès ou d'erreurs
*/
public Response HttpResponseMessageWEBSRM;
public WEBSRM_Response() {
}
}
The wrapper.
Java:
package ca.chicpos.mevweb;
import anywheresoftware.b4a.AbsObjectWrapper;
import anywheresoftware.b4a.BA.ShortName;
import ca.logichic.foframework.WEBSRM_Response;
import okhttp3.Response;
@ShortName("WEBSRM_Response")
public class WEBSRM_ResponseWrapper extends AbsObjectWrapper<WEBSRM_Response> {
private WEBSRM_Response mWEBSRM_Response;
public void Initialize() {
mWEBSRM_Response = new WEBSRM_Response();
this.setObject(mWEBSRM_Response);
}
public int getStatusCode() {
return this.getObject().StatusCode;
}
public String getStatusDescription() {
return this.getObject().StatusDescription;
}
public String getResponseJsonWEBSRM() {
return this.getObject().ResponseJsonWEBSRM;
}
public Exception getResponseExceptionWEBSRM() {
return this.getObject().ResponseExceptionWEBSRM;
}
public Response getHttpResponseMessageWEBSRM() {
return this.getObject().HttpResponseMessageWEBSRM;
}
public void setStatusCode(int statusCode) {
this.getObject().StatusCode = statusCode;
}
public void setStatusDescription(String statusDescription) {
this.getObject().StatusDescription = statusDescription;
}
public void setResponseJsonWEBSRM(String responseJsonWEBSRM) {
this.getObject().ResponseJsonWEBSRM = responseJsonWEBSRM;
}
public void setResponseExceptionWEBSRM(Exception responseExceptionWEBSRM) {
this.getObject().ResponseExceptionWEBSRM = responseExceptionWEBSRM;
}
public void setHttpResponseMessageWEBSRM(Response httpMessageResponseWEBSRM) {
this.getObject().HttpResponseMessageWEBSRM = httpMessageResponseWEBSRM;
}
}
I've been using this for a while now. I now have an issue returning the wrapper to B4J in a map or a list. It complains of a classcast wrapper cannot be casted to wrapped class.
this is how I use it.
Java:
WEBSRM_Response WEB_SRM_Response = UtilesJSON.CertificatesRequest(ValeursPossibles.Modif.REM,
HTTPHeadersDicti, jSon, _ALIAS_CERTIFICAT.SEV, KEY_PAIRS_DIR, changeItPass,TimeOutSeconds);
WEBSRM_ResponseWrapper mWEBSRM_ResponseWrapper = new WEBSRM_ResponseWrapper();
mWEBSRM_ResponseWrapper.Initialize();
mWEBSRM_ResponseWrapper.setObject(WEB_SRM_Response);
myMap.Put("WEB_SRM_Response", mWEBSRM_ResponseWrapper);
When I try getting it as athe wrapped object in B4Jas this I get.
B4X:
Dim WEB_SRM_Response As WEBSRM_Response = CertificateMap.Get("WEB_SRM_Response")
B4X:
java.lang.RuntimeException: java.lang.ClassCastException: class ca.chicpos.mevweb.WEBSRM_ResponseWrapper cannot be cast to class ca.logichic.foframework.WEBSRM_Response (ca.chicpos.mevweb.WEBSRM_ResponseWrapper and ca.logichic.foframework.WEBSRM_Response are in unnamed module of loader 'app')
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:140)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:98)
at anywheresoftware.b4j.object.JServlet$Handle.run(JServlet.java:146)
at anywheresoftware.b4j.object.JServlet.Handle(JServlet.java:126)
at anywheresoftware.b4j.object.JServlet.doPost(JServlet.java:96)
at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:520)
at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:587)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:764)
at org.eclipse.jetty.servlet.ServletHandler$ChainEnd.doFilter(ServletHandler.java:1630)
at org.eclipse.jetty.servlets.DoSFilter.doFilterChain(DoSFilter.java:483)
at org.eclipse.jetty.servlets.DoSFilter.doFilter(DoSFilter.java:332)
at org.eclipse.jetty.servlets.DoSFilter.doFilter(DoSFilter.java:297)
at org.eclipse.jetty.servlet.FilterHolder.doFilter(FilterHolder.java:202)
at org.eclipse.jetty.servlet.ServletHandler$Chain.doFilter(ServletHandler.java:1600)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:506)
at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:221)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1571)
at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:221)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1375)
at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:176)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:463)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1544)
at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:174)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1297)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:129)
at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:141)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:122)
at org.eclipse.jetty.server.Server.handle(Server.java:562)
at org.eclipse.jetty.server.HttpChannel.lambda$handle$0(HttpChannel.java:505)
at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:762)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:497)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:282)
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:319)
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:100)
at org.eclipse.jetty.io.SelectableChannelEndPoint$1.run(SelectableChannelEndPoint.java:53)
at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.runTask(AdaptiveExecutionStrategy.java:412)
at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.consumeTask(AdaptiveExecutionStrategy.java:381)
at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.tryProduce(AdaptiveExecutionStrategy.java:268)
at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.lambda$new$0(AdaptiveExecutionStrategy.java:138)
at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:407)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:894)
at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:1038)
at java.base/java.lang.Thread.run(Thread.java:1589)
Caused by: java.lang.ClassCastException: class ca.chicpos.mevweb.WEBSRM_ResponseWrapper cannot be cast to class ca.logichic.foframework.WEBSRM_Response (ca.chicpos.mevweb.WEBSRM_ResponseWrapper and ca.logichic.foframework.WEBSRM_Response are in unnamed module of loader 'app')
at ca.chicpos.server.mevweb_query._replacecertificate(mevweb_query.java:3091)
at ca.chicpos.server.mevweb_query$ResumableSub_PROCESS_QUERY.resume(mevweb_query.java:2286)
at ca.chicpos.server.mevweb_query._process_query(mevweb_query.java:2140)
at ca.chicpos.server.mevweb_query._handle(mevweb_query.java:2019)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
at java.base/java.lang.reflect.Method.invoke(Method.java:578)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:111)
... 42 more
How to solve this issue ?
Last edited: