Exception while Converting String to Json - no String-argument constructor/factory method to deserialize from String value

Viewed 29

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;
1 Answers

Have you included getter/setter method for ReportArguments. Object mapper will serialize/deserialize based on getter/setter method.

Related