I have following case:
Flex class
public class Flex {
private String key;
private String val;
public Flex () {
}
public void setKey(String key) {
this.key = key;
}
public String getKey() {
return key;
}
public void setVal(String val) {
this.val = val;
}
public String getVal() {
return val;
}
FlexManager class
public class FlexManager {
private Map<String, Flex> keyValue = new HashMap<String, Flex>();
public FlexManager () {
populateFlexFieldMap();
}
private void populateFlexFieldMap() {
if (keyValue.isEmpty()) {
List<Flex> fieldds = loadKVFromFile();
for (Flexfield : fieldds) {
keyValue.put(field.getKey(), field);
}
}
}
public void setKeyValue(Map<String, FlexField> keyValue) {
this.keyValue = keyValue;
}
public Map<String, Flex> getKeyValue() {
return keyValue;
}
}
The input with managedBean is ready.
How can I get the val value in Flex class through getKeyValue() method with EL?
My approach is this: ${managedBeanName.keyValue['key'].val}
but I get this warning in my IDE
Reference ${managedBeanName.keyValue['key'].val} not found
You don't need to type get in order to invoke a getter.
${managedBeanName.keyValue['key'].val}
Related
This Is Main Fragment
Fragment:
private void getStock() {
dialog.show();
Retrofit retrofit = RetrofitClient.getRetrofitInstance();
apiInterface api = retrofit.create(apiInterface.class);
Call<List<Blocks>>call = api.getVaccineBlocks();
call.enqueue(new Callback<List<Blocks>>() {
#Override
public void onResponse(Call<List<Blocks>>call, Response<List<Blocks>> response) {
if (response.code() == 200) {
block = response.body();
spinnerada();
dialog.cancel();
}else{
dialog.cancel();
}
}
#Override
public void onFailure(Call<List<Blocks>> call, Throwable t) {
dialog.cancel();
}
});
}
private void spinnerada() {
String[] s = new String[block.size()];
for (int i = 0; i < block.size(); i++) {
s[i] = block.get(i).getBlockName();
final ArrayAdapter a = new ArrayAdapter(getContext(), android.R.layout.simple_spinner_item, s);
a.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
//Setting the ArrayAdapter data on the Spinner
spinner.setAdapter(a);
}
}
This Is Blocks Model
model:
package com.smmtn.book.models;
import java.io.Serializable;
public class Blocks implements Serializable {
public String id;
public String blockName;
public String blockSlug;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getBlockName() {
return blockName;
}
public void setBlockName(String blockName) {
this.blockName = blockName;
}
public String getBlockSlug() {
return blockSlug;
}
public void setBlockSlug(String blockSlug) {
this.blockSlug = blockSlug;
}
}
here i need onitemclick with blockslug please any one can help, am new to android so i need some example.when on click i want take blockslug and load another method with that blockslug,like will get data from u "http://example.com/block/"+blockslug
i want to get blockslug from selected block
i hope guys i will get help
and sorry for my bad English,
First of all, you need to implement setOnItemSelectedListener. Refer to this https://stackoverflow.com/a/20151596/9346054
Once you selected the item, you can call them by making a new method. Example like below
public void onItemSelected(AdapterView<?> parent, View view, int pos,long id) {
Toast.makeText(parent.getContext(),
"OnItemSelectedListener : " + parent.getItemAtPosition(pos).toString(),
Toast.LENGTH_SHORT).show();
final String itemSelected = parent.getItemAtPosition(pos).toString();
showBlockSlug(itemSelected);
}
And then, at the method showBlockSlug() , you can call Retrofit.
private void showBlockSlug(final String blockslug){
final String url = "http://example.com/block/"+ blockslug;
//Do your stuff...
}
I am trying to create my custom configuration object from Map using model mapper. Everything gets mapped properly excepts the fields property which is coming fro Generic super class.
My target object is
public class ADParserConfig extends CustomParserConfig<ADParserConfigField> {
private String pattern;
public String getPattern() {
return pattern;
}
public void setPattern(String pattern) {
this.pattern = pattern;
}
}
This extends generic class CustomParserConfig
public class CustomParserConfig<T extends CustomParserConfigField> {
protected List<T> fields;
protected String timeStampField;
public List<T> getFields() {
return fields;
}
public void setFields(List<T> fields) {
this.fields = fields;
}
public String getTimeStampField() {
return timeStampField;
}
public void setTimeStampField(String timeStampField) {
this.timeStampField = timeStampField;
}
}
Where CustomParserConfigField is
public class CustomParserConfigField {
protected String name;
protected Integer index;
protected String type;
protected String format;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getIndex() {
return index;
}
public void setIndex(Integer index) {
this.index = index;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getFormat() {
return format;
}
public void setFormat(String format) {
this.format = format;
}
}
I am trying to map Map using below function
ADParserConfig adParserConfig = getConfig(map,ADParserConfig.class);
public <T extends CustomParserConfig> T getConfig(Map<String,Object> configObject, Class<T> classType){
ModelMapper modelMapper = new ModelMapper();
return modelMapper.map(configObject,classType);
}
Everything excepts fields gets mapped properly for the below map.
{fields=[{name=timeStamp, type=timestamp, format=dd/mm/yyyy HH:MM:SS a}, {name=logName, type=string}], pattern=(?<timeStamp>\d{2}\/\d{2}\/\d{4}\s\d{2}:\d{2}:\d{2}\s[AMPMampm]{2})?\s(LogName=(?<logName>[\w\s\W]+))?\sSourceName=(?<sourceName>[\w\s\W]+)\sEventCode=(?<eventCode>[0-9]*), timeStampField=timestamp}
Please help. Why is issue happens only for fields object ? Do I need to specify something else in mapper configurations ?
It looks like a bug and it had been fixed by #370
my json data is this
{
"data":[
{
"id":"4",
"totalOpns":"40000",
"killedDrugPer":"320",
"arrestedDrugPer":"17683",
"houseVisited":"4000",
"userSurrenderers":"45000",
"pusherSurrenderers":"15000",
"totalSurrenderers":"60000",
"killedPNPPerOpns":"40",
"woundedPNPPerOpns":"70",
"killedAFPPerOpns":"100",
"woundedAFPPerOpns":"10",
"date":"2017-07-12 13:57:34.000"
}
]
}
and my data model is this
package com.androidtutorialpoint.retrofitandroid;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import java.io.Serializable;
public class Student implements Serializable {
//Variables that are in our json
#SerializedName("id")
#Expose
private String id;
#SerializedName("totalOpns")
#Expose
private String totalOpns;
#SerializedName("killedDrugPer")
#Expose
private String killedDrugPer;
#SerializedName("arrestedDrugPer")
#Expose
private String arrestedDrugPer;
#SerializedName("houseVisited")
#Expose
private String houseVisited;
#SerializedName("userSurrenderers")
#Expose
private String userSurrenderers;
#SerializedName("pusherSurrenderers")
#Expose
private String pusherSurrenderers;
#SerializedName("totalSurrenderers")
#Expose
private String totalSurrenderers;
#SerializedName("killedPNPPerOpns")
#Expose
private String killedPNPPerOpns;
#SerializedName("woundedPNPPerOpns")
#Expose
private String woundedPNPPerOpns;
#SerializedName("killedAFPPerOpns")
#Expose
private String killedAFPPerOpns;
#SerializedName("woundedAFPPerOpns")
#Expose
private String woundedAFPPerOpns;
#SerializedName("date")
#Expose
private String date;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getTotalOpns() {
return totalOpns;
}
public void setTotalOpns(String totalOpns) {
this.totalOpns = totalOpns;
}
public String getKilledDrugPer() {
return killedDrugPer;
}
public void setKilledDrugPer(String killedDrugPer) {
this.killedDrugPer = killedDrugPer;
}
public String getArrestedDrugPer() {
return arrestedDrugPer;
}
public void setArrestedDrugPer(String arrestedDrugPer) {
this.arrestedDrugPer = arrestedDrugPer;
}
public String getHouseVisited() {
return houseVisited;
}
public void setHouseVisited(String houseVisited) {
this.houseVisited = houseVisited;
}
public String getUserSurrenderers() {
return userSurrenderers;
}
public void setUserSurrenderers(String userSurrenderers) {
this.userSurrenderers = userSurrenderers;
}
public String getPusherSurrenderers() {
return pusherSurrenderers;
}
public void setPusherSurrenderers(String pusherSurrenderers) {
this.pusherSurrenderers = pusherSurrenderers;
}
public String getTotalSurrenderers() {
return totalSurrenderers;
}
public void setTotalSurrenderers(String totalSurrenderers) {
this.totalSurrenderers = totalSurrenderers;
}
public String getKilledPNPPerOpns() {
return killedPNPPerOpns;
}
public void setKilledPNPPerOpns(String killedPNPPerOpns) {
this.killedPNPPerOpns = killedPNPPerOpns;
}
public String getWoundedPNPPerOpns() {
return woundedPNPPerOpns;
}
public void setWoundedPNPPerOpns(String woundedPNPPerOpns) {
this.woundedPNPPerOpns = woundedPNPPerOpns;
}
public String getKilledAFPPerOpns() {
return killedAFPPerOpns;
}
public void setKilledAFPPerOpns(String killedAFPPerOpns) {
this.killedAFPPerOpns = killedAFPPerOpns;
}
public String getWoundedAFPPerOpns() {
return woundedAFPPerOpns;
}
public void setWoundedAFPPerOpns(String woundedAFPPerOpns) {
this.woundedAFPPerOpns = woundedAFPPerOpns;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
}
and the interface is this
package com.androidtutorialpoint.retrofitandroid;
import retrofit2.Call;
import retrofit2.http.GET;
public interface RetrofitObjectAPI {
/*
* Retrofit get annotation with our URL
* And our method that will return us details of student.
*/
// #GET("JSONTESTING/index.php")
#GET("getJson")
Call<Student> getStudentDetails();
}
and in my main is this
private void getRetrofitObject() {
HttpLoggingInterceptor.Level logLevel = HttpLoggingInterceptor.Level.BODY;
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
// set your desired log level
logging.setLevel(logLevel);
OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
// add your other interceptors …
// add logging as last interceptor
httpClient.addInterceptor(logging); // <-- this is the important line!
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(url)
.addConverterFactory(GsonConverterFactory.create())
.client(httpClient.build())
.build();
RetrofitObjectAPI service = retrofit.create(RetrofitObjectAPI.class);
Call<Student> call = service.getStudentDetails();
call.enqueue(new Callback<Student>() {
#Override
public void onResponse(Call<Student> call, Response<Student> response) {
try {
if (response.isSuccessful()) {
text_id_1.setText("StudentId : " + response.body().getId());
text_name_1.setText("StudentName : " + response.body().getTotalOpns());
text_marks_1.setText("StudentMarks : " + response.body().getArrestedDrugPer());
} else {
//unsuccessful response
}
} catch (Exception e) {
Log.d("onResponse", "There is an error");
e.printStackTrace();
}
}
#Override
public void onFailure(Call<Student> call, Throwable t) {
Log.d("onFailure", t.toString());
}
});
}
and in my logcat is this, i can see the json data but on my response.body returns null.
logcat
What should I do?
You are getting a response but there is issue in deserialization.
Reason being the Call<Student> is not the type it will be serialized to becuase you are getting a List of Students(JSONArray).
add this class
MyResponse
public class MyResponse {
#SerializedName("data")
#Expose
private List<Student> data = null;
public List<Student> getData() {
return data;
}
public void setData(List<Student> data) {
this.data = data;
}
}
and change your call to:
#GET("getJson")
Call<MyResponse> getStudentDetails();
Now you will get response body
and how to retrive?
List<Student> students = response.body().getData();
This will do..:)
I have a problem with jaxB. There is no exception and here is my xml ;
<event>
<event_datetimeGMT>2015-02-27 17:00</event_datetimeGMT>
<gamenumber>443364144</gamenumber>
<sporttype>Basketball</sporttype>
<league>Adriatic</league>
<IsLive>No</IsLive>
<participants>
<participant>
<participant_name>Cedevita</participant_name>
<contestantnum>1001</contestantnum>
<rotnum>1001</rotnum>
<visiting_home_draw>Home</visiting_home_draw>
</participant>
<participant>
<participant_name>Mega Leks</participant_name>
<contestantnum>1002</contestantnum>
<rotnum>1002</rotnum>
<visiting_home_draw>Visiting</visiting_home_draw>
</participant>
</participants>
<periods>
<period>
<period_number>0</period_number>
<period_description>Game</period_description>
<periodcutoff_datetimeGMT>2015-02-27 17:00</periodcutoff_datetimeGMT>
<period_status>I</period_status>
<period_update>open</period_update>
<spread_maximum>500</spread_maximum>
<moneyline_maximum>500</moneyline_maximum>
<total_maximum>500</total_maximum>
<moneyline>
<moneyline_visiting>583</moneyline_visiting>
<moneyline_home>-720</moneyline_home>
</moneyline>
<spread>
<spread_visiting>12</spread_visiting>
<spread_adjust_visiting>-104</spread_adjust_visiting>
<spread_home>-12</spread_home>
<spread_adjust_home>-106</spread_adjust_home>
</spread>
<total>
<total_points>164</total_points>
<over_adjust>-101</over_adjust>
<under_adjust>-109</under_adjust>
</total>
</period>
</periods>
here is main class ;
#XmlRootElement (name = "pinnacle_line_feed")
public class PinnacleLineFeed {
private Long PinnacleFeedTime;
private Long lastContest;
private Long lastGame;
private List<Event> events;
#XmlAttribute(name = "PinnacleFeedTime")
public Long getPinnacleFeedTime() {
return PinnacleFeedTime;
}
public void setPinnacleFeedTime(Long pinnacleFeedTime) {
PinnacleFeedTime = pinnacleFeedTime;
}
#XmlAttribute (name = "lastContest")
public Long getLastContest() {
return lastContest;
}
public void setLastContest(Long lastContest) {
this.lastContest = lastContest;
}
#XmlAttribute (name = "lastGame")
public Long getLastGame() {
return lastGame;
}
public void setLastGame(Long lastGame) {
this.lastGame = lastGame;
}
#XmlElement (name = "events")
public List<Event> getEvents() {
return events;
}
public void setEvents(List<Event> events) {
this.events = events;
}
}
you can see full xml from the url which i shared at my first post
and here is my pojos ;
public class Event {
private String event_datetimeGMT;
private Long gamenumber;
private String sporttype;
private String league;
private String IsLive;
private List<Participant> participants;
private List<Period> periods;
#XmlAttribute (name = "event_datetimeGMT")
public String getEvent_datetimeGMT() {
return event_datetimeGMT;
}
public void setEvent_datetimeGMT(String event_datetimeGMT) {
this.event_datetimeGMT = event_datetimeGMT;
}
#XmlAttribute (name = "gamenumber")
public Long getGamenumber() {
return gamenumber;
}
public void setGamenumber(Long gamenumber) {
this.gamenumber = gamenumber;
}
#XmlAttribute (name = "sporttype")
public String getSporttype() {
return sporttype;
}
public void setSporttype(String sporttype) {
this.sporttype = sporttype;
}
#XmlAttribute (name = "league")
public String getLeague() {
return league;
}
public void setLeague(String league) {
this.league = league;
}
#XmlAttribute (name = "IsLive")
public String getIsLive() {
return IsLive;
}
public void setIsLive(String isLive) {
this.IsLive = isLive;
}
#XmlElement(name = "participant")
public List<Participant> getParticipants() {
return participants;
}
public void setParticipants(List<Participant> participants) {
this.participants = participants;
}
#XmlElement(name = "period")
public List<Period> getPeriods() {
return periods;
}
public void setPeriods(List<Period> periods) {
this.periods = periods;
}
}
public class Participants {
private List<Participant> participants;
#XmlElement(name = "participant")
public List<Participant> getParticipants() {
return participants;
}
public void setParticipants(List<Participant> participants) {
this.participants = participants;
}
}
public class Participant {
private String participant_name;
private Long contestantnum;
private Long rotnum;
private String visiting_home_draw;
#XmlAttribute(name = "participant_name")
public String getParticipant_name() {
return participant_name;
}
public void setParticipant_name(String participant_name) {
this.participant_name = participant_name;
}
#XmlAttribute (name = "contestantnum")
public Long getContestantnum() {
return contestantnum;
}
public void setContestantnum(Long contestantnum) {
this.contestantnum = contestantnum;
}
#XmlAttribute (name = "rotnum")
public Long getRotnum() {
return rotnum;
}
public void setRotnum(Long rotnum) {
this.rotnum = rotnum;
}
#XmlAttribute (name = "visiting_home_draw")
public String getVisiting_home_draw() {
return visiting_home_draw;
}
public void setVisiting_home_draw(String visiting_home_draw) {
this.visiting_home_draw = visiting_home_draw;
}
}
public class Periods {
private List<Period> periods;
#XmlElement(name = "period")
public List<Period> getPeriods() {
return periods;
}
public void setPeriods(List<Period> periods) {
this.periods = periods;
}
}
public class Period {
private int period_number;
private String period_description;
private String periodcutoff_datetimeGMT;
private String period_status;
private String period_update;
private int spread_maximum;
private int moneyline_maximum;
private int total_maximum;
private Moneyline moneyline;
private Spread spread;
private Total total;
#XmlAttribute(name = "period_number")
public int getPeriod_number() {
return period_number;
}
public void setPeriod_number(int period_number) {
this.period_number = period_number;
}
#XmlAttribute(name = "period_description")
public String getPeriod_description() {
return period_description;
}
public void setPeriod_description(String period_description) {
this.period_description = period_description;
}
#XmlAttribute(name = "periodcutoff_datetimeGMT")
public String getPeriodcutoff_datetimeGMT() {
return periodcutoff_datetimeGMT;
}
public void setPeriodcutoff_datetimeGMT(String periodcutoff_datetimeGMT) {
this.periodcutoff_datetimeGMT = periodcutoff_datetimeGMT;
}
#XmlAttribute(name = "period_status")
public String getPeriod_status() {
return period_status;
}
public void setPeriod_status(String period_status) {
this.period_status = period_status;
}
#XmlAttribute(name = "period_update")
public String getPeriod_update() {
return period_update;
}
public void setPeriod_update(String period_update) {
this.period_update = period_update;
}
#XmlAttribute(name = "spread_maximum")
public int getSpread_maximum() {
return spread_maximum;
}
public void setSpread_maximum(int spread_maximum) {
this.spread_maximum = spread_maximum;
}
#XmlAttribute(name = "moneyline_maximum")
public int getMoneyline_maximum() {
return moneyline_maximum;
}
public void setMoneyline_maximum(int moneyline_maximum) {
this.moneyline_maximum = moneyline_maximum;
}
#XmlAttribute(name = "total_maximum")
public int getTotal_maximum() {
return total_maximum;
}
public void setTotal_maximum(int total_maximum) {
this.total_maximum = total_maximum;
}
#XmlElement (name = "moneyline")
public Moneyline getMoneyline() {
return moneyline;
}
public void setMoneyline(Moneyline moneyline) {
this.moneyline = moneyline;
}
#XmlElement (name = "spread")
public Spread getSpread() {
return spread;
}
public void setSpread(Spread spread) {
this.spread = spread;
}
#XmlElement (name = "total")
public Total getTotal() {
return total;
}
public void setTotal(Total total) {
this.total = total;
}
}
public class Moneyline {
private int moneyline_visiting;
private int moneyline_home;
#XmlAttribute(name = "moneyline_visiting")
public int getMoneyline_visiting() {
return moneyline_visiting;
}
public void setMoneyline_visiting(int moneyline_visiting) {
this.moneyline_visiting = moneyline_visiting;
}
#XmlAttribute(name = "moneyline_home")
public int getMoneyline_home() {
return moneyline_home;
}
public void setMoneyline_home(int moneyline_home) {
this.moneyline_home = moneyline_home;
}
}
public class Spread {
private int spread_visiting;
private int spread_adjust_visiting;
private int spread_home;
private int spread_adjust_home;
#XmlAttribute(name = "spread_visiting")
public int getSpread_visiting() {
return spread_visiting;
}
public void setSpread_visiting(int spread_visiting) {
this.spread_visiting = spread_visiting;
}
#XmlAttribute(name = "spread_adjust_visiting")
public int getSpread_adjust_visiting() {
return spread_adjust_visiting;
}
public void setSpread_adjust_visiting(int spread_adjust_visiting) {
this.spread_adjust_visiting = spread_adjust_visiting;
}
#XmlAttribute(name = "spread_home")
public int getSpread_home() {
return spread_home;
}
public void setSpread_home(int spread_home) {
this.spread_home = spread_home;
}
#XmlAttribute(name = "spread_adjust_home")
public int getSpread_adjust_home() {
return spread_adjust_home;
}
public void setSpread_adjust_home(int spread_adjust_home) {
this.spread_adjust_home = spread_adjust_home;
}
}
public class Total {
private int total_points;
private int over_adjust;
private int under_adjust;
#XmlAttribute(name = "total_points")
public int getTotal_points() {
return total_points;
}
public void setTotal_points(int total_points) {
this.total_points = total_points;
}
#XmlAttribute(name = "over_adjust")
public int getOver_adjust() {
return over_adjust;
}
public void setOver_adjust(int over_adjust) {
this.over_adjust = over_adjust;
}
#XmlAttribute(name = "under_adjust")
public int getUnder_adjust() {
return under_adjust;
}
public void setUnder_adjust(int under_adjust) {
this.under_adjust = under_adjust;
}
}
and my test method ;
private static void unmarshall() {
try {
JAXBContext jc = JAXBContext.newInstance(PinnacleLineFeed.class);
URL url = new URL("http://xml.pinnaclesports.com/pinnacleFeed.aspx?");
Unmarshaller unmarshaller = jc.createUnmarshaller();
PinnacleLineFeed pinnacleLineFeed = (PinnacleLineFeed) unmarshaller.unmarshal(url);
System.out.println("bakıcez");
} catch (Exception ex) {
ex.printStackTrace();
}
}
When i try to unmarshall this xml, all fields are null. And there is no exception. Can anyone help ?
I have XML as follows
<request type="1">
<request-header/>
<request-details>
<!-- Some more tags -->
</request-details>
</request>
For mapping this XML I have class structure as follows :
public class Request1
{
private RequestDetail_1;
//other members
}
public class Request2
{
private RequestDetail_2;
//other members
}
public class RequestDetail_1
{
//members
}
public class RequestDetail_2
{
//Members
}
What I want to do is ... If attribute type is 1 then I need to create object of type Request_1 , if type is 2 then object type will be Request_2 and so on.
I have gone through this link for reference but still couldn't figure out a way to do this. I want to use pure JAXB and not MOXY or any other such frame works... :( .
Partial code :
#XmlJavaTypeAdapter(RequestAdaptor.class)
#XmlRootElement(name="request")
public class AuthRequest extends Request
{
private AuthRequestDetails requestDetails;
public RequestDetails getRequestDetails()
{
return requestDetails;
}
#Override
public void setRequestDetails(RequestDetails requestDetails)
{
this.requestDetails = (AuthRequestDetails)requestDetails;
}
}
#XmlAccessorType(XmlAccessType.FIELD)
public class AuthRequestDetails extends RequestDetails
{
#XmlElement(name="user-name")
private String userName;
#XmlElement(name="password")
private String password;
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
#XmlAccessorType(XmlAccessType.FIELD)
#XmlJavaTypeAdapter(RequestAdaptor.class)
public abstract class Request
{
#XmlAttribute
protected String type;
#XmlElement(name="request-header")
protected RequestHeader requestHeader;
public RequestHeader getRequestHeader()
{
return requestHeader;
}
public void setRequestHeader(RequestHeader requestHeader)
{
this.requestHeader = requestHeader;
}
public String getType()
{
return type;
}
public void setType(String type)
{
this.type = type;
}
public abstract void setRequestDetails(RequestDetails requestDetails);
public abstract RequestDetails getRequestDetails();
}
public class RequestAdaptor extends XmlAdapter<RequestDTO, Request>
{
#Override
public RequestDTO marshal(Request v) throws Exception
{
System.out.println("marshal");
RequestDTO lRequestDTO= new RequestDTO();
lRequestDTO.setRequestHeader(v.getRequestHeader());
lRequestDTO.setType(v.getType());
if(v.getType().equals("5"))
{
AuthRequest lRequest = (AuthRequest)v;
}
else
{
PingRequest lRequest = (PingRequest)v;
}
return lRequestDTO;
}
#Override
public Request unmarshal(RequestDTO v) throws Exception
{
System.out.println("unmarshal");
if(v.getType().equals("5"))
{
AuthRequest lRequest = new AuthRequest();
lRequest.setRequestHeader(v.getRequestHeader());
lRequest.setType(v.getType());
return lRequest;
}
else
{
PingRequest lRequest = new PingRequest();
lRequest.setRequestHeader(v.getRequestHeader());
lRequest.setType(v.getType());
return lRequest;
}
}
}
#XmlAccessorType(XmlAccessType.FIELD)
public class RequestDTO
{
#XmlAttribute
protected String type;
#XmlElement(name="request-header")
private RequestHeader requestHeader;
#XmlElement(name="request-details")
private RequestDetails requestDetails;
public RequestHeader getRequestHeader()
{
return requestHeader;
}
public void setRequestHeader(RequestHeader requestHeader)
{
this.requestHeader = requestHeader;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public RequestDetails getRequestDetails() {
return requestDetails;
}
public void setRequestDetails(RequestDetails requestDetails) {
this.requestDetails = requestDetails;
}
}
#XmlAccessorType(XmlAccessType.FIELD)
public class RequestHeader
{
#XmlElement(name="name")
String Name;
public String getName() {
return Name;
}
public void setName(String name) {
Name = name;
}
}
First thing is : Marshal and Unmarshal of Adaptor is not getting called. I am stuck at this point.
You can use a StAX XmlStreamReader to parse the XML. Then advance it to the root element. When it's at the root element event check the value of the type attribute. Use this value to determine which Class you should pass to the unmarshal method that takes a Class and XmlStreamReader to get the result you are looking for.