API RESTを使用してデータを取得し、JTextAreaに表示するプログラムがあります。すべてはOKですが、私はデシリアライズでこのプログラムを修正する必要があります。 APIからクラスCountryに渡したデータを非直列化して表示する必要があります。私が試みたが、得たエラー:クラスにデータを逆直列化する
public void actionPerformed(ActionEvent evt) {
/*ObjectMapper mapper = new ObjectMapper();
String userDataJSON = "{\"nativeName\":\"latitude\",\"longitude\"}";
mapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true);
try {
Country[] userFromJSON = mapper.readValue(userDataJSON, Country[].class);
System.out.println(userFromJSON);
} catch (IOException e1) {
System.out.println(e1);
}*/
...
textField.selectAll();
textArea.setCaretPosition(textArea.getDocument().getLength());
}
} catch (Exception e) {
}
}
}
そして、私のクラス国名:
public class Country {
@JsonProperty
private String name;
@JsonProperty
public String nativeName;
@JsonProperty
private String latitude;
@JsonProperty
private String longitude;
@JsonProperty
private String currencyCode;
public Country(String name, String nativeName, String latitude, String longitude, String currencyCode) {
super();
this.name = name;
this.nativeName = nativeName;
this.latitude = latitude;
this.longitude = longitude;
this.currencyCode = currencyCode;
// getters & setters
}
** 1 **国オブジェクトをJSONとして**国**配列**に逆シリアル化しようとしています。 –
どうすればいいですか? – Viola
あなたは**ワン**カントリーを望んでいるので、あなたは、あなたが脱直列化の結果としてそれを望むことをジャクソンに伝えるべきです: 'Country = mapper.readValue(userDataJSON、Country.class);' –