0

Say I have:

ReportExecution executionRequestBody = new ReportExecution(); 

I need something to parse the instance in a way that it would be parsed in JSON format but having textual outlook.

String b = JacksonParserParse(executionRequestBody);

Where I would be able to do something like:

logger.info(b);

Output:

{"reportUnitUri": "/path/to/report",
"async": "true",
"freshData": "false",
"saveDataSnapshot": "false",
"outputFormat": "html",
"interactive": "true",
"ignorePagination": "false",
"pages": "1-5"
}

The ultimate task is to simply insert this String into HTTP request body in Spring RestTemplate HttpEntity. So if there is less thorny way I am more than happy to hear alternative.

Now I can do simple mapping but that usually results in .json file in the filesystem which I do not really know how to plug into my HttpEntity.

2 Answers 2

1

What you want to do is integration RestTemplate with Jackson. This can easily be done and is described in this SO question.

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

2 Comments

@Aubergine Happy to hear it :)!
Though this automatic object mapping, cant work with nested json values quite well or either i cant find suitable data structure - list of list of map rofl, my next question tomorrow.
1

You could do this easily using ObjectMapper from Jackson

ObjectMapper mapper = new ObjectMapper();
ReportExecution executionRequestBody = new ReportExecution(); 
String b = mapper.writeValueAsString(executionRequestBody);
System.out.println(b);

Comments

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.