2

I have to initialize an element of type JAXBElement <String>, I have tried as follows:

JAXBElement<String> element = new JAXBElement<>(new QName("http://tempuri.org/", "FieldName"), String.class, "FieldData");

But I am not sure if it is the correct way. Can someone confirm if there is another easier way?

jbuddy
  • 180
  • 4
  • 14
Despotars
  • 541
  • 1
  • 8
  • 23

1 Answers1

1

What you posted is the simplest way of initializing a JAXBElement element that I know of - a correct one.

The two constructors are:

JAXBElement(QName name, Class<T> declaredType, Class scope, T value)

and (the simplest one, the one you used)

JAXBElement(QName name, Class<T> declaredType, T value)


Also, keep in mind that if by Simple you mean, you don't need to initialize the object with the scope (3rd argument of the first constructor), then your code should be fine.

Edit:

The only questionable thing I see is the "FieldName" (2nd argument provided to the QName constructor) - I'm not what it represents for you, but this should be the local part of the QName. For more info about this see

public QName(String namespaceURI, String localPart)

jbuddy
  • 180
  • 4
  • 14
  • That should do it. When you call the SOAP service, what's the result? – jbuddy Aug 11 '20 at 10:46
  • Sorry, I deleted my comment by mistake. My problem is that I can't make the call from my spring boot project. With this question I try to understand if this part is correct – Despotars Aug 11 '20 at 10:48
  • It would help if you say specifically what's failing. What do you mean exactly with _"I can't make the call from my spring boot project"_? – jbuddy Aug 11 '20 at 10:52
  • I have created this question: https://stackoverflow.com/questions/63356692/consume-a-soap-webservice-with-wsdl-spring-boot-2 to check if someone can help me solve my problems with the connection to my SOAP webservice (from visual basic the connection is very easy, but from java spring boot it is very difficult! – Despotars Aug 11 '20 at 10:54
  • Could you read my new question? There I have my code and my error – Despotars Aug 11 '20 at 12:13