java


Set a Value for JAXBElement<String>


I have a generated class that looks like below. I need to call setAmount() from a POJO, but I don't know what value to pass for the arg. It takes type JAXBElement, and I haven't found a way to instantiate that.
I have an ObjectFactory, but it only creates the class CardRequest.
Can anyone suggest a way?
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "", propOrder = {
"amount",
})
#XmlRootElement(name = "card-request")
public class CardRequest {
#XmlElementRef(name = "amount", namespace = "http://mycompany/services", type = JAXBElement.class)
protected JAXBElement<String> amount;
public JAXBElement<String> getAmount() {
return amount;
}
public void setAmount(JAXBElement<String> value) {
this.amount = ((JAXBElement<String> ) value);
}
}
You can do the following:
JAXBElement<String> jaxbElement =
new JAXBElement(new QName("http://mycompany/services", "amount"), String.class, "Hello World");
There should also be a create method on the generated ObjectFactory class that will create this instance of JAXBElement with the appropriate info for you.
ObjectFactory objectFactory = new ObjectFactory();
JAXBElement<String> jaxbElement = objectFactory.createAmount("Hello World");
UPDATE
If the element definition is nested within your schema the name of the create method might be longer such as createCardRequestAmount().

Related Links

Java Regex Matching Forward Slash and Word
Spring-boot form post large data taking long to enter filter
Java DataStreams and Sockets
Taking input through console Java
Search through ArrayList for value then copy value & key to new TreeSet
JTable doesn't display data by using click button
Threaded factorial performane in Java
Upgraded from Maven to Gradle, now my webapp returning 404 for main logon page
java.lang.ClassFormatError: JVMCFRE074 no Code attribute specified; class=javax/ejb/RemoveException, method=<init>()V, pc=0
#Transactional Method Calling - should we pass objects as parameters?
HttpURLConnection: Already connected after redirect
How do I change the KeyFrame duration of my timer when user clicks a button?
Java - Reading a line from a file containing text and number
How to interleave Java 8 Stream? Like Collectors.joining() but for things other than Strings
how to limit tests time execution from build xml file
Maven Shade Plugin - NoClassDefFound

Categories

HOME
twitter
variables
bluetooth
clips
cookies
keras
smarty
hashmap
maven-3
malloc
jgroups
jxls
cross-browser
mvvmcross
networkx
android-youtube-api
vifm
collectd
zebra-printers
pugjs
scichart
xlsxwriter
sox
captiveportal
microsoft-r
crystal-reports-2010
emgucv
semantic-analysis
elasticsearch-ruby
gitignore
pdb
http-get
typed.js
commit
avcapturesession
subset-sum
google-api-nodejs-client
bower-install
stacked
multilingual
hockeyapp
android-browser
ssjs
eigenvalue
isbn
http-redirect
scorm
komodoedit
python-webbrowser
domain-model
return-value
brightcove
colorama
setter
composite-key
nodebb
akka-cluster
pearson
spring-mongodb
objective-c-swift-bridge
word-vba-mac
heidisql
slicknav
file-writing
mathematica-frontend
contact-list
bgp
rhino-servicebus
freelancer.com-api
ford-fulkerson
r-tree
sdhc
endeca-workbench
wordml
varargs
sonarqube5.1.2
android-imagebutton
id3v2
preferences
terminfo
contenttype
rebol3
mysql-error-1062
kgdb
undefined-reference
jboss-weld
balanced-payments
spring-io
listings
blending
excel-2003
django-nonrel
android-screen-support
drools-planner
free-variable
mhtml
nsnetservice
frameset
multipage
cascalog
online-compilation
netdna-api
gnustep
heartbeat
rfc1123
self-extracting
table-footer
remember-me
site.master
.nettiers
gin
audio-capture
text-coloring
grid-system

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App