I want to disable HAL format by default.
Flow the document, I set this property.
spring.hateoas.use-hal-as-default-json-media-type=false
Then test it:
1. Request with header Accept: application/json
.
Header: Content-Type: application/json;charset=UTF-8
Response:
{
"links": {}
}
2. Request with header Accept: */*
or without Accept
header.
Header: Content-Type: application/hal+json;charset=UTF-8
Response:
{
"_embedded": {},
"_links": {}
}
The version of spring-boot
is 1.5.3, and I use spring-boot-starter-hateoas
.
Is anyway let hateoas to response json without HAL when no header specified?
Thanks a lot.
Update:
Here is a example base on the guide from spring.io.
Requests at: http://localhost:8080/greeting
Requests with header Accept: */*
.
HTTP/1.1 200
Content-Type: application/hal+json;charset=UTF-8
{
"content":"Hello, World!",
"_links":{
"self":{
"href":"http://localhost:8080/greeting?name=World"
}
}
}
Requests with header Accept: application/json
.
HTTP/1.1 200
Content-Type: application/json;charset=UTF-8
{
"content":"Hello, World!",
"_links":{
"self":{
"href":"http://localhost:8080/greeting?name=World"
}
}
}
I don't want HAL by default, so I add a config file resources/application.properties
to the project.
spring.hateoas.use-hal-as-default-json-media-type=false
And test again.
Requests with header Accept: */*
.
HTTP/1.1 200
Content-Type: application/hal+json;charset=UTF-8
{
"content":"Hello, World!",
"_links":{
"self":{
"href":"http://localhost:8080/greeting?name=World"
}
}
}
Requests with header Accept: application/json
.
HTTP/1.1 200
Content-Type: application/json;charset=UTF-8
{
"content":"Hello, World!",
"links":[
{
"rel":"self",
"href":"http://localhost:8080/greeting?name=World"
}
]
}