cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

OCC Webservice V2 - unable to convert JSON request to Java Object

former_member686625
Participant
1,130

Hi,

I have created one controller in version 2 which will take JSON as request.

@RequestMapping(value = "/trackStatus", method = RequestMethod.POST, consumes = "application/json")
    @ResponseStatus(value = HttpStatus.OK)
    public @ResponseBody ConsignmentTrackData updateConsignment(@RequestBody(required=false) ConsignmentTrackData json) {

In JSON I have key like "tracking_number" and in POJO I have variable "trackingNumber" for it.

Tried:

import com.google.gson.annotations.SerializedName;

@SerializedName("tracking_number")
private String trackingNumber;

as well as

import com.fasterxml.jackson.annotation.JsonProperty;

@JsonProperty("tracking_number")
private String trackingNumber;

I have tried this in my separate java program and used it in other DTOs also within Hybris but here in this controller it does not seems to be working.

json.getTrackingNumber() gives me null. Value is not getting populated in it.

Thank you.

Accepted Solutions (0)

Answers (1)

Answers (1)

0 Likes

You have to map your attributes of dto with POJO in dto-mappings-v2-springs.xml.

former_member686625
Participant
0 Likes

I checked it before and i can see that i need to create one more dto with attribute having underscore in it. But do we have any way where i don't need to create new dto.