Sam
Sam

Reputation: 1328

Return xml/json based on content type

I am using spring rest to create handle rest api creation in the project . The rest method is annotated with the following.

@GetMapping(value = FETCH_ALL,produces ={MediaType.APPLICATION_XML_VALUE,MediaType.APPLICATION_JSON_VALUE})

I have added the following dependancy to the maven project

        <dependency>
            <groupId>com.fasterxml.jackson.dataformat</groupId>
            <artifactId>jackson-dataformat-xml</artifactId>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
        </dependency>

I am using postman to make test the api and i am passing Content-Type in the header as application/json but it still returns me the xml format.

I am not able to figure out what i have missed in the configuration to return the content the user is requesting for

TIA

Upvotes: 4

Views: 7628

Answers (1)

pvpkiran
pvpkiran

Reputation: 27048

You have to specify Accept Header in your request.

Accept: application/json

Upvotes: 4

Related Questions