Hi i am trying to make an API call from another legacy application. I cannot add any more dependency in legacy application. The legacy application is trying to make a call to API with request Body as argumentsMap.toString() , here argumentsMap is a HashMap which contains lot of parameters . I cannot add any more dependency in legacy app like ObjectMapper. Currently i am trying to receive it as below.
public byte[] report(@RequestBody String argumentsMapParams) {
ObjectMapper objectMapper = new ObjectMapper();
String jsonFormat = objectMapper.writeValueAsString(stringReportArguments);
ReportArguments reportArguments = objectMapper.readValue(jsonFormat,ReportArguments.class);
}
My aim is to convert the string i am receiving into ReportArguments class. Above code giving me an error like
no String-argument constructor/factory method to deserialize from String value
How i can do it .
The parameter i am receiving will be like , plain text
{fromDate=12, rptSql=select * from property}
This is my ReportArguments Class
@Data
@NoArgsConstructor
@AllArgsConstructor
@ToString
@JsonIgnoreProperties
public class ReportArguments implements Serializable {
@JsonProperty("fromDate")
String fromDate;
@JsonProperty("rptSql")
String rptSql;
byte[] report(@RequestBody ReportArguments reportArguments)directly?{fromDate=12, rptSql=select * from property}? This isn't valid JSON, not is it any known format (to me at least), so I'm afraid you'll have to parse it manually. This data "JSONised" would be{"fromDate": 12, "rptSql": "select * from property"}, which Spring via Jackson/GSON/AnyJsonParser would be able to parse.