为什么我们需要杰克逊数据绑定? [英] Why do we need jackson databind?

查看:65
本文介绍了为什么我们需要杰克逊数据绑定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是JAVA EE的新手.我的问题是,为什么我们需要杰克逊数据绑定?因为我们可以通过@ModelAttribute接收Request Params,并通过@RequestBody通过http PUT或POST请求.我找不到为什么我们需要杰克逊数据绑定将json/xml转换为POJO或反之亦然的原因.

I am new in JAVA EE. My question is, why do we need jackson databind? Because We can receive the Request Params by @ModelAttribute and requests through http PUT or POST by @RequestBody. I can't find a reason why we need jackson databind to convert json/xml to POJO or vice versa.

谢谢.

推荐答案

为什么我们需要杰克逊数据绑定?

Why do we need jackson databind?

因为使用XML(或JSON)表示结构化数据要比使用简单的名称/值对容易得多.

Because representing structured data is much easier using XML (or JSON) than using simple name-value pairs.

因为在执行AJAX时从客户端发送和接收JSON更方便.

Because it is more convenient to send and receive JSON from the client side when you are doing AJAX.

因为一旦您必须在服务器端Java应用程序中处理发送和接收JSON或XML,便可以更方便地将结构化数据作为POJO进行处理.

Because once you have to deal with sending and receiving JSON or XML in the server side Java app, it is more convenient to deal with structured data as POJOs.

以上所有内容均不表示必须使用绑定.还有其他处理上述每个问题的方法.但是许多Java开发人员认为数据绑定是更好的方法:在开发人员时间方面更高效,并且更可靠.尤其是当您使用复杂的API实现服务时.这就是为什么它们很受欢迎.

None of the above points mean you have to use a binding. There are other ways of dealing with each of the above. But many Java developers think that data bindings the better way to go: more efficient in terms of developer time, and more reliable. Especially if you are implementing services with a complex APIs. That's why they are popular.

正如其他答案/评论所指出的那样,如果您使用的是@RequestBody,那么这是在后台使用绑定库为您提供POJO.对于Spring,正在使用的是Jackson.

And as other answers/comments point out, if you are using @RequestBody, then that is using a binding library under the hood to give you the POJOs. In the case of Spring, it is Jackson that is being used.

这篇关于为什么我们需要杰克逊数据绑定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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