我試圖使用序列傑克遜Java中的對象,但是當我試圖序列化,它給了我這個錯誤序列化對象到JSON:無法使用傑克遜
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'?你如何期望傑克遜序列化它? –
傑克遜爲什麼不應該序列化它?當im將對象傳遞給序列化程序時,files字段爲空。 –