在json4s的示例和文档中,我经常看到惯用法
In json4s examples and documentation I often see the idioms
compact(render(jval))和
pretty(render(jval))我认为我实际上没有见过将紧凑或漂亮的示例直接应用于生成的代码JValue的示例, 但是我不清楚render在这里做什么. 渲染的类型为JValue => JValue,我看不到有什么明显的不同 并运行
I do not think I have actually seen an example with compact or pretty applied directly to a code generated JValue, but it is not clear to me what render is doing here. Render has type JValue => JValue and I do not see any obvious difference it makes and running
json.take(100000).filter(x => compact(render(x)) != compact(x))对我的某些数据返回一个空的空集合.
on some of my data returns an empty an empty collection.
render的实际作用是什么?
What does render actually do?
推荐答案我想您正在研究render方法的具体实现之一,您可以在 JsonMethods trait :
I guess you were looking at one of the concrete implementations of the render method, which definition you can see in the JsonMethods trait:
def render(value: JValue)(implicit formats: Formats = DefaultFormats): T def compact(d: T): String def pretty(d: T): String方法render返回泛型类型T,这是compact和pretty方法的条目类型.
The method render returns a generic type T, which is the entry type for the compact and pretty methods.
根据 native 和 jackson 的口味, json4s 项目中有两种方法render的实现.只是表面上检查了代码,但它们似乎都根据不同的策略过滤了json对象的空元素.假设要准备好使用pretty和/或compact方法了吗?
There are two implementations of the method render in the json4s project, as per the native and jackson flavours... I've checked the code superficially only but they both seem to be filtering the empty elements of the json object according to different strategies. Let's say getting it ready for the pretty and / or compact methods to kick in?
更多推荐
json4s中`render`的目的
发布评论