json4s中`render`的目的

编程入门 行业动态 更新时间:2024-10-18 05:54:54
本文介绍了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方法的具体实现之一,您可以在 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`的目的

本文发布于:2023-07-14 14:43:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1105086.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:目的   json4s   render

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!