Convert JSON or Dict to client objects
@roycaihw já está trabalhando nisso.
Desde 8/10/2019.
Avaliação
Esta issue ainda não foi avaliada.
Descrição
See also https://github.com/kubernetes-client/python/issues/340#issuecomment-526249075 (was closed for inactivity, NOT resolved)
See also #63
Motivation
It is sometimes useful to be able to load Python objects from JSON, for example to read it from a config file. It should be possible to get Python objects from JSON, to pass around the code in a type-safe manner, for modification and ultimately sending through the client.
Feature request
There should be functions to convert JSON to objects and objects to JSON. This code already exists (it's required to talk to the API server), it should be exposed.
Workaround?
Right now, you can put this raw JSON into Python objects' fields, and the API client will apparently accept this, however if you use such mixed objects your code will probably break since their attribute names are different (API uses PascalCase, Python objects use snake_case). Even if taking care to handle that, you will reach the point where you have to handle things coming from the API client (Python objects using snake_case) differently from what you load from config files (JSON using PascalCase). Really messy.
Right now I am left considering dropping this lib altogether and issuing requests directly, since the point of the wrapper is to expose safe typed Python classes instead of the raw JSON, but this doesn't work if you use any kind of config file.
Current status
It is somewhat possible to convert from a Python object to JSON using client.api_client.sanitize_for_serialization(), however converting from JSON to Python is completely impossible; the deserialize() method that exists expects a requests.Response, not JSON. Calling client.api_client._ApiClient__deserialize() works, but that is a private method, and you need to pass it the kind read from the JSON yourself.
Apologies for duplicating #340 but I cannot re-open it myself.
- Linguagem predominante
- Python
- Estrelas
- 7.7k
- Forks
- 3.5k
- Merge médio
- 1d 14h
- PRs com merge (30d)
- 18
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de kubernetes-client/python
-
kind/bug
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 68/100
kubernetes-client/python#2280 · 16 comentários · 9 reações ·
-
Release 1.37 Aberta
kubernetes-client/python#2691 · 1 comentário · 1 reação · 1 responsável ·
-
Growing library size Abertahelp wanted
Dificuldade 5/5 Mais de uma semana Facilidade para iniciantes 35/100
kubernetes-client/python#2677 · 13 comentários · 1 reação ·
-
help wanted kind/feature
kubernetes-client/python#2602 · 6 comentários · 1 responsável ·
-
kind/bug
kubernetes-client/python#2596 · 13 comentários · 2 reações · 1 responsável ·
Todas as issues de kubernetes-client/python
Issues semelhantes
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 86/100
browser-use/browser-use#5905 ·
-
type: enhancement
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
ynput/ayon-python-api#363 ·
-
bug needs triage
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 88/100
modelscope/FunASR#3728 ·
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 88/100
open-compass/opencompass#2655 ·