API响应JSON转换为Java中的类对象

huangapple go评论67阅读模式
英文:

API Response JSON to Class Object in Java

问题

我从Azure API获取了一个JSON格式的服务响应,但我需要将它转换为Java类对象格式。请建议最简单的转换方法。

英文:

I am getting a service response from Azure API in JSON format, but I need to transform it into Java class object format. Please suggest the simplest way to transform

答案1

得分: 0

以下是翻译好的内容:

有一个网站,您可以在该网站上放置 JSON 响应并选择要创建类的语言。
这是最简单的转换方式 -

https://app.quicktype.io/

英文:

There is website on which you can put json response and select the language in which you want to create classes.
This is simplest way to transform -

https://app.quicktype.io/

答案2

得分: 0

你可以使用 com.fasterxml.jackson.databind.ObjectMapper

示例:

ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

UserType user = mapper.readValue("your_Json", UserType.class);
英文:

You can use com.fasterxml.jackson.databind.ObjectMapper

Exemple :

        ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

        UserType user= mapper.readValue("your_Json", UserType.class);

huangapple
  • 本文由 发表于 2020年10月1日 22:23:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/64157395.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定