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

The Android libstreaming is broadcasting audio without video to server?
Which Exception is thrown when a website is down?
A local variable can't be used inside an inner class. So why does this code work?
When setOnClickListener of button execute at the 2 time
How to make a docx file, requires some custom plugin when opened
How to use HK2 DI framkework with Jersey 2?
Oracle Data can not set Time on gregorian calendar
Voice Command in OK Google to Control App
How to use getText() method on a textarea and write to txt file as it appears in textarea?
How to convert string to array (int and string array).?
Lazily recurse Java 8 stream
How to start DUKPT encryption & decryption in Java/Android? [duplicate]
Is defining variables for every condition is better then using getter and setters?
XSL: Why I always get unreadable Spanish characters in HTML
Android Studio edit_Text
log4j:WARN No appenders could be found for logger (org.apache.http.impl.conn.SingleClientConnManager)

Categories

HOME
maven
yii2
winforms
netsuite
proxy
urbancode
google-api-php-client
smarty
jsp-tags
at-command
yarn
jgroups
pivotal-cloud-foundry
esper
basic
floating-action-button
rascal
collectd
windows-phone-7
openrefine
highlight.js
riot.js
realex-payments-api
tibco-mdm
emgucv
facebook-apps
tasklet
http-status-code-503
repo
accelerate-framework
y86
fusionpbx
vapor
streamreader
temporary-files
graphenedb
broadcastreceiver
preconditions
ncalc
firebase-admin
android-mediaprojection
.net-4.6.2
angular2-meteor
revapi
rails-routing
datastax-startup
lowpass-filter
tactic
pg-dump
sqlbulkcopy
pdfclown
flutterwave
topbeat
google-cdn
xcb
android-textview
py2app
django-debug-toolbar
oauth2client
ptrace
two-factor-authentication
srand
endeca-workbench
muse
ibaction
responsive-images
ios9.1
graph-drawing
composite
facebook-graph-api-v2.4
oxwall
jscript.net
mdt
code-access-security
onactivityresult
google-reader
responsive-slides
android-2.2-froyo
page-layout
ccss
sitemesh
tws
drools-planner
tinn-r
e4x
gil
bluepill
manchester-syntax
tridion-worldserver
transactionscope
gnustep
genshi
xmlspy
xtype
iphone-web-app
gamequery
mozilla-prism
nhibernate.search
forums
signal-handling

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App