I am getting sometimes and sometimes not weird error:
Error setting expression X with value [Ljava.lang.String;@......]
It sometimes occurs and sometimes not. It is quiet annoying. The error sometimes comes from this class:
package com.coreRestaurant.menuItem;
import com.google.gson.Gson;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
public class MenuItemAction extends ActionSupport implements ModelDriven<MenuItem>{
private MenuItem menuItem = new MenuItem();
private final String DATABASE_PROBLEMS = "Error code : Database problems";
private String json;
public String execute(){
MenuItemService itemService = new MenuItemService();
if(itemService.testDatabaseConnectionU()){
setJson(new Gson().toJson(itemService.getMenuItemsByMenuId(menuItem.getMenuId()) ));
}else{
setErrorToBeSentBackToClientSide(DATABASE_PROBLEMS);
}
return SUCCESS;
}
@Override
public MenuItem getModel() {
return menuItem;
}
public String getJson() {
return json;
}
public void setJson(String json) {
this.json = json;
}
private void setErrorToBeSentBackToClientSide(String error){
String errorCode = error;
setJson(new Gson().toJson(errorCode));
}
}
And then MenuItem
class:
package com.coreRestaurant.menuItem;
public class MenuItem {
private String name;
private double price;
private int menuId;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public int getMenuId() {
return menuId;
}
public void setMenuId(int menuId) {
this.menuId = menuId;
}
public void setMenuId(MenuItem fromJson) {
setName(fromJson.getName());
setPrice(fromJson.getPrice());
}
}
And I am calling those things from PHP file (the two lines do that, but the second one is a worrychild):
$specificMenuJson = file_get_contents('http://localhost:8080/Core/read?id=' . $menuId);
$specificMenuItemsJson = file_get_contents('http://localhost:8080/Core/readMenuItemById?menuId=' . $menuId);
It has problem setting the value of menuId
, but I have getters and setters included. I don't know why it sometimes fails to do that. Any suggestions?
Try to change the name of the method setMenuId
public void fromJsonMenuId(MenuItem fromJson) {
setName(fromJson.getName());
setPrice(fromJson.getPrice());
}