Oi pessoal, estou tentando enviar um json que contem um campo data e está me retornando o seguinte erro:
com.thoughtworks.xstream.converters.ConversionException: Cannot parse date 1974-03-23 00:00:00.0
---- Debugging information ----
class : br.com.aberta.tzion.cadastroGlobal.entity.Aluno
required-type : java.util.Date
path : /data/niver
line number : -1
com.thoughtworks.xstream.converters.basic.DateConverter.fromString(DateConverter.java:97)
os codigos são o seguinte:
controller:
@Path("/aluno/alterar")
public void alterar(List registros) {
try{
Aluno a = (Aluno) this.alunoService.alterar(registros.get(0));
result.use(ExtJSJson.class).from(a).success(a != null).serialize();
} catch (Exception e) {
result.use(ExtJSJson.class).from(e.getMessage()).success(false).serialize();
}
}
ParametersProvider
@Component
public class JsonableParametersProvider implements ParametersProvider {
private ParametersProvider delegate;
public JsonableParametersProvider(ParametersProvider delegate) {
this.delegate = delegate;
}
public Object[] getParametersFor(ResourceMethod method, List<Message> errors, ResourceBundle bundle) {
Object[] parameters = delegate.getParametersFor(method, errors, bundle);
for(int i = 0; i < parameters.length; i++) {
if((parameters[i] instanceof List<?>)&&
(!((List<?>)parameters[i]).isEmpty()) &&
(((List<?>)parameters[i]).get(0) instanceof List<?>) &&
((!((List<?>)((List<?>)parameters[i]).get(0)).isEmpty() &&
((List<?>)((List<?>)parameters[i]).get(0)).get(0) instanceof Jsonable)||
(((List<?>)((List<?>)parameters[i]).get(0)).isEmpty()))){
parameters[i] = ((List<?>)parameters[i]).get(0);
}
}
return parameters;
}
}
Converter
@Convert(Jsonable.class)
public class JsonableConverter implements Converter<List> {
public List convert(String value, Class<? extends List> type, ResourceBundle arg2) {
ArrayList list = new ArrayList();
if (value.substring(0, 2).equals("[{")){
JSONArray arrayJson;
try {
arrayJson = new JSONArray(value);
for (int i = 0; i < arrayJson.length(); i++) {
String json = "{\"data\":"+ arrayJson.getJSONObject(i).toString() +"}";
addJsonable(list, json, type);
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}else if (!value.substring(0, 2).equals("[]")){
String json = "{\"data\":"+ value +"}";
addJsonable(list, json, type);
}
return list;
}
@SuppressWarnings("rawtypes")
private void addJsonable(List<Jsonable> list, String json, Class type){
XStream xstream = new XStream(new JettisonMappedXmlDriver());
xstream.alias("data", type);
list.add((Jsonable) xstream.fromXML(json));
}
}
Já tentei criar um converte pra Date, mas nem entra no converter
Converter Data:
@Convert(Date.class)
public class DateConverter implements Converter<Date> {
public Date convert(String value, Class<? extends Date> type, ResourceBundle arg2) {
Date date = new Date();
try {
date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(value);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return date;
}
}
Valeu, desde já, Obrigado!!!