Tôi đang sử dụng Gson để tạo debug ouput trong ứng dụng của tôibãi đối tượng String với Jackson
Gson gson = new GsonBuilder().setPrettyPrinting().serializeNulls().create();
gson.toJson(myObject);
Nhưng Gson không phàn nàn về một lỗi tham chiếu vòng tròn khi cố gắng serialize một cấu trúc dữ liệu. Điều này có thể được thực hiện với thư viện Jackson không?
UPD Gson 2.3.1: Phát hành Tháng Mười Một 20, 2014
Added support to serialize objects with self-referential fields. The self-referential field is set to null in JSON. Previous version of Gson threw a StackOverflowException on encountering any self-referential fields.
The most visible impact of this is that Gson can now serialize Throwable (Exception and Error)
đối số đầu tiên của configure() phương pháp nên được 'SerializationFeature.FAIL_ON_EMPTY_BEANS' hiện . Phương thức serialize() của bạn phải có 'throws JsonProcessingException' hoặc try/catch block – kiedysktos