简体   繁体   English

如何实例化 JAXBElement<String> 目的?

[英]How do I instantiate a JAXBElement<String> object?

I need to create one of these as the interface requires it.我需要创建其中之一,因为界面需要它。 Can someone please let me know how to create one, as there doesn't seem to be a c'tor defined?有人可以让我知道如何创建一个,因为似乎没有定义 c'tor 吗?

When you imported the WSDL, you should have an ObjectFactory class which should have bunch of methods for creating various input parameters.当你导入 WSDL 时,你应该有一个ObjectFactory类,它应该有一堆方法来创建各种输入参数。

ObjectFactory factory = new ObjectFactory();
JAXBElement<String> createMessageDescription = factory.createMessageDescription("description");
message.setDescription(createMessageDescription);
ObjectFactory fact = new ObjectFactory();   
JAXBElement<String> str = fact.createCompositeTypeStringValue("vik");    
comp.setStringValue(str);
CompositeType retcomp = service.getDataUsingDataContract(comp);
System.out.println(retcomp.getStringValue().getValue());

Here is how I do it.这是我如何做到的。 You will need to get the namespace URL and the element name from your generated code.您需要从生成的代码中获取命名空间 URL 和元素名称。

new JAXBElement(new QName("http://www.novell.com/role/service","userDN"),
                new String("").getClass(),testDN);

Other alternative:其他选择:

JAXBElement<String> element = new JAXBElement<>(new QName("Your localPart"),
                                                String.class, "Your message");

Then:然后:

System.out.println(element.getValue()); // Result: Your message

I don't know why you think there's no constructor.我不知道你为什么认为没有构造函数。 See the API .请参阅API

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM