简体   繁体   English

杰克逊ObjectMapper.readValue()

[英]Jackson ObjectMapper.readValue()

I am reading a List of integers using Jackson as follows: 我正在使用Jackson读取整数列表,如下所示:

List<Integer> businessIds = mapper.readValue(strBusinessIDArrayJSON, new TypeReference<List<Integer>>(){});

The returned list contains a list of businesses displayed in a Grid on my UI. 返回的列表包含在我的UI的网格中显示的业务列表。 I have the following questions: 我有以下问题:

  1. Will the returned list maintain Sequence. 返回的列表是否将保持序列。 In my code, I am populating a variable called businessDisplayPosition with the index of the list. 在我的代码中,我使用列表的索引填充了一个名为businessDisplayPosition的变量。 Is this how its done? 这是怎么做的?

  2. Is there a faster way to parse my JSON? 有没有更快的方法来解析我的JSON?

  1. Yes, of course. 当然是。 Otherwise, an array and a list wouldn't be an array and a list anymore. 否则,数组和列表将不再是数组和列表。 Test it, and see by yourself. 测试一下,然后自己看看。

  2. there's probably a faster way, but it will probably not be as convenient, and the way you're doing it is probably fast enough. 可能有一种更快的方法,但可能不会那么方便,而且您执行该操作的方法可能足够快。 Unless you have millions and millions of IDs in your array, I doubt the user would notice any difference between this solution and a faster one. 除非阵列中有成千上万的ID,否则我怀疑用户会注意到此解决方案与更快的解决方案之间的任何区别。 Premature optimization is the root of all evil. 过早的优化是万恶之源。 Don't try to optimize something that doesn't need to be. 不要尝试优化不需要的东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM