MismatchedInputExceptionを取得しています。ここで多くの質問を検索しましたが、主にJSONMappingExceptionが見つかりました。彼らが同じか違うか分かりません。com.fasterxml.jackson.databind.exc.MismatchedInputException:START_ARRAYトークンからオブジェクトのインスタンスを逆シリアル化できません。
@Entity
@Table
@NamedQueries({
@NamedQuery(name="User.findAll", query="SELECT u FROM User u"),
@NamedQuery(name="User.findByEmail", query="SELECT u FROM User u WHERE u.email=:pEmail")
})
public class User {
@Id
@GenericGenerator(name = "idGenerator", strategy = "uuid2")
@GeneratedValue(generator = "idGenerator")
private String id;
private String firstName;
private String lastName;
@Column(unique=true)
private String username;
@Column(unique=true)
private String email;
private String password;
private String role;
}
の場所にあるすべてのゲッターとセッターを持つ:
後
は、エンティティです。私が使用依存関係は次のとおり@Override
public User findByEmail(String email) {
TypedQuery<User> query = em.createNamedQuery("User.findByEmail", User.class);
query.setParameter("pEmail", email);
List<User> users = query.getResultList();
if(users != null && users.size()==1){
return users.get(0);
}
return null;
}
@Override
public User create(User user) {
em.persist(user);
return user;
}
:リポジトリ
@Override
@Transactional
public User create(User user) {
User existing = repository.findByEmail(user.getEmail());
if(existing == null){
repository.create(user);
}
return user;
}
以下の通りである:
@RequestMapping(method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
public User create(@RequestBody User user) {
return service.create(user);
}
後のサービスである:後
はコントローラマッピング関数である
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.0.pr2</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.2.9.Final</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>6.0.6</version>
</dependency>
私はPostmanを通じてテストしていますが、まだフロントエンドを作成していません。最後に、以下の
[{
"firstName": "hgf",
"lastName": "frew",
"username": "erf",
"email": "bgghjk",
"password": "bgte",
"role": "trrere"
}
]
コンソールログさ:
Thu May 11 13:56:43 CDT 2017 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
May 11, 2017 1:57:52 PM org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver handleHttpMessageNotReadable
WARNING: Failed to read HTTP message: org.springframework.http.converter.HttpMessageNotReadableException: Could not read document: Can not deserialize instance of priyanka.movieflix.entity.User out of START_ARRAY token
at [Source: (PushbackInputStream); line: 1, column: 1]; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Can not deserialize instance of priyanka.movieflix.entity.User out of START_ARRAY token
at [Source: (PushbackInputStream); line: 1, column: 1]
私はこの例外を発生させているかわからないです以下の私が送りますJSONです。アプリケーションを起動すると、データベースにテーブルが正しく作成されており、GETリクエストでもデータが正しく取得されています。
ねえとして
User
オブジェクトのコレクションを受け取るために、コントローラのマッピングを変更する必要があります。ありがとう。 –