简体   繁体   中英

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

您必须在请求中指定Accept Header。

Accept: application/json

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM