My frontend server sends a json built from a VueJS form. I am trying to get, to map and to parse this json using Jersey 2.32.
{
"objetDesLiensDuTheme": {
"id": 7195,
"formalisation": {
"selectTitreFichier": "fiche de formalisation",
"inputTitreFichier": "fiche de formalisation titre fichier",
"inputFichier": {},
},
"modop": {
"selectTitreFichier": "fiche méthodologique",
"inputTitreFichier": "fiche méthodologique titre fichier",
"inputFichier": {},
},
}
}
I've stringyfied it to show its structure here but it is a JSON object and a console.log shows me also the content of "inputFichier":
inputFichier: File { name: "Fichier formalisation.txt", lastModified: 1690373320586, size: 0, type: "text/plain", webkitRelativePath: ""}
My REST controller method looks like this:
@POST
@Path("/create")
@Consumes(MediaType.APPLICATION_JSON)
public Response createLien(@BeanParam LiensDTO objetDesLiensDuTheme)
{
Response response;
//TODO
System.out.println(objetDesLiensDuTheme);
response = Response.status(Status.CREATED).build();
return response;
}
But according to the toString method, the bean parameter seems to be null:
LiensDTO [objetDesLiensDuTheme=null]
Here is the LiensDTO class (getter and setter not shown):
public class LiensDTO implements Serializable
{
private static final long serialVersionUID = -5717326975468155988L;
public LiensDTO()
{
super();
}
@FormParam("objetDesLiensDuTheme")
// @JsonProperty("objetDesLiensDuTheme")
private DocLienDTO objetDesLiensDuTheme;
@Override
public String toString()
{
return "LiensDTO [objetDesLiensDuTheme=" + objetDesLiensDuTheme + "]";
}
}
Here is the DocLienDTO class (getters and setters not shown):
public class DocLienDTO implements Serializable
{
private static final long serialVersionUID = -493282593738066056L;
private int id;
private DocumentDTO formalisation;
private DocumentDTO modop;
}
And finally the DocumentDTO class (getters and setters not shown):
public class DocumentDTO implements Serializable
{
private static final long serialVersionUID = -6698584238714969958L;
private String selectTitreFichier;
private String inputTitreFichier;
private File inputFichier;
}
When I try without the @BeanParam
annotation (like described here
or with the @RequestBody
annotation in the rest controller, I get this exception:
com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of
api.bean.LiensDTOout of START_ARRAY token at [Source: (org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$UnCloseableInputStream); line: 1, column: 1].
However, the json object doesn't contain arrays.
I also tried with @JsonProperty("objetDesLiensDuTheme")
instead of @FormParam("objetDesLiensDuTheme")
.
I would like to get and to iterate through the "objetDesLiensDuTheme" object for my upload module.