user5157427 user5157427 - 12 days ago 6
Java Question

what is needed for Unmarshalling in rest call

suppose a remote application sending my spring rest web application this post request :

https://www.my-domain.com/order-status-update

Body:
{"orderId":"00010000100000000020","statusCode":"canceled"}

and in my application I have :

@Controller
public class OrderPlacementController
{
@RequestMapping(value = "/order-status-update-only-url", method = RequestMethod.POST)
@ResponseBody
public MerchantResponseInfo updateOrderStatus(@RequestBody final MerchantOrder order)
{
///
}
}


and I have :

public class MerchantOrder
{

private String orderId;
private String statusCode;


public String getOrderId()
{
return orderId;
}


public void setOrderId(final String orderId)
{
this.orderId = orderId;
}


public String getStatusCode()
{
return statusCode;
}


public void setStatusCode(final String statusCode)
{
this.statusCode = statusCode;
}
}


Is this enough to Unmarshall the post body into the MerchantOrder object while getting to the updateOrderStatus method ? if yes - how does it happen ? or I need to add jackson annotations in the MerchantOrder class ?

Thank you

Answer

Default is JSON serialization. So your example should work without any additional metadata.