我收到一个大的 json 文档,我只想将其中的一部分解析到我的 java 类中。我正在考虑使用像 jsonpath 这样的东西从中提取部分数据,而不是创建 java 类的整个层次结构。
Jackson 或 Gson 是否以任何方式支持 jsonpath ?如果是,您能为我提供一些示例或指出用于此目的的另一个标准库吗?
例如,假设我有一个以下文档,并且我只想在我的 java 类中从中提取以下数据:
$.store.book[0] - 只有第一本书
$.store.bicycle.price - 自行车的价格
{
"store": {
"book": [
{
"category": "reference",
"author": "Nigel Rees",
"title": "Sayings of the Century",
"price": 8.95
},
{
"category": "fiction",
"author": "Evelyn Waugh",
"title": "Sword of Honour",
"price": 12.99
},
{
"category": "fiction",
"author": "Herman Melville",
"title": "Moby Dick",
"isbn": "0-553-21311-3",
"price": 8.99
},
{
"category": "fiction",
"author": "J. R. R. Tolkien",
"title": "The Lord of the Rings",
"isbn": "0-395-19395-8",
"price": 22.99
}
],
"bicycle": {
"color": "red",
"price": 19.95
}
},
"expensive": 10
}