你好!
我正在使用 .json 文件,如下所示:
[{
"SourceFile": "videos/KobeAlleyOop.flv",
"ExifTool": {
"ExifToolVersion": 8.22,
"Warning": "Truncated 'mdat' data"
},
"System": {
"FileName": "KobeAlleyOop.flv",
"Directory": "videos",
"FileSize": "4.8 MB",
"FileModifyDate": "2010:06:15 14:57:24+02:00",
"FilePermissions": "rwxr-xr-x"
},
"File": {
"FileType": "MP4",
"MIMEType": "video/mp4"
}]
我用 3 个组件制作了一个 Bean:
public class MetadataContentBean {
SourceFileBean sourceFileBean;
FileBean fileBean;
SystemBean systemBean;
public FileBean getFileBean() { return fileBean; }
@JsonProperty("File")
public void setFileBean(FileBean fileBean) {
this.fileBean = fileBean; }
public SystemBean getSystemBean() {
return systemBean; }
@JsonProperty("System")
public void setSystemBean(SystemBean systemBean) {
this.systemBean = systemBean; }
public SourceFileBean
getSourceFileBean() {
sourceFileBean.getSource(); return
sourceFileBean; }
@JsonProperty("SourceFile")
public void setSourceFileBean(SourceFileBean
sourceFileBean) {
this.sourceFileBean = sourceFileBean;
} }
我添加了一个 SourceFileBean 的示例,其他类似:
public class SourceFileBean {
private String source;
public String getSource() {
return source;
}
@JsonProperty("SourceFile")
public void setSource(String source) {
this.source = source;
}
}
在主程序中,我进行了以下调用:
InputStream is = this.getClass().getClassLoader().getResourceAsStream(filename);
String jsonTxt = IOUtils.toString(is);
JSONArray json = (JSONArray) JSONSerializer.toJSON(jsonTxt);
JSONObject metadatacontent = json.getJSONObject(0);
ObjectMapper mapper = new ObjectMapper(); mapper.readValue(metadatacontent.toString(),MetadataContentBean.class);
但是当我运行它时出现此错误,我不知道为什么:
org.codehaus.jackson.map.JsonMappingException:无法构造 com.path.bean.SourceFileBean 的实例,问题:在 [Source: java.io.StringReader@12d7a10; 找不到合适的创建者方法;line: 1, column: 2] at org.codehaus.jackson.map.JsonMappingException.from(JsonMappingException.java:159) at org.codehaus.jackson.map.deser.StdDeserializationContext.instantiationException(StdDeserializationContext.java:212) at org .codehaus.jackson.map.deser.BeanDeserializer.deserializeFromString(BeanDeserializer.java:415) at org.codehaus.jackson.map.deser.BeanDeserializer.deserialize(BeanDeserializer.java:291) at org.codehaus.jackson.map.deser .SettableBeanProperty.deserialize(SettableBeanProperty.java:135) 在 org.codehaus.jackson.map.deser.SettableBeanProperty$MethodProperty.deserializeAndSet(SettableBeanProperty.java:
有什么帮助吗??提前致谢!