FormDataParam Object passed as JSON string in post request does not get deserialized properly

Viewed 3246

I have a rest call which is taking some parameters as FormDataParam. When I am passing object EngineConfigMeta in json string to the rest call from postman, at the restcall level the object is not getting deserialized properly.

Rest-call

@Path( "/add-config" )
@POST
@Consumes( MediaType.MULTIPART_FORM_DATA )
@Produces( MediaType.APPLICATION_JSON )
public Response addConfig( @FormDataParam( "config" ) EngineConfigMeta config,
        @FormDataParam( "file" ) InputStream configFileInputStream,
        @FormDataParam( "file" ) FormDataContentDisposition cdh)
{

    return Response.ok(Response.Status.OK).entity(buildJson(config.getVersion())).build();
}

EngineConfigMeta.java

public class EngineConfigMeta {

  private String tenantName;
  private long version;

  EngineConfigMeta(String tenantName, long version) {
   this.tenantName = tenantName;
   this.version = version;
  }

  ..getters and setters
}

This is how I am passing the parameters to rest call using postman - Postman screenshot

Now the problem is when I debug the code of rest call, I am getting all the json string assigned to only one property on EngineConfigMeta pojo -

EngineConfigMeta{tenantName={"tenantName": "abc", "version": 2}, version=0}

As you can see above that the whole object json string is assigned to tenantName property. So deserialization is not happening correctly here.

Please help me.

1 Answers
Related