0

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;
6
  • Can you add your ReportArguments class? Commented Sep 21, 2022 at 14:39
  • Updated the question with the class Commented Sep 21, 2022 at 14:41
  • Have you tried simply using byte[] report(@RequestBody ReportArguments reportArguments) directly? Commented Sep 21, 2022 at 14:59
  • 1
    Wait, you're receiving strictly this: {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. Commented Sep 21, 2022 at 15:02
  • Correct , This is coming as a plain text . i believe that is the problem here . How i can convert it to json string Commented Sep 21, 2022 at 15:03

1 Answer 1

0

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

Sign up to request clarification or add additional context in comments.

1 Comment

I think the problem is with the plain string to json string conversion. I updated the question with my class as well . The class have getters and setters

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.