python中杰克逊的替代品是什么? [英] What is the alternative of Jackson in python?

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

问题描述

我正在使用 Jackson 解析器 将 Java 对象解析为 JSON.我正在使用以下代码为某些 java 对象强制添加 JSON 键.

I am using Jackson parser for parsing for Java object to JSON. I am forcefully adding JSON keys for some java objects, using the following code.

@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.WRAPPER_OBJECT)
@JsonSubTypes({ @JsonSubTypes.Type(value = A.class, name = "a"),
        @JsonSubTypes.Type(value = F.class, name = "f") })

我在 Python 中也有相同的集合类.我想在 python 中做同样的事情.但不确定 Python 中可用的 Jackson 注释有哪些替代方案.

I am having same set classes in Python also. I would like to do the same thing in python. But not sure about what are the alternatives for this Jackson annotation available in python.

我的要求是我必须向 REST API 发送 POST 请求.我需要将 java 对象序列化为 JSON.但是由于我的类结构有点不同,我没有在 Java 类中提到的所有 JSON 键.为了解决这个问题,我正在做的是,当它发现A"对象是从 java 传递的时,我在 JSON 中添加a"键.它对F"对象做同样的事情.所以,我已经按照我上面提到的方式实现了解决方案.我想在 Python 中实现同样的功能.

My requirement is that I have to send a POST request to a REST API. I need to serialize the java object into JSON. But as my class structure is a little bit different I don't have all the JSON keys mentioned handy in java classes. To solve the issue what I am doing is that I am adding 'a' key in JSON when it finds 'A' object is passed from java. It is doing the same thing for 'F' object. So, I have achieved the solution the way I mentioned above. I want to achieve the same thing in Python.

是否有一些可用的 JSON 解析器与上面提到的相同,或者我必须遵循一些不同的方法?

Is there some JSON parser available what does the same thing as mentioned above, or I have to follow some different approach for that?

推荐答案

我有同样的问题,找不到合适的.所以我写了pyson

I have the same problem and could not find anything suitable. So I wrote pyson

https://tracinsy.ewi.tudelft.nl/pubtrac/Utilities/wiki/pyson

它仍在开发中,我会在此过程中添加新功能.杰克逊是巨大的,因此不能完全替代杰克逊.我只是在可能的情况下以杰克逊风格实现我需要的东西.

It's still under development and I will add new features along the way. It's not ment to be a complete substitute for jackson as jackson is huge. I just implement what I need, in jackson style where possible.

这篇关于python中杰克逊的替代品是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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