Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 136 Vote(s) - 3.41 Average
  • 1
  • 2
  • 3
  • 4
  • 5
"Could not find acceptable representation" using spring-boot-starter-web

#11
I had the same exception. The problem was, that I used the annotation

```@RepositoryRestController```

instead of

```@RestController```
Reply

#12
I had this issue when accessing actuator. Putting following configuration class solved the issue:

@Configuration
@EnableWebMvc
public class MediaConverterConfiguration implements WebMvcConfigurer {
@Bean
public MappingJackson2HttpMessageConverter jacksonConverter() {
MappingJackson2HttpMessageConverter mc =
new MappingJackson2HttpMessageConverter();
List<MediaType> supportedMediaTypes =
new ArrayList<>(mc.getSupportedMediaTypes());
supportedMediaTypes
.add(MediaType.valueOf(MediaType.APPLICATION_JSON_VALUE));
supportedMediaTypes.add(
MediaType.valueOf("application/vnd.spring-boot.actuator.v2+json"));
mc.setSupportedMediaTypes(supportedMediaTypes);
return mc;
}

@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
converters.add(jacksonConverter());
}
}
Reply

#13
Had similar issue when one of my controllers was intercepting all requests with empty `@GetMapping`
Reply

#14
**Add below dependency to your `pom.xml`:**

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

Reply

#15
If you are using **Lombok**, make sure it have annotations like **@Data or @Getter
@Setter** in your Response Model class.
Reply

#16
In my case I was sending in correct object in ResponseEntity<>().

Correct :

@PostMapping(value = "/get-customer-details", produces = { MediaType.APPLICATION_JSON_VALUE })
public ResponseEntity<?> getCustomerDetails(@RequestBody String requestMessage) throws JSONException {
JSONObject jsonObject = new JSONObject();
jsonObject.put("customerId", "123");
jsonObject.put("mobileNumber", "XXX-XXX-XXXX");
return new ResponseEntity<>(jsonObject.toString(), HttpStatus.OK);
}

Incorrect :

return new ResponseEntity<>(jsonObject, HttpStatus.OK);

Because, jsonObject's toString() method "Encodes the jsonObject as a compact JSON string". Therefore, Spring returns json string directly without any further serialization.

When we send jsonObject instead, Spring tries to serialize it based on produces method used in RequestMapping and fails due to it "Could not find acceptable representation".
Reply

#17
For me, the problem was trying to pass a filename in a url, with a dot. For example
```java
"http://localhost:8080/something/asdf.jpg" //causes error because of '.jpg'
```

It could be solved by not passing the .jpg extension, or sending it all in a request body.
Reply

#18
I was running into the same issue, and what I was missing in my setup was including this in my maven (pom.xml) file.

<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.9</version>
</dependency>

Reply

#19
Even if you do all of the above, as like in my case I still got the error 406 - Not acceptable when used from postman. Upon careful study, I have noticed that, in the request headers, default header for 'accept' is '*/*'.

I solved my problem, by adding a preset to the header and switched off default header. Please see below screenshot.

[![screenshot of postman preset][1]][1]


[1]:


This solved my problem without any other settings or even adding the spring configurations.
Reply

#20
I got the exact same problem. After viewing this reference:

[To see links please register here]


My problem solved by changing

`method = RequestMethod.GET, produces = "application/json;charset=UTF-8"`

to

`method = RequestMethod.GET, produces = MediaType.TEXT_PLAIN_VALUE`

and don't forget to add the library:

import org.springframework.http.MediaType;

it works on both postman or regular browser.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through