I am trying to write a java client for Restful web service implemented using WCF & NTLM Authentication.
我正在为使用WCF和NTLM认证实现的Restful web服务编写一个java客户机。
I am able to use Apache HTTPClient library to connect and retrieve the data.
我可以使用Apache HTTPClient库来连接和检索数据。
The following code gives me the response in the JSon text form.
下面的代码以JSon文本形式给出了响应。
DefaultHttpClient httpClient = new DefaultHttpClient();
httpClient.getCredentialsProvider().setCredentials(new AuthScope(hostName, 443), new NTCredentials(userName, password, hostName, domainName));
httpclient.getAuthSchemes().register("ntlm", new NTLMSchemeFactory());
HttpConnectionParams.setConnectionTimeout(httpclient.getParams(), 150000);
HttpGet httpget = new HttpGet(url);
httpget.setHeader("Content-Type", "application/json");
HttpResponse response = httpclient.execute(httpget);
HttpEntity responseEntity = response.getEntity();
content = EntityUtils.toString(responseEntity);
Now i am writing JSon parser to convert the JSon text into business objects(Manually created classes).
现在我正在编写JSon解析器,将JSon文本转换为业务对象(手工创建的类)。
Does anyone knows how to automate the business object class creation and automated response parser to convert Json text to java object as we consume SOAP based Web Services using frameworks like Axis/CXF?
当我们使用Axis/CXF等框架使用基于SOAP的Web服务时,有人知道如何自动创建业务对象类和自动响应解析器,将Json文本转换为java对象吗?
1 个解决方案
#1
1
There are several options for automatically converting JSON data to Java objects. Some options are:
有几个选项可以自动将JSON数据转换为Java对象。一些选项:
- Jackson - Annotate Java classes and fields to link them to the JSON schema.
- Jackson -注释Java类和字段,将它们链接到JSON模式。
- Google GSON - Can create simple toJson() and fromJson() methods to convert Java objects to JSON and vice-versa. Works with existing classes without modifying source code.
- 谷歌GSON -可以创建简单的toJson()和fromJson()方法来将Java对象转换为JSON,反之亦然。使用现有的类而不修改源代码。
- JSON.org - Doesn't map the JSON directly to your Java classes, but provides parsing into JSONObject and JSONArray classes to make it simple work with JSON.
- JSON.org—没有将JSON直接映射到Java类,但是提供了对JSONObject和JSONArray类的解析,使其与JSON一起工作变得简单。
More answers can be found in this question: How to parse JSON in Java
在这个问题中可以找到更多的答案:如何在Java中解析JSON
EDIT All of the above require manually creating the Java objects, and then linking them to the JSON representation. If instead you want to automatically create the Java objects that correspond to the C# objects, I don't know of a way to do it automatically, however, the JSONSchema2POJO tool will generate Java POJOs from a sample of JSON, so that might save you some time.
编辑以上所有内容需要手动创建Java对象,然后将它们链接到JSON表示。如果您想要自动创建与c#对象对应的Java对象,我不知道有什么方法可以自动创建,但是,JSONSchema2POJO工具将从JSON示例生成Java pojo,这样可以节省一些时间。
#1
1
There are several options for automatically converting JSON data to Java objects. Some options are:
有几个选项可以自动将JSON数据转换为Java对象。一些选项:
- Jackson - Annotate Java classes and fields to link them to the JSON schema.
- Jackson -注释Java类和字段,将它们链接到JSON模式。
- Google GSON - Can create simple toJson() and fromJson() methods to convert Java objects to JSON and vice-versa. Works with existing classes without modifying source code.
- 谷歌GSON -可以创建简单的toJson()和fromJson()方法来将Java对象转换为JSON,反之亦然。使用现有的类而不修改源代码。
- JSON.org - Doesn't map the JSON directly to your Java classes, but provides parsing into JSONObject and JSONArray classes to make it simple work with JSON.
- JSON.org—没有将JSON直接映射到Java类,但是提供了对JSONObject和JSONArray类的解析,使其与JSON一起工作变得简单。
More answers can be found in this question: How to parse JSON in Java
在这个问题中可以找到更多的答案:如何在Java中解析JSON
EDIT All of the above require manually creating the Java objects, and then linking them to the JSON representation. If instead you want to automatically create the Java objects that correspond to the C# objects, I don't know of a way to do it automatically, however, the JSONSchema2POJO tool will generate Java POJOs from a sample of JSON, so that might save you some time.
编辑以上所有内容需要手动创建Java对象,然后将它们链接到JSON表示。如果您想要自动创建与c#对象对应的Java对象,我不知道有什么方法可以自动创建,但是,JSONSchema2POJO工具将从JSON示例生成Java pojo,这样可以节省一些时间。