使用JacksonFactory将对象转换为String

时间:2018-08-10 07:35:49

标签: android jackson2

我正在使用app.use('/static', express.static('public'),并想将JacksonFactory转换为object

这是我正在使用的代码,但无法正常工作。

InformerItem

String

StorageInformer

 public class InformerItem {

    private String filePath;
    private String fileName;

    // getter setter
}

ConvertObjectIntoString

public class StorageInformer {

    private List<InformerItem> informerItems;

    // getter setter constructor etc
}

没有错误,但是没有正确地将对象转换为字符串。

注意:我不想使用 InformerItem infoItem = new InformerItem("name of file", "path of file"); InformerItem infoItem2 = new InformerItem("second name", "second path"); List<InformerItem> informerList = new ArrayList(); informerList.add(infoItem); informerList.add(infoItem2); StorageInformer storageInformer = new StorageInformer(); storageInformer.setInformerList(informerList); JacksonFactory jacksonFactory = new JacksonFactory(); String storageInformerString = jacksonFactory.toString(storageInformer.getInformerItems().get(0)); String objectInString = jacksonFactory.toString(storageInformer); String anotherString = JacksonFactory.getDefaultInstance().toString(storageInformer); String prettyString = jacksonFactory.toPrettyString(storageInformer); // all these methods are returning {} or [{}] some kind of this.

请让我知道这里出了什么问题

0 个答案:

没有答案