Skip to Content
Java性能权威指南(第2版)
book

Java性能权威指南(第2版)

by Scott Oaks
April 2022
Intermediate to advanced
348 pages
11h 21m
Chinese
Posts & Telecom Press
Content preview from Java性能权威指南(第2版)
254
|
第
10
章
生成简单
JSON
对象比生成自定义
Java
类要快得多,但从编程的角度来看,这些
Java
类
更容易使用。
表
10-2
中的
Jackson
映射器是另一种方法
,在这一点上,它已经远远超过了其他用法。虽
然
Jackson
提供了一个标准的
JSON
处
理(
JSON-P
)
API
的实现,但它还有一个替代实现,
可以将
JSON
数据解码为
Java
对象并将
Java
对象编码为
JSON
数据
,不过它与
JSON-B
不
同。这个实现是建立在
Jackson
提供的
ObjectMapper
类上的。
JSON-B
将数据解码到对象
的代码是这样的:
Jsonb jsonb = JsonbBuilder.create();
FindItemsByKeywordsResponse f =
jsonb.fromJson(inputStream, FindItemsByKeywordsResponse.class);
ObjectMapper
的代码略有不同:
ObjectMapper mapper = new ObjectMapper();
FindItemsByKeywordsResponse f =
mapper.readValue(inputStream, FindItemsByKeywordsResponse.class);
从性能角度来看,
ObjectMapper
的使用有一些缺陷。随着
JSON
数据被解码,
mapper
会
创建很多代理类,它们是用来创建最终
POJO
的
。当一个类第一次被使用时,它本身会
有些耗时。为了解决这个问题,常见的做法是创建大量映射器对象 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Java数据科学实战

Java数据科学实战

Michael R. Brzustowicz, PhD
深入淺出代數

深入淺出代數

Tracey Pilone, Dan Pilone
Go程序设计语言

Go程序设计语言

艾伦A. A.多诺万, 布莱恩W. 柯尼汉
软件开发实践:项目驱动式的Java开发指南

软件开发实践:项目驱动式的Java开发指南

Raoul-Gabriel Urma, Richard Warburton

Publisher Resources

ISBN: 9787115587367