ここには、Javaオブジェクトリストとして変換したい文字列のJSON
があります。JSON文字列をJavaオブジェクトリストに変換中にトークンエラーが認識されない
String manuallyVerificationRemarks = "[{
"logedInUserName": "forum-admin",
"actionDate": null,
"action": null,
"remarksText": "done by admin..."
}, {
"logedInUserName": null,
"actionDate": null,
"action": null,
"remarksText": null
}]";
ここでは、文字列をオブジェクトに変換する方法を示します。
private ObjectMapper objectMapper = new ObjectMapper();
try{
remarksDtoList = objectMapper.readValue(manuallyVerificationRemarks, new TypeReference<List<RemarksDTO>>() {});
} catch (Exception e) {
e.printStackTrace();
}
そしてここでは、ターゲットDTOある
public class RemarksDTO implements Serializable {
/**
* serialVersionUID
*/
private static final long serialVersionUID = 1L;
private String logedInUserName;
private Date actionDate;
private String action;
private String remarksText;
RemarksDTO(){
super();
}
public RemarksDTO(String remarks,String userName){
this.remarksText = remarks;
this.logedInUserName=userName;
}
public RemarksDTO(String userName,Date actionDate,String action,String remarks){
this.logedInUserName =userName;
this.action=action;
this.remarksText = remarks;
this.actionDate = actionDate;
}
public String getLogedInUserName() {
return logedInUserName;
}
public void setLogedInUserName(String logedInUserName) {
this.logedInUserName = logedInUserName;
}
public String getRemarksText() {
return remarksText;
}
public void setRemarksText(String remarksText) {
this.remarksText = remarksText;
}
public RemarksDTO(String remarks){
this.remarksText = remarks;
}
public Date getActionDate() {
return actionDate;
}
public void setActionDate(Date actionDate) {
this.actionDate = actionDate;
}
public String getAction() {
return action;
}
public void setAction(String action) {
this.action = action;
}
@Override
public String toString(){
return "RemarksDTO [logedInUserName=" + logedInUserName + ", remarksText=" + remarksText + "]";
}
}
私は、次のエラーを取得しています:匿名型の宣言がand here is error trace.... com.fasterxml.jackson.databind.JsonMappingException: Unrecognized token 'nul': was expecting 'null', 'true', 'false' or NaN at [Source: [{"logedInUserName":"forum-admin","actionDate":nul l,"action":null,"remarksText":"new simple Test is abused done by admin."},{"logedInUserName":null,"actionDate":null,"action":null,"remarksText":null}]; line: 1, column: 51] at [Source: [{"logedInUserName":"forum-admin","actionDate":nul l,"action":null,"remarksText":"new simple Test is abused done by admin."},{"logedInUserName":null,"actionDate":null,"action":null,"remarksText":null}]; line: 1, column: 35] (through reference chain: java.util.ArrayList[0])
私はoracle jdk 1.8とjackson-databind 2.6.5で上記のコードを試してみました。あなたの環境に関する詳細を提供できますか? –