RESTful API + POST + json body
Library:
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.7.2</version>
</dependency>
Mapper Class
public class MapperUtil {
private final static ObjectMapper mapper = new ObjectMapper();
public static <T> T readAsObjectOf(Class<T> clazz, String value) {
try {
return mapper.readValue(value, clazz);
} catch (IOException e) {
logger.error(e.getMessage());
}
return null;
}
}
@POST
@Path("/transaction")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public TransactionIdDetails requestTransactionIds(String jsonInput) {
TransactionIdFilterInput transactionIdFilterInput = MapperUtil.readAsObjectOf(TransactionIdFilterInput.class,
jsonInput);
.........
.........
}
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.7.2</version>
</dependency>
Mapper Class
public class MapperUtil {
private final static ObjectMapper mapper = new ObjectMapper();
public static <T> T readAsObjectOf(Class<T> clazz, String value) {
try {
return mapper.readValue(value, clazz);
} catch (IOException e) {
logger.error(e.getMessage());
}
return null;
}
}
@POST
@Path("/transaction")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public TransactionIdDetails requestTransactionIds(String jsonInput) {
TransactionIdFilterInput transactionIdFilterInput = MapperUtil.readAsObjectOf(TransactionIdFilterInput.class,
jsonInput);
.........
.........
}
Comments
Post a Comment