私は、ユーザーを表すために、このクラスを持っている:私は何をしようとしている春ブーツHttpMessageNotReadableException
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
@Getter
@Setter
public class UserDto implements Serializable {
private Long id;
private String username;
private String email;
private String password;
private Collection<? extends GrantedAuthority> roles;
public UserDto() {
}
}
}
はUserDtoに以下のコントローラの春マップ@RequestBodyをさせることです。
public class AuthController {
@Autowired
private UserService userService;
@Autowired
private AuthService authService;
@RequestMapping(value = "signup", method = RequestMethod.POST)
public ResponseEntity<?> addUser(@RequestBody UserDto userDto) throws Exception {
UserDto existingUserDto;
try {
existingUserDto = userService.save(userDto);
} catch (Exception e) {
return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}
return new ResponseEntity<>(existingUserDto, HttpStatus.CREATED);
}
}
しかし、その代わりに、私はPOSTリクエストを送信しようとすると、私は春から次のエラーを取得:
を3210Failed to read HTTP message: org.springframework.http.converter.HttpMessageNotReadableException: Could not read document: Unrecognized token 'username': was expecting ('true', 'false' or 'null')
at [Source: [email protected]; line: 1, column: 10]; nested exception is com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'username': was expecting ('true', 'false' or 'null')
at [Source: [email protected]; line: 1, column: 10]
私は何をしようとしたことは、カスタムMappingJackson2HttpMessageConverterを宣言しましたが、私はここで
@Bean
public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter() {
MappingJackson2HttpMessageConverter jsonConverter = new MappingJackson2HttpMessageConverter();
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
jsonConverter.setObjectMapper(objectMapper);
return jsonConverter;
}
要求された私は、コンテンツタイプで(やっているの画面何が違うの結果を取得できませんでした:アプリケーション/ JSONを):
あなたが任意のアイデアを持っていますか?
リクエスト本体にJSONコンテンツを表示します。 –
JSONではなくフォームデータを送信しています。 '@ RequestBody'を取り除く。これは単純なフォームパラメータでなければなりません。 –
リクエストの画面を追加しました。返信いただきありがとうございます。 – fraccaman