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
最满意答案
您可以执行类似的操作,遍历根节点以分别通过嵌套的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.
相关问答
更多-
将JsonNode转换为POJO(Convert JsonNode into POJO)[2022-09-23]
在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.
-
使JsonNode可序列化(Make JsonNode Serializable)[2022-12-22]
您的读写操作不匹配。 在写入端,您使用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 ...
-
ELK中fieldname和fieldname.raw之间的区别?(Difference between fieldname and fieldname.raw in ELK?)[2023-08-22]
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中的JsonNode(JsonNode in JSON in Rust)[2022-03-22]
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 ...