Jackson XML - Can't deserialize Boolean - java

I'm trying to parse XML content with Jackson but I have some difficulties with Boolean value.
This is a part of my XML content :
<?xml version="1.0" encoding="UTF-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body xmlns:ns1="http://somecontent">
<wsResponse xmlns="http://somecontent">
<responseType>SUCCESS</responseType>
<response>
<successfullResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="InterchangeSearchResponse">
<totalResult>1</totalResult>
<returnedResults>1</returnedResults>
<pageIndex>1</pageIndex>
<interchanges>
<interchange>
<depositId>somecontent</depositId>
<interchangeId>somecontent</interchangeId>
<depositDate>2021-03-26T11:45:05.000+01:00</depositDate>
<depositSubject>dépôt WS</depositSubject>
<numADS>number</numADS>
<adsDate>2021-03-26T11:45:05.000+01:00</adsDate>
<alias>contentAsString</alias>
<version xsi:nil="true"/>
<isTest>false</isTest>
<deposantAccount>
<name>someString</name>
</deposantAccount>
<teleProcedure>someString</teleProcedure>
<statesHistory>
This is my XML structure as class :
#JacksonXmlProperty(localName = "Body")
private Body body;
public Body getBody() {
return body;
}
public void setBody(Body body) {
this.body = body;
}
}
#JacksonXmlRootElement
public class Body {
#JacksonXmlProperty(localName = "Fault")
private Fault fault;
private WsResponse wsResponse;
public Fault getFault() {
return fault;
}
public void setFault(Fault fault) {
this.fault = fault;
}
public WsResponse getWsResponse() {
return wsResponse;
}
public void setWsResponse(WsResponse wsResponse) {
this.wsResponse = wsResponse;
}
}
#JacksonXmlRootElement(localName = "wsResponse")
public class WsResponse {
private String responseType;
private Response response;
public String getResponseType() {
return responseType;
}
public void setResponseType(String responseType) {
this.responseType = responseType;
}
public Response getResponse() {
return response;
}
public void setResponse(Response response) {
this.response = response;
}
}
#JacksonXmlRootElement
public class Response {
private SuccessfulResponse successfullResponse;
private ErrorResponse errorResponse;
public SuccessfulResponse getSuccessfullResponse() {
return successfullResponse;
}
public void setSuccessfullResponse(SuccessfulResponse successfullResponse) {
this.successfullResponse = successfullResponse;
}
public ErrorResponse getErrorResponse() {
return errorResponse;
}
public void setErrorResponse(ErrorResponse errorResponse) {
this.errorResponse = errorResponse;
}
}
#JacksonXmlRootElement
public class SuccessfulResponse {
/**
* Response when add document success
*/
private String depositId;
/**
* Response when get interchanges by deposit id success
*/
private String type;
private Integer totalResult;
private Integer returnedResults;
private Integer pageIndex;
private Interchanges interchanges;
/**
* Response when get declaration details success
*/
private DeclarationTdfc declarationTdfc;
public SuccessfulResponse() {}
public SuccessfulResponse(String depositId) {
this.depositId = depositId;
}
public SuccessfulResponse(String type, Integer totalResult, Integer returnedResults, Integer pageIndex, Interchanges interchanges) {
this.type = type;
this.totalResult = totalResult;
this.returnedResults = returnedResults;
this.pageIndex = pageIndex;
this.interchanges = interchanges;
}
public SuccessfulResponse(DeclarationTdfc declarationTdfc) {
this.declarationTdfc = declarationTdfc;
}
public SuccessfulResponse(String depositId, String type, Integer totalResult, Integer returnedResults,
Integer pageIndex, Interchanges interchanges, DeclarationTdfc declarationTdfc) {
super();
this.depositId = depositId;
this.type = type;
this.totalResult = totalResult;
this.returnedResults = returnedResults;
this.pageIndex = pageIndex;
this.interchanges = interchanges;
this.declarationTdfc = declarationTdfc;
}
public String getDepositId() {
return depositId;
}
public void setDepositId(String depositId) {
this.depositId = depositId;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public Integer getTotalResult() {
return totalResult;
}
public void setTotalResult(Integer totalResult) {
this.totalResult = totalResult;
}
public Integer getReturnedResults() {
return returnedResults;
}
public void setReturnedResults(Integer returnedResults) {
this.returnedResults = returnedResults;
}
public Integer getPageIndex() {
return pageIndex;
}
public void setPageIndex(Integer pageIndex) {
this.pageIndex = pageIndex;
}
public Interchanges getInterchanges() {
return interchanges;
}
public void setInterchanges(Interchanges interchanges) {
this.interchanges = interchanges;
}
public DeclarationTdfc getDeclarationTdfc() {
return declarationTdfc;
}
public void setDeclarationTdfc(DeclarationTdfc declarationTdfc) {
this.declarationTdfc = declarationTdfc;
}
}
public class Interchanges {
#JacksonXmlProperty(localName = "interchange")
#JacksonXmlElementWrapper(useWrapping = false)
private List<Interchange> interchange;
public Interchanges() { super(); }
public Interchanges(List<Interchange> interchange) {
super();
this.interchange = interchange;
}
public List<Interchange> getInterchange() {
return interchange;
}
public void setInterchange(List<Interchange> interchange) {
this.interchange = interchange;
}
}
public class Interchange {
private String depositId;
private Integer interchangeId;
//#JsonFormat(shape = JsonFormat.Shape.STRING, pattern = SelfmedConstants.Dates.ENGLISH_DATETIME_PATTERN)
private String depositDate;
private String depositSubject;
private String numADS;
//#JsonFormat(shape = JsonFormat.Shape.STRING, pattern = SelfmedConstants.Dates.ENGLISH_DATETIME_PATTERN)
private String adsDate;
private String alias;
//#JacksonXmlProperty(isAttribute = true)
private String version;
#JsonSerialize(using = BooleanSerializer.class)
#JsonDeserialize(using = BooleanDeserializer.class)
#JacksonXmlProperty(localName = "isTest")
private Boolean isTest;
#JacksonXmlProperty(localName = "name")
#JacksonXmlElementWrapper(localName = "deposantAccount")
private List<String> name;
private String teleProcedure;
private StatesHistory statesHistory;
#JacksonXmlProperty(localName = "declarationId")
#JacksonXmlElementWrapper(localName = "declarationIds")
private List<String> declarationId;
public Interchange() {
}
public Interchange(String depositId, Integer interchangeId, String depositDate, String depositSubject, String numADS,
String adsDate, String alias, String version, Boolean isTest, List<String> name, String teleProcedure,
StatesHistory statesHistory, List<String> declarationId) {
this();
this.depositId = depositId;
this.interchangeId = interchangeId;
this.depositDate = depositDate;
this.depositSubject = depositSubject;
this.numADS = numADS;
this.adsDate = adsDate;
this.alias = alias;
this.version = version;
this.isTest = isTest;
this.name = name;
this.teleProcedure = teleProcedure;
this.statesHistory = statesHistory;
this.declarationId = declarationId;
}
public String getDepositId() {
return depositId;
}
public void setDepositId(String depositId) {
this.depositId = depositId;
}
public Integer getInterchangeId() {
return interchangeId;
}
public void setInterchangeId(Integer interchangeId) {
this.interchangeId = interchangeId;
}
public String getDepositDate() {
return depositDate;
}
public void setDepositDate(String depositDate) {
this.depositDate = depositDate;
}
public String getDepositSubject() {
return depositSubject;
}
public void setDepositSubject(String depositSubject) {
this.depositSubject = depositSubject;
}
public String getNumADS() {
return numADS;
}
public void setNumADS(String numADS) {
this.numADS = numADS;
}
public String getAdsDate() {
return adsDate;
}
public void setAdsDate(String adsDate) {
this.adsDate = adsDate;
}
public String getAlias() {
return alias;
}
public void setAlias(String alias) {
this.alias = alias;
}
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
public Boolean getIsTest() {
return isTest;
}
public void setIsTest(Boolean isTest) {
this.isTest = isTest;
}
public void setIsTest(String isTest) {
this.isTest = Boolean.valueOf(isTest);
}
public List<String> getName() {
return name;
}
public void setName(List<String> name) {
this.name = name;
}
public String getTeleProcedure() {
return teleProcedure;
}
public void setTeleProcedure(String teleProcedure) {
this.teleProcedure = teleProcedure;
}
public StatesHistory getStatesHistory() {
return statesHistory;
}
public void setStatesHistory(StatesHistory statesHistory) {
this.statesHistory = statesHistory;
}
public List<String> getDeclarationId() {
return declarationId;
}
public void setDeclarationId(List<String> declarationId) {
this.declarationId = declarationId;
}
}
As you can see in the Interchange class, I try some stuff but nothing work.
I generate my class like that :
JacksonXmlModule xmlModule = new JacksonXmlModule();
xmlModule.setDefaultUseWrapper(false);
XmlMapper xmlMapper = new XmlMapper(xmlModule);
xmlMapper.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, true);
xmlMapper.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_VALUES);
System.out.println(responseAsString);
Envelope envelope = xmlMapper.readValue(responseAsString, new TypeReference<>() {
But when I try to parse my content, I got this exception :
Cannot construct instance of payload.response.Interchange (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('false')
at [Source: (StringReader); line: 20, column: 28] (through reference chain: payload.response.Envelope["Body"]->payload.response.Body["wsResponse"]->payload.response.WsResponse["response"]->payload.response.Response["successfullResponse"]->payload.response.SuccessfulResponse["interchanges"]->payload.response.Interchanges["interchange"]->java.util.ArrayList[1])
I try a lot of things but nothing work so I'm wondering if the problem may be not here...
If you have any solution or leads to explore, please let me know !
Thank.

According to JavaBean spec you have to name getter isTest().

Related

org.codehaus.jackson.map.JsonMappingException: Illegal type (de.db.kigbau.client.domain.Benutzer) to deserialize: prevented for security reasons

When sending the POST request from my angular client to my Rest API, I am getting the above error.
below is my request model coming from angular client:
{
"anmeldename":"KBBT765",
"nachname":"nach",
"vorname":"vor",
"telefonnummer":"4563",
"password":"szpi;ItM",
"rolle":"B",
"region":"Z",
"eiuname":"",
"zbname":"",
"evuname":"",
"spnv":false,
"spfv":false,
"sgv":false,
"fromEdit":false
}
Below is the rest API POST method to handle the request from angular client and parse the json fields to Benutzer Model:
#POST
#Path("speichern")
#Consumes(MediaType.APPLICATION_JSON)
public boolean speichern(Benutzer benutzerInfo) {
--------------
---------------
}
Rest API Benutzer Model is below:
#JsonIgnoreProperties(ignoreUnknown = true)
public class Benutzer implements Serializable {
private String nachname;
private String anmeldename;
private String vorname;
private String rolle;
private String region;
private String eiuname;
private String zbname;
private String evuname;
private String password;
private String telefonnummer;
private String defaultAnmeldname;
private Boolean spnv;
private Boolean spfv;
private Boolean sgv;
private Boolean fromEdit;
#JsonProperty("evuProfilelist")
private List<EvuProfilSelectedItem> evuProfilelist;
public void setRolle(String rolle) {
this.rolle = rolle;
}
public void setRegion(String region) {
this.region = region;
}
public void setEiuname(String eiuname) {
this.eiuname = eiuname;
}
public void setZbname(String zbname) {
this.zbname = zbname;
}
public void setEvuname(String evuname) {
this.evuname = evuname;
}
public void setSpnv(Boolean spnv) {
this.spnv = spnv;
}
public void setSpfv(Boolean spfv) {
this.spfv = spfv;
}
public void setSgv(Boolean sgv) {
this.sgv = sgv;
}
public String getRolle() {
return rolle;
}
public String getRegion() {
return region;
}
public String getEiuname() {
return eiuname;
}
public String getZbname() {
return zbname;
}
public String getEvuname() {
return evuname;
}
public Boolean isSpnv() {
return spnv;
}
public Boolean isSpfv() {
return spfv;
}
public Boolean isSgv() {
return sgv;
}
public void setPassword(String password) {
this.password = password;
}
public List<EvuProfilSelectedItem> getEvuProfilelist() {
return evuProfilelist;
}
public void setEvuProfilelist(List<EvuProfilSelectedItem> evuProfilelist) {
this.evuProfilelist = evuProfilelist;
}
public String getPassword() {
return password;
}
public String getTelefonnummer() {
return telefonnummer;
}
public void setTelefonnummer(String telefonnummer) {
this.telefonnummer = telefonnummer;
}
public String getNachname() {
return nachname;
}
public void setNachname(String nachname) {
this.nachname = nachname;
}
public String getAnmeldename() {
return anmeldename;
}
public void setAnmeldename(String anmeldename) {
this.anmeldename = anmeldename;
}
public String getVorname() {
return vorname;
}
public void setVorname(String vorname) {
this.vorname = vorname;
}
public Boolean isFromEdit() {
return fromEdit;
}
public void setFromEdit(Boolean fromEdit) {
this.fromEdit = fromEdit;
}
public String getDefaultAnmeldname() {
return defaultAnmeldname;
}
public void setDefaultAnmeldname(String defaultAnmeldname) {
this.defaultAnmeldname = defaultAnmeldname;
}
}
Stack Trace:
2020-03-05 06:42:57,017|ERROR|http-0.0.0.0:17206-4|kigbau.client.RestExceptionMapper||(Request-ID: 9fdG4mDBJWUqtjnqWhdx32) Propagating Exception to the client||| org.codehaus.jackson.map.JsonMappingException: Illegal type (de.db.kigbau.client.domain.Benutzer) to deserialize: prevented for security reasons at org.codehaus.jackson.map.deser.BeanDeserializerFactory.checkLegalTypes(BeanDeserializerFactory.java:1536) at org.codehaus.jackson.map.deser.BeanDeserializerFactory.createBeanDeserializer(BeanDeserializerFactory.java:668)
Is this due to blank or null values in the fields coming from angular client or some thing else?
Please help. Thank you in advance.

Retrofit + Observable - Expected BEGIN_ARRAY but was BEGIN_OBJECT

I'm trying to use New York Times API with Retrofit using Observable. But I'm getting this error when trying to use datas.
Can someone help me see where I'm wrong, please ?
Here is my ApiServices interface:
#GET("svc/topstories/v2/home.json?api-key=HiddenApiKeyJustForThisMessage")
Observable<TopStoryResult> getTopStories();
#GET("svc/topstories/v2/home.json?api-key=HiddenApiKeyJustForThisMessage")
Observable<List<NewsItem>> getResults();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://api.nytimes.com/")
.addConverterFactory(GsonConverterFactory.create(new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create()))
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.build();
Here is my ApiStreams class
public static Observable<TopStoryResult> streamFetchTopStories(){
ApiServices mApiServices = ApiServices.retrofit.create(ApiServices.class);
return mApiServices.getTopStories()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.timeout(10, TimeUnit.SECONDS);
}
public static Observable<List<NewsItem>> streamFetchNews(){
ApiServices mApiServices = ApiServices.retrofit.create(ApiServices.class);
return mApiServices.getResults()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.timeout(10, TimeUnit.SECONDS);
}
And this is what I'm trying to do in my MainActivity. For now I just want to display in a TextView the list of each Title...
//------------------------
// Update UI
//------------------------
private void updateUIWhenStartingHttpRequest() {
this.textView.setText("Downloading...");
}
private void updateUIWhenStopingHttpRequest(String response) {
this.textView.setText(response);
}
//------------------------
// Rx Java
//------------------------
private void executeRequestWithRetrofit(){
this.updateUIWhenStartingHttpRequest();
this.disposable = ApiStreams.streamFetchNews()
.subscribeWith(new DisposableObserver<List<NewsItem>>(){
#Override
public void onNext(List<NewsItem> topStories) {
Log.e("TAG", "On Next");
updateUIWithResult(topStories);
}
#Override
public void onError(Throwable e) {
Log.e("ERROR", Log.getStackTraceString(e));
}
#Override
public void onComplete() {
Log.e("TAG", "On Complete !");
}
});
}
private void updateUIWithResult(List<NewsItem> newsItemList){
StringBuilder mStringBuilder = new StringBuilder();
for (NewsItem news : newsItemList){
Log.e("TAG", "UPDATE UI" + news.getTitle());
mStringBuilder.append("- " + news.getTitle() + "\n");
}
updateUIWhenStopingHttpRequest(mStringBuilder.toString());
}
[EDIT]
There are my two models for TopStories and NewsItem
TopStories:
private String status;
private String copyright;
private String section;
private String lastUpdated;
private Integer numResults;
private List<NewsItem> results = null;
public String getStatus() {return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getCopyright() {
return copyright;
}
public void setCopyright(String copyright) {
this.copyright = copyright;
}
public String getSection() {
return section;
}
public void setSection(String section) {
this.section = section;
}
public String getLastUpdated() {
return lastUpdated;
}
public void setLastUpdated(String lastUpdated) {
this.lastUpdated = lastUpdated;
}
public Integer getNumResults() {
return numResults;
}
public void setNumResults(Integer numResults) {
this.numResults = numResults;
}
public List<NewsItem> getResults() {
return results;
}
public void setResults(List<NewsItem> results) {
this.results = results;
}
NewsItem:
private String section;
private String subsection;
private String title;
private String url;
private String byline;
private String updated_date;
private String created_date;
private String published_date;
private String material_type_facet;
private String kicker;
#SerializedName("abstract")
private String abstract_string;
private List<Multimedia> multimedia;
private transient String des_facet;
private transient String org_facet;
private transient String per_facet;
private transient String geo_facet;
public NewsItem() {
}
public NewsItem(String url) {
this.url = url;
}
public NewsItem(String section, String subsection, String title, String url, String byline, String updated_date, String created_date, String published_date, String material_type_facet, String kicker) {
this.section = section;
this.subsection = subsection;
this.title = title;
this.url = url;
this.byline = byline;
this.updated_date = updated_date;
this.created_date = created_date;
this.published_date = published_date;
this.material_type_facet = material_type_facet;
this.kicker = kicker;
}
public String getSection() {
return section;
}
public void setSection(String section) {
this.section = section;
}
public String getSubsection() {
return subsection;
}
public void setSubsection(String subsection) {
this.subsection = subsection;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getByline() {
return byline;
}
public void setByline(String byline) {
this.byline = byline;
}
public String getUpdated_date() {
return updated_date;
}
public void setUpdated_date(String updated_date) {
this.updated_date = updated_date;
}
public String getCreated_date() {
return created_date;
}
public void setCreated_date(String created_date) {
this.created_date = created_date;
}
public String getPublished_date() {
return published_date;
}
public void setPublished_date(String published_date) {
this.published_date = published_date;
}
public String getMaterial_type_facet() {
return material_type_facet;
}
public void setMaterial_type_facet(String material_type_facet) {
this.material_type_facet = material_type_facet;
}
public String getKicker() {
return kicker;
}
public void setKicker(String kicker) {
this.kicker = kicker;
}
public String getAbstract() {
return abstract_string;
}
public void setAbstract(String abstract_string) {
this.abstract_string = abstract_string;
}
public List<Multimedia> getMultimedia() {
return multimedia;
}
public void setMultimedia(List<Multimedia> multimedia) {
this.multimedia = multimedia;
}
public String getDes_facet() {
return des_facet;
}
public void setDes_facet(String des_facet) {
this.des_facet = des_facet;
}
public String getOrg_facet() {
return org_facet;
}
public void setOrg_facet(String org_facet) {
this.org_facet = org_facet;
}
public String getPer_facet() {
return per_facet;
}
public void setPer_facet(String per_facet) {
this.per_facet = per_facet;
}
public String getGeo_facet() {
return geo_facet;
}
public void setGeo_facet(String geo_facet) {
this.geo_facet = geo_facet;
}
Here is what the JSON looks like:
JSON
First when I tried this one with Github user API, it works fine. But I can't figure out where I'm wrong there...
Is anybody can help me please ?
Thanks a lot !
Expected BEGIN_ARRAY but was BEGIN_OBJECT
this means you are trying to a get a JSON Array as a List in JAVA but the api sent you a JSON OBJECT. So I cannot gather enough information but if I have to guess you should change this
#GET("svc/topstories/v2/home.json?api-key=HiddenApiKeyJustForThisMessage")
Observable<List<NewsItem>> getResults();
to
#GET("svc/topstories/v2/home.json?api-key=HiddenApiKeyJustForThisMessage")
Observable<NewsItemObject> getResults();
NewsItemObject is the Class that wraps NewsItem
In your ApiServices interface you expect that getResults() returns Observable<List<NewsItem>>. Based on JSON you getting back this is not gonna work, because your root JSON element is Object, not an Array.
You have to create new wrapper Class (ResultsWrapper) with "results" field type of List<NewsItem>. Your method in ApiServices interface will then be:
#GET("svc/topstories/v2/home.json?api-key=HiddenApiKeyJustForThisMessage")
Observable<ResultsWrapper> getResults();
That is what "Expected BEGIN_ARRAY but was BEGIN_OBJECT" says to you.

Assigning multiple Retrofit response values to an arraylist

I'm struggling to implement a solution to retrieve multiple values from my api response ( https://www.thecocktaildb.com/api/json/v1/1/lookup.php?i=13060 ) and assign specific values to an array. Specifically values, strIngredient1, strIngredient2, strIngredient3 etc...
At present i created a POJO cocktail class as follows:
public class Cocktail implements Serializable {
#SerializedName("idDrink")
#Expose
private String idDrink;
#SerializedName("strDrink")
#Expose
private String strDrink;
#SerializedName("strVideo")
#Expose
private Object strVideo;
#SerializedName("strCategory")
#Expose
private String strCategory;
#SerializedName("strIBA")
#Expose
private Object strIBA;
#SerializedName("strAlcoholic")
#Expose
private String strAlcoholic;
#SerializedName("strGlass")
#Expose
private String strGlass;
#SerializedName("strInstructions")
#Expose
private String strInstructions;
#SerializedName("strDrinkThumb")
#Expose
private String strDrinkThumb;
#SerializedName("strIngredient1")
#Expose
private String strIngredient1;
#SerializedName("strIngredient2")
#Expose
private String strIngredient2;
#SerializedName("strIngredient3")
#Expose
private String strIngredient3;
#SerializedName("strIngredient4")
#Expose
private String strIngredient4;
#SerializedName("strIngredient5")
#Expose
private String strIngredient5;
#SerializedName("strIngredient6")
#Expose
private String strIngredient6;
#SerializedName("strIngredient7")
#Expose
private String strIngredient7;
#SerializedName("strIngredient8")
#Expose
private String strIngredient8;
#SerializedName("strIngredient9")
#Expose
private String strIngredient9;
#SerializedName("strIngredient10")
#Expose
private String strIngredient10;
#SerializedName("strIngredient11")
#Expose
private String strIngredient11;
#SerializedName("strIngredient12")
#Expose
private String strIngredient12;
#SerializedName("strIngredient13")
#Expose
private String strIngredient13;
#SerializedName("strIngredient14")
#Expose
private String strIngredient14;
#SerializedName("strIngredient15")
#Expose
private String strIngredient15;
#SerializedName("strMeasure1")
#Expose
private String strMeasure1;
#SerializedName("strMeasure2")
#Expose
private String strMeasure2;
#SerializedName("strMeasure3")
#Expose
private String strMeasure3;
#SerializedName("strMeasure4")
#Expose
private String strMeasure4;
#SerializedName("strMeasure5")
#Expose
private String strMeasure5;
#SerializedName("strMeasure6")
#Expose
private String strMeasure6;
#SerializedName("strMeasure7")
#Expose
private String strMeasure7;
#SerializedName("strMeasure8")
#Expose
private String strMeasure8;
#SerializedName("strMeasure9")
#Expose
private String strMeasure9;
#SerializedName("strMeasure10")
#Expose
private String strMeasure10;
#SerializedName("strMeasure11")
#Expose
private String strMeasure11;
#SerializedName("strMeasure12")
#Expose
private String strMeasure12;
#SerializedName("strMeasure13")
#Expose
private String strMeasure13;
#SerializedName("strMeasure14")
#Expose
private String strMeasure14;
#SerializedName("strMeasure15")
#Expose
private String strMeasure15;
#SerializedName("dateModified")
#Expose
private String dateModified;
public String getIdDrink() {
return idDrink;
}
public void setIdDrink(String idDrink) {
this.idDrink = idDrink;
}
public String getStrDrink() {
return strDrink;
}
public void setStrDrink(String strDrink) {
this.strDrink = strDrink;
}
public Object getStrVideo() {
return strVideo;
}
public void setStrVideo(Object strVideo) {
this.strVideo = strVideo;
}
public String getStrCategory() {
return strCategory;
}
public void setStrCategory(String strCategory) {
this.strCategory = strCategory;
}
public Object getStrIBA() {
return strIBA;
}
public void setStrIBA(Object strIBA) {
this.strIBA = strIBA;
}
public String getStrAlcoholic() {
return strAlcoholic;
}
public void setStrAlcoholic(String strAlcoholic) {
this.strAlcoholic = strAlcoholic;
}
public String getStrGlass() {
return strGlass;
}
public void setStrGlass(String strGlass) {
this.strGlass = strGlass;
}
public String getStrInstructions() {
return strInstructions;
}
public void setStrInstructions(String strInstructions) {
this.strInstructions = strInstructions;
}
public String getStrDrinkThumb() {
return strDrinkThumb;
}
public void setStrDrinkThumb(String strDrinkThumb) {
this.strDrinkThumb = strDrinkThumb;
}
public String getStrIngredient1() {
return strIngredient1;
}
public void setStrIngredient1(String strIngredient1) {
this.strIngredient1 = strIngredient1;
}
public String getStrIngredient2() {
return strIngredient2;
}
public void setStrIngredient2(String strIngredient2) {
this.strIngredient2 = strIngredient2;
}
public String getStrIngredient3() {
return strIngredient3;
}
public void setStrIngredient3(String strIngredient3) {
this.strIngredient3 = strIngredient3;
}
public String getStrIngredient4() {
return strIngredient4;
}
public void setStrIngredient4(String strIngredient4) {
this.strIngredient4 = strIngredient4;
}
public String getStrIngredient5() {
return strIngredient5;
}
public void setStrIngredient5(String strIngredient5) {
this.strIngredient5 = strIngredient5;
}
public String getStrIngredient6() {
return strIngredient6;
}
public void setStrIngredient6(String strIngredient6) {
this.strIngredient6 = strIngredient6;
}
public String getStrIngredient7() {
return strIngredient7;
}
public void setStrIngredient7(String strIngredient7) {
this.strIngredient7 = strIngredient7;
}
public String getStrIngredient8() {
return strIngredient8;
}
public void setStrIngredient8(String strIngredient8) {
this.strIngredient8 = strIngredient8;
}
public String getStrIngredient9() {
return strIngredient9;
}
public void setStrIngredient9(String strIngredient9) {
this.strIngredient9 = strIngredient9;
}
public String getStrIngredient10() {
return strIngredient10;
}
public void setStrIngredient10(String strIngredient10) {
this.strIngredient10 = strIngredient10;
}
public String getStrIngredient11() {
return strIngredient11;
}
public void setStrIngredient11(String strIngredient11) {
this.strIngredient11 = strIngredient11;
}
public String getStrIngredient12() {
return strIngredient12;
}
public void setStrIngredient12(String strIngredient12) {
this.strIngredient12 = strIngredient12;
}
public String getStrIngredient13() {
return strIngredient13;
}
public void setStrIngredient13(String strIngredient13) {
this.strIngredient13 = strIngredient13;
}
public String getStrIngredient14() {
return strIngredient14;
}
public void setStrIngredient14(String strIngredient14) {
this.strIngredient14 = strIngredient14;
}
public String getStrIngredient15() {
return strIngredient15;
}
public void setStrIngredient15(String strIngredient15) {
this.strIngredient15 = strIngredient15;
}
public String getStrMeasure1() {
return strMeasure1;
}
public void setStrMeasure1(String strMeasure1) {
this.strMeasure1 = strMeasure1;
}
public String getStrMeasure2() {
return strMeasure2;
}
public void setStrMeasure2(String strMeasure2) {
this.strMeasure2 = strMeasure2;
}
public String getStrMeasure3() {
return strMeasure3;
}
public void setStrMeasure3(String strMeasure3) {
this.strMeasure3 = strMeasure3;
}
public String getStrMeasure4() {
return strMeasure4;
}
public void setStrMeasure4(String strMeasure4) {
this.strMeasure4 = strMeasure4;
}
public String getStrMeasure5() {
return strMeasure5;
}
public void setStrMeasure5(String strMeasure5) {
this.strMeasure5 = strMeasure5;
}
public String getStrMeasure6() {
return strMeasure6;
}
public void setStrMeasure6(String strMeasure6) {
this.strMeasure6 = strMeasure6;
}
public String getStrMeasure7() {
return strMeasure7;
}
public void setStrMeasure7(String strMeasure7) {
this.strMeasure7 = strMeasure7;
}
public String getStrMeasure8() {
return strMeasure8;
}
public void setStrMeasure8(String strMeasure8) {
this.strMeasure8 = strMeasure8;
}
public String getStrMeasure9() {
return strMeasure9;
}
public void setStrMeasure9(String strMeasure9) {
this.strMeasure9 = strMeasure9;
}
public String getStrMeasure10() {
return strMeasure10;
}
public void setStrMeasure10(String strMeasure10) {
this.strMeasure10 = strMeasure10;
}
public String getStrMeasure11() {
return strMeasure11;
}
public void setStrMeasure11(String strMeasure11) {
this.strMeasure11 = strMeasure11;
}
public String getStrMeasure12() {
return strMeasure12;
}
public void setStrMeasure12(String strMeasure12) {
this.strMeasure12 = strMeasure12;
}
public String getStrMeasure13() {
return strMeasure13;
}
public void setStrMeasure13(String strMeasure13) {
this.strMeasure13 = strMeasure13;
}
public String getStrMeasure14() {
return strMeasure14;
}
public void setStrMeasure14(String strMeasure14) {
this.strMeasure14 = strMeasure14;
}
public String getStrMeasure15() {
return strMeasure15;
}
public void setStrMeasure15(String strMeasure15) {
this.strMeasure15 = strMeasure15;
}
public String getDateModified() {
return dateModified;
}
public void setDateModified(String dateModified) {
this.dateModified = dateModified;
}
And my API call is as follows:
#Override
protected Cocktail doInBackground(Cocktail... cocktails) {
Call<Cocktails> call = mApiService.getCocktail(id);
try {
Response<Cocktails> response = call.execute();
this.cocktails = response.body();
this.cocktail = this.cocktails.getCocktail().get(0);
Log.i(TAG, "Success: " + response.body().toString());
} catch (IOException e) {
Log.e(TAG, "IOException: " + e);
e.printStackTrace();
} catch (IllegalStateException e) {
Log.e(TAG, "IllegalStateException: " + e);
e.printStackTrace();
}
return cocktail;
}
I know enough to realise that a large number of variables, ingredients and measures (many of which are empty) is the wrong approach but i'm struggling to find a solution with retrofit to create an array of these values. I've not found any way to assign multiple SerializedNames to a single array variable?
The option that jumps out at me is looping through the response pulling out the key values in onSuccess but this seems to go against the simplicity of using retrofit?

Unable to Convert Json Response to an Entity by ClientResponse class

I have below method addAppearance(BasicInfo basicInfo)
private static Boolean addAppearance(BasicInfo basicInfo){
Boolean inserted = false;
GsonBuilder builder = new GsonBuilder();
Gson gson = builder.create();
String jsonObj = gson.toJson(basicInfo);
Client client = Client.create();
WebResource webResource = client
.resource("http://localhost:8080/Services/webapi/appearance");
ClientResponse clientResponse = webResource
.accept(MediaType.TEXT_PLAIN)
.type(MediaType.APPLICATION_JSON)
.post(ClientResponse.class, jsonObj.toString());
basicInfo = clientResponse.getEntity(BasicInfo.class);
if(clientResponse.getStatus()==200)
inserted = true;
return inserted;
}
After hitting the url by client.resource() I am getting a Json Response
{
"appearanceId": 24,
"bodyType": "SLIM",
"healthInfo": "LOW_BP",
"height_cm": 101,
"height_feet": 3,
"height_inch": 8,
"skinTone": "VERY_FAIR",
"weight": 34
}
But I am not able to convert that response to BasicInfo class.
BasicInfo.java
public class BasicInfo {
private int appearanceId;
private int height_feet;
private int height_inch;
private int height_cm;
private int weight;
private String fullName;
private String maritalStatus;
private String bodyType;
private String healthInfo;
private String skinTone;
private String disability;
private String bloodgroup;
public String getBodyType() {
return bodyType;
}
public void setBodyType(String bodyType) {
this.bodyType = bodyType;
}
public int getAppearanceId() {
return appearanceId;
}
public void setAppearanceId(int appearanceId) {
this.appearanceId = appearanceId;
}
public int getHeight_feet() {
return height_feet;
}
public void setHeight_feet(int height_feet) {
this.height_feet = height_feet;
}
public int getHeight_inch() {
return height_inch;
}
public void setHeight_inch(int height_inch) {
this.height_inch = height_inch;
}
public int getHeight_cm() {
return height_cm;
}
public void setHeight_cm(int height_cm) {
this.height_cm = height_cm;
}
public int getWeight() {
return weight;
}
public void setWeight(int weight) {
this.weight = weight;
}
public String getFullName() {
return fullName;
}
public void setFullName(String fullName) {
this.fullName = fullName;
}
public String getMaritalStatus() {
return maritalStatus;
}
public void setMaritalStatus(String maritalStatus) {
this.maritalStatus = maritalStatus;
}
public String getHealthInfo() {
return healthInfo;
}
public void setHealthInfo(String healthInfo) {
this.healthInfo = healthInfo;
}
public String getSkinTone() {
return skinTone;
}
public void setSkinTone(String skinTone) {
this.skinTone = skinTone;
}
public String getDisability() {
return disability;
}
public void setDisability(String disability) {
this.disability = disability;
}
public String getBloodgroup() {
return bloodgroup;
}
public void setBloodgroup(String bloodgroup) {
this.bloodgroup = bloodgroup;
}
}

Mybatis There is no getter for property

I'm working with Mybatis to batch insert data,specifically my parameterType is a class,which has a List property,so I use foreach to do the traversal.But it didn't work,here are the debug and codes.Thanks.
DEBUG
here is the sql:
<insert id="batchInsertSn" parameterType="domain.collectSn.IbSnTransit">
insert into
ib_sn_transit (
sn, inbound_no, container_no,
goods_no,goods_name, owner_no,
owner_name,create_user,update_user,
create_time,update_time,yn,
org_no,org_name,distribute_no,
warehouse_no,receiving_no,supplier_no
,out_wave_no)
values
<foreach collection="snList" item="item" index="index" separator="," >
(
#{item.sn,jdbcType=VARCHAR}, #{inboundNo,jdbcType=VARCHAR}, #{containerNo,jdbcType=VARCHAR},
#{goodsNo,jdbcType=VARCHAR},#{goodsName,jdbcType=VARCHAR},#{ownerNo,jdbcType=VARCHAR},
#{ownerName,jdbcType=VARCHAR}, #{createUser,jdbcType=VARCHAR}, #{updateUser,jdbcType=VARCHAR},
now(),now(),#{yn,jdbcType=TINYINT},
#{orgNo,jdbcType=VARCHAR},#{orgName,jdbcType=VARCHAR},#{distributeNo,jdbcType=VARCHAR},
#{warehouseNo,jdbcType=VARCHAR},#{receivingNo,jdbcType=VARCHAR},#{supplierNo,jdbcType=VARCHAR}
,#{outWaveNo,jdbcType=VARCHAR}
)
</foreach>
</insert>
here is the class
public class IbSnTransit {
private String outWaveNo;
private String queryUser;
private String finishFlag;
private Integer id;
private String inboundNo;
private String sn;
private String snStart;
private String snEnd;
private String containerNo;
private String goodsNo;
private String goodsName;
private String ownerNo;
private String ownerName;
private String createUser;
private Date createTime;
private String updateUser;
private Date updateTime;
private Integer yn;
private String orgNo;
private String orgName;
private String distributeNo;
private String warehouseNo;
private String receivingNo;
private String supplierNo;
private List<String> snList;
public String getSupplierNo() {
return supplierNo;
}
public void setSupplierNo(String supplierNo) {
this.supplierNo = supplierNo;
}
public Integer getId() {
return id;
}
public void setId(Integer id){
this.id = id;
}
public String getOwnerName() {
return ownerName;
}
public void setOwnerName(String ownerName) {
this.ownerName = ownerName;
}
public String getOrgName() {
return orgName;
}
public void setOrgName(String orgName) {
this.orgName = orgName;
}
public String getSn() {
return sn;
}
public void setSn(String sn){
this.sn = sn;
}
public String getInboundNo() {
return inboundNo;
}
public void setInboundNo(String inboundNo) {
this.inboundNo = inboundNo;
}
public String getGoodsNo() {
return goodsNo;
}
public void setGoodsNo(String goodsNo) {
this.goodsNo = goodsNo;
}
public String getGoodsName() {
return goodsName;
}
public void setGoodsName(String goodsName) {
this.goodsName = goodsName;
}
public String getContainerNo() {
return containerNo;
}
public void setContainerNo(String containerNo) {
this.containerNo = containerNo;
}
public String getOwnerNo() {
return ownerNo;
}
public void setOwnerNo(String ownerNo) {
this.ownerNo = ownerNo;
}
public String getCreateUser() {
return createUser;
}
public void setCreateUser(String createUser) {
this.createUser = createUser;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public String getUpdateUser() {
return updateUser;
}
public void setUpdateUser(String updateUser) {
this.updateUser = updateUser;
}
public Date getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
public Integer getYn() {
return yn;
}
public void setYn(Integer yn) {
this.yn = yn;
}
public String getDistributeNo() {
return distributeNo;
}
public void setDistributeNo(String distributeNo) {
this.distributeNo = distributeNo;
}
public String getOrgNo() {
return orgNo;
}
public void setOrgNo(String orgNo) {
this.orgNo = orgNo;
}
public String getWarehouseNo() {
return warehouseNo;
}
public void setWarehouseNo(String warehouseNo) {
this.warehouseNo = warehouseNo;
}
public String getSnStart() {
return snStart;
}
public void setSnStart(String snStart) {
this.snStart = snStart;
}
public String getSnEnd() {
return snEnd;
}
public void setSnEnd(String snEnd) {
this.snEnd = snEnd;
}
public String getReceivingNo() {
return receivingNo;
}
public void setReceivingNo(String receivingNo) {
this.receivingNo = receivingNo;
}
public String getFinishFlag() {
return finishFlag;
}
public void setFinishFlag(String finishFlag) {
this.finishFlag = finishFlag;
}
public String getQueryUser() {
return queryUser;
}
public void setQueryUser(String queryUser) {
this.queryUser = queryUser;
}
public String getOutWaveNo() {
return outWaveNo;
}
public void setOutWaveNo(String outWaveNo) {
this.outWaveNo = outWaveNo;
}
public List<String> getSnList() {
return snList;
}
public void setSnList(List<String> snList) {
this.snList = snList;
}
}
the result
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named '' in 'class java.lang.String'
IbSnTransit.snList is declared as List of String.class objects so, when you use #{item.sn,jdbcType=VARCHAR} in your mapper you are asked for a property sn in the String.class. Maybe you must use #{item,jdbcType=VARCHAR} instead.

Categories