3

I am trying to fetch xml through postman into spring boot rest api. But having a problem while fetching the data from it. How to parse it into spring boot application and get the attributes values. Otherwise, How to fetch xml data by creating pojo class.

Following is the xml file:

<Transmission>
    <TransmissionHeader/>
    <TransmissionBody>
        <GLogXMLElement>
            <TransmissionReport>
                <Name>FUEL</Name>
                <Number>57</Number>
                <Status>PROCESSED</Status>
                <TransmissionSummary>
                    <FirstTransactionNo>1017</FirstTransactionNo>
                    <LastTransactionNo>1017</LastTransactionNo>
                </TransmissionSummary>
            </TransmissionReport>
        </GLogXMLElement>
    </TransmissionBody>
</Transmission>

Thanks in advance.

2
  • 1
    "But having a problem while fetching the data from it"... What kind of problem ? Please provide more information. Commented Jul 21, 2017 at 15:29
  • Hello and welcome to Stack Overflow, please take a time to go through the welcome tour to know your way around here (and also to earn your first badge), read how to create a minimal reproducible example example and also check How to Ask so you increase your chances to get feedback and useful answers. Commented Jul 21, 2017 at 19:18

1 Answer 1

1

In Spring boot, to get the request body -

@RequestMapping(method = RequestMethod.POST)
void testEndPoint(@PathVariable String param, @RequestBody String xml) {
//do stuff
}

See below for details -

Spring Boot Guide

@RequestBody

In order to convert it to POJO, you could explore using Xstream - XStream Tutorial

Define your POJOs and you can simply do -

POJO pojo = (POJO)xstream.fromXML(xml);
Sign up to request clarification or add additional context in comments.

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.