首页 \ 问答 \ Spring-ws客户端编程(Spring-ws client side programming)

Spring-ws客户端编程(Spring-ws client side programming)

我想要使​​用我拥有wsdl的Web服务。 我使用spring-ws并希望使用编组/解组(jaxb)将xml转换为java,反之亦然。 如何从wsdl获取jaxb类。 我是否需要访问xsd,在这种情况下我没有。 我可以使用像trang这样的工具来完成这项工作吗?


I want to consume a web service of which I have the wsdl. I am using spring-ws and want to use marshalling/unmarshalling (jaxb) to convert xml to java and vice versa. How can I get the jaxb classes from the wsdl. Do I need access to xsd which in this case I don't have. Can I use a tool like trang to do the work?


原文:https://stackoverflow.com/questions/6449030
更新时间:2021-06-19 08:06

最满意答案

您可以执行类似的操作,遍历根节点以分别通过嵌套的while循环和for循环获取所需的键字段( '1/1/0'和' 1/1/1' )以及每个对象的数据。

final JsonNode node = parser.parseToNode(configJson); 

for (JsonNode root : node) {

            Iterator<String> itr = root.getFieldNames();
                while (itr.hasNext()) {  //to get the key fields
                String key_field = itr.next();
                }

            for (JsonNode n : node.get("sensors")) {  //to get each object
                final String event = root.get("event").asText();
                final String name = root.get("name").asText();
                final String type = root.get("type").asText();
                final String location = root.get("location").asText();
                }
   }

如果你使用json映射的pojo类在你使用jackson库时执行这些操作会更容易。


You can do something like this, iterate over the root node to get the required key fields ('1/1/0' and '1/1/1') and data for each object through the nested while loop and for-loop respectively.

final JsonNode node = parser.parseToNode(configJson); 

for (JsonNode root : node) {

            Iterator<String> itr = root.getFieldNames();
                while (itr.hasNext()) {  //to get the key fields
                String key_field = itr.next();
                }

            for (JsonNode n : node.get("sensors")) {  //to get each object
                final String event = root.get("event").asText();
                final String name = root.get("name").asText();
                final String type = root.get("type").asText();
                final String location = root.get("location").asText();
                }
   }

It would be easier if you have a pojo class mapped with your json to perform these operations when you are using jackson library.

相关问答

