This is my Resource class where I want to handle POST operation to get @BeanParam
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import org.springframework.stereotype.Component;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
@Path("")
@Component
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.TEXT_PLAIN)
public class MyResource{
@POST
@Path("/create")
@ApiOperation()
@ApiResponses()
public String createProfile(@BeanParam final Person person) {
// Person handling goes here....
}
}
public class Person{
@FormParam("name")
private String name;
@FormParam("designation")
private String designation;
// getters and setters...
}
From a test:
public void test(){
final String uri = BASE_URI + "/create";
// Here I am creating Person and converting it as json
final String jsonInput = SimplePojoMapper.toJSON(person);
final HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
final HttpEntity<String> entity = new HttpEntity<>(jsonInput, headers);
final ResponseEntity<String> responseEntity
= this.restTemplate.postForEntity(uri, entity, String.class);
LOGGER.info("HTTP RESPONSE " + responseEntity.getStatusCode());
}
But it Person
has all the null fields.
Is there any way to handle this with @BeanParam
. I didn't want to use @FormParam
or MultuvaluedMap
for some reason.