json4s中`render`的目的 [英] Purpose of `render` in json4s

查看:167
本文介绍了json4s中`render`的目的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在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方法的具体实现之一,您可以在

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,这是compactpretty方法的条目类型.

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`的目的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