更多
  • 在Jackson 2.4中,您可以转换如下: MyClass newJsonNode = jsonObjectMapper.treeToValue(someJsonNode, MyClass.class); 其中jsonObjectMapper是Jackson ObjectMapper 。 在老版本的杰克逊,这将是 MyClass newJsonNode = jsonObjectMapper.readValue(someJsonNode, MyClass.class); In Jackson 2.4, ...
  • 检查类型似乎是这样做的唯一方法,好吧它不是很准确,因为你只能检查它是否是一个数字,而不是它是否是双精度数的int。 Checking the type seems to be the only way of doing this, alright it is not very accurate as you can only check if it is a number, but not if it is an int of a double.
  • 您的读写操作不匹配。 在写入端,您使用ObjectOutputStream.writeObject(Object)来编写包含序列化JSON内容的byte[] 。 在读取端ObjectMapper.readValue(InputStream, Class)当您实际需要首先读取byte[]对象时ObjectMapper.readValue(InputStream, Class)尝试使用ObjectMapper.readValue(InputStream, Class)读取流中的原始字节ObjectMapper. ...
  • 答案主要在Jackson文档和教程中 ; 您有几种方法可以将JsonNode转换为有用的数据。 如果事先知道数据的结构,可以使用数据绑定方法:对于“完全”绑定,使一个Class对应于所有字段); 对于结构较少的方法,“原始”绑定允许您使用通用对象。 否则, 树模型方法应该适合您; 您将在链接页面中找到的示例与您的用例相对应。 请尝试这个例子,然后如果你有更具体的问题回来与确切的实际或哲学问题! The answer is mostly in the Jackson documentation and the ...
  • elasticsearch中的每个字段都有一个映射,用于描述类型以及如何分析索引。 默认情况下,字段是字符串并进行分析(删除标点符号,单词分隔为令牌等)。 例如,一个名为“path”的字段包含: /var/log/messages 会成为 ["var", "log", "messages"] 这意味着您不能再搜索原始字符串,并且标点符号中的任何含义都已丢失。 这是使用文本引擎处理日志数据的一个副作用。 由于每个logstash用户几乎立即就会遇到这种情况,因此logstash团队创建了一个模板,该模板将 ...
  • JsonNode对象是不可变的,因此您无法修改它们。 你可以做的是用另一个JsonNode替换它。 还需要ObjectNode为ObjectNode以公开所需的方法。 首先找到要替换的节点的父节点: JsonNode node = root.findParent("JsonPath"); 然后使用这两种方法中的任何一种将其替换为新方法: ((ObjectNode) node).remove("JsonPath"); // remove current node ((ObjectNode ...
  • 您可以执行类似的操作,遍历根节点以分别通过嵌套的while循环和for循环获取所需的键字段( '1/1/0'和' 1/1/1' )以及每个对象的数据。 final JsonNode node = parser.parseToNode(configJson); for (JsonNode root : node) { Iterator itr = root.getFieldNames(); while (itr.hasNext()) ...
  • 不确定kryo是否真的能够编写那些JSON节点。 我认为有多种可能的选择: 你留在kryo,但这意味着你应该读取和写入对象作为单独的值,而不是你可以用构造函数参数重新创建JsonNode实例 如果您仍然要写独立值,您可能希望将值直接写入ObjectDataOutput并使用ObjectDataInput读取它 从我的pov开始,最好的方法就是使用Jackson - 你可能想看看CBOR数据格式,它是二进制的,非常简洁并可直接用于Jackson - 此外你不会失去JSON的无模式,动态特性( https:// ...
  • 这个问题的关键在于null的含义。 在有问题的情况下,显然op已被实例化,因此不为null 。 这可以通过在执行验证的构造函数中添加另一个输出行来显示: System.out.println(" class:" + (null == op ? "Real Null" : op.getClass().toString())); 这样,当程序再次运行时,会产生以下输出: Initial value: {"type":"CREATE","op":null} Document value: {"@type" ...
  • Rust的JSON“DOM”由Json枚举定义。 例如,这个JSON对象: { "array": [1, 2, 3], "submap": { "bool": true, "string": "abcde" } } 在Rust中由此表达式表示: macro_rules! tree_map { ($($k:expr -> $v:expr),*) => ({ let mut r = ::std::collections::TreeMap::new(); $(r.inse ...

相关文章

更多

最新问答

更多
  • 如何检索Ember.js模型的所有属性(How to retrieve all properties of an Ember.js model)
  • maven中snapshot快照库和release发布库的区别和作用
  • arraylist中的搜索元素(Search element in arraylist)
  • 从mysli_fetch_array中获取选定的值并输出(Get selected value from mysli_fetch_array and output)
  • Windows Phone上的可用共享扩展(Available Share Extensions on Windows Phone)
  • 如何在命令提示符下将日期设置为文件名(How to set file name as date in command prompt)
  • 如何在Laravel 5.2中使用paginate与关系?(How to use paginate with relationships in Laravel 5.2?)
  • 从iframe访问父页面的id元素(accessing id element of parent page from iframe)
  • linux的常用命令干什么用的
  • Feign Client + Eureka POST请求正文(Feign Client + Eureka POST request body)
  • 怎么删除禁用RHEL/CentOS 7上不需要的服务
  • 为什么Gradle运行测试两次?(Why does Gradle run tests twice?)
  • 由于有四个新控制器,Auth刀片是否有任何变化?(Are there any changes in Auth blades due to four new controllers?)
  • 如何交换返回集中的行?(How to swap rows in a return set?)
  • 在android中的活动之间切换?(Switching between activities in android?)
  • Perforce:如何从Depot到Workspace丢失文件?(Perforce: how to get missing file from Depot to Workspace?)
  • Webform页面避免运行服务器(Webform page avoiding runat server)
  • 在ios 7中的UITableView部分周围绘制边界线(draw borderline around UITableView section in ios 7)
  • 内存布局破解(memory layout hack)
  • 使用Boost.Spirit Qi和Lex时的空白队长(Whitespace skipper when using Boost.Spirit Qi and Lex)
  • 我们可以有一个调度程序,你可以异步添加东西,但会同步按顺序执行吗?(Can we have a dispatcher that you can add things todo asynchronously but will be executed in that order synchronously?)
  • “FROM a,b”和“FROM a FULL OUTER JOIN b”之间有什么区别?(What is the difference between “FROM a, b” and “FROM a FULL OUTER JOIN b”?)
  • Java中的不可变类(Immutable class in Java)
  • bat批处理文件结果导出到txt
  • WordPress发布查询(WordPress post query)
  • 如何在关系数据库中存储与IPv6兼容的地址(How to store IPv6-compatible address in a relational database)
  • 是否可以检查对象值的条件并返回密钥?(Is it possible to check the condition of a value of an object and JUST return the key?)
  • 德州新起点计算机培训学校主要课程有什么?
  • GEP分段错误LLVM C ++ API(GEP segmentation fault LLVM C++ API)
  • “latin1_german1_ci”整理来自哪里?(Where is “latin1_german1_ci” collation coming from?)