Bom dia pessoa, estou desenvolvendo um web service utilizando Rest, aparentemente o mesmo está funcionando, pois, quando acesso, ele trás oque tem que trazer. O problema é na hora de converter a string JSON pra o objeto ele dá erro. O objeto só tem uma variável, esta variável é uma lista de outro objeto. Abaixo os trechos dos fontes. Alguém pode me dá uma luz?
Erro: java.lang.ClassCastException: model.ScriptVersion cannot be cast to model.ScriptVersionListWrapper at com.integration.SURELScript.doWork(SURELScript.java:37) at com.integration.SURELScript.doWork(SURELScript.java:1) at com.services.FilterSystemUpdatesByScriptNames.filter(FilterSystemUpdatesByScriptNames.java:23) at com.controller.ConfirmInformationsController.getScriptToBeLaunchedBySystemVersion(ConfirmInformationsController.java:136) at com.controller.ConfirmInformationsController.lambda$0(ConfirmInformationsController.java:76) at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86) at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238) at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191) at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59) at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58) at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74) at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54) at javafx.event.Event.fireEvent(Event.java:198) at javafx.scene.Scene$ClickGenerator.postProcess(Scene.java:3470) at javafx.scene.Scene$ClickGenerator.access$8100(Scene.java:3398) at javafx.scene.Scene$MouseHandler.process(Scene.java:3766) at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485) at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762) at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494) at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:352) at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:275) at java.security.AccessController.doPrivileged(Native Method) at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$355(GlassViewEventHandler.java:388) at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389) at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:387) at com.sun.glass.ui.View.handleMouseEvent(View.java:555) at com.sun.glass.ui.View.notifyMouse(View.java:937) at com.sun.glass.ui.win.WinApplication._runLoop(Native Method) at com.sun.glass.ui.win.WinApplication.lambda$null$149(WinApplication.java:191)
WebService:
@Path("/allVersions") @GET @Produces(MediaType.APPLICATION_JSON) @PermitAll public Response getAllVersions() { ScriptVersionListWrapper versions = new ScriptVersionListWrapper(); try { versions.setVersions(new VersionDaoImpl().getAllVersions()); return Response.ok(versions).build(); } catch (Exception e) { e.printStackTrace(); return Response.ok(null).build(); } }
Objeto: `
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement
public class ScriptVersionListWrapper {
@XmlElementWrapper
@XmlElement
private List<ScriptVersion> scriptVersion;
public ScriptVersionListWrapper() {
scriptVersion = new ArrayList<ScriptVersion>();
}
public List<ScriptVersion> getVersions() {
return scriptVersion;
}
public void setVersions(List<ScriptVersion> versions) {
this.scriptVersion = versions;
}
}`
Bean:
` @Entity
@Table(name = “TB_VERSION_SCRIPT”)
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class ScriptVersion implements Serializable {
private static final long serialVersionUID = -8451393100074453943L;
@Id
@Column(name = "PK_UPDATE")
@XmlElement
private Long pkUpdate;
@Column(name = "SYSTEM_UPDATE")
@XmlElement
private String sysUpdate;
@Column(name = "SCRIPTNAME")
@XmlElement
private String scriptName;
`
public List<ScriptVersion> doWork(String type) {
try {
Client client = ClientBuilder.newClient();
WebTarget target = client
.target(Resources.getPath(InstallerPaths.PathRestServiceKey) + "version/allVersions");
ScriptVersionListWrapper arrayVersion = target.request(MediaType.APPLICATION_JSON)
.get(ScriptVersionListWrapper.class);
List<ScriptVersion> list = arrayVersion.getVersions();
client.close();
return list;
} catch (Exception e) {
exitCode = -1;
MessageBox.showMessageAndWait(AlertType.ERROR, Resources.getCaption(InstallerCaptions.ErrorKey),
Resources.getMessage(InstallerMessages.UnknownCurrentVersionKey),
Resources.getMessage(InstallerMessages.VerifyConnectionOrContactAdminKey));
e.printStackTrace();
return null;
}
}
`