【发布时间】:2015-12-10 14:26:56
【问题描述】:
我正在尝试使用 Jackson 序列化 Java 中的对象,但是当我尝试序列化它时,它给了我这个错误:
No serializer found for class java.io.FileDescriptor and no properties discovered to create BeanSerializer
I tried this post, but it didn't help.
这是我要序列化的类:
public class Repository {
public String name;
@JsonIgnore // to avoid recursive calls
public ArrayList<UserRole> contributors = new ArrayList<UserRole>();
public User self;
public ArrayList<FileInfo> files;
public RepositoryType repositoryType;
public String path;
}
我还尝试为每个字段创建 getter/setter,但仍然没有。
这是我的序列化方法:
public static String convertObjectToJson(Object object) throws IOException {
ObjectWriter objectWriter = new ObjectMapper().writer().withDefaultPrettyPrinter();
String json = objectWriter.writeValueAsString(object); //error on this line
return json;
}
【问题讨论】:
-
什么是
FileInfo?你希望Jackson怎么连载它? -
杰克逊为什么不能序列化呢?当我将对象传递给序列化程序时,文件字段为空。
标签: java json serialization jackson