我正在尝试阅读下面的json,当我在本地运行时,一切正常,但当我尝试使用邮递员发送时,它返回一个带有此错误的html页面:
Can not deserialize instance of java.lang.String out of START_OBJECT token date
我将在下面发布控制器代码,我可以发布转换器或者你可能会问的任何其他内容,我找不到的原因是我甚至无法调试它,因为错误发生在之前控制器的第一行
{
"ageRange": "ADULT",
"condition": "ALMOSTNEW",
"images": "[]",
"Size": "G",
"Denunciations": {
"reviews": {
"dateCreated": " 2017/07/20 14:45:05",
"description": "Teste review Denunciations",
"reviewer": "cassio.t@gmail.com",
"value": 5
}
},
"description": "gato",
"creationDate": "2017/07/20 14:45:05",
"title": "Bermuda",
"user": "312321321",
"status": "AVAILABLE"
}
Java ClothesController
package br.com.troca.controllers;
@Path("clothes")
public class ClothesController {
private ClothesMongoDAO clothesMongoDAO;
@Context
private HttpServletRequest request;
/**
* Lista todos os usuarios via api
**/
@GET
@Path("/")
@Produces("application/json; charset=UTF-8")
public List<Clothes> list() throws PersistenciaException, SQLException, NegocioException {
request.getSession();
//User loggedUser = (User) session.getAttribute("user");
try {
List<Clothes> clothes = new ClothesMongoDAO().findClothes();
return clothes;
} catch (Exception e) {
System.out.println("FUDEU CARALHO IRMÃO ACABOU");
e.printStackTrace();
}
return null;
}
/**
* cloth saving
**/
@POST
@Path("/")
@Consumes("application/json; charset=UTF-8")
@Produces("application/json; charset=UTF-8")
public Response create(HashMap<String, String> body) throws PersistenciaException, ValidationException, NegocioException {
HashMap<String, Object> map = new HashMap<>();
request.getSession();
// User loggedUser = (User) session.getAttribute("user");
clothesMongoDAO = new ClothesMongoDAO();
Clothes clothes = new Clothes();
// ageRange condition size criatonDate description status title;
try {
clothes.setAgeRange(AgeRange.valueOf(body.get("ageRange")));
clothes.setCondition(Condition.valueOf(body.get("condition")));
clothes.setSize(Size.valueOf(body.get("Size")));
clothes.setDescription(body.get("description"));
clothes.setStatus(StatusItem.valueOf(body.get("status")));
clothes.setTitle(body.get("title"));
clothes.setComplain(new Denunciations());
clothes.setImages(body.get("images"));
clothes.setIdUser(body.get("user"));
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Date date = new Date();
clothes.setCreationDate(date);
// userBO.validate(newUser);
clothesMongoDAO.save(clothes);
map.put("success", true);
map.put("message", MensagemContantes.MSG_SUC_CADASTRO_USUARIO);
// map.put("user", userMongoDAO.getUserByCPF(newUser.getCpf()));
} catch (Exception e) {
map.put("success", false);
map.put("message", e.getMessage());
}
return Response.ok().entity(map).build();
}
}