我正在尝试将字符串数组的json对象映射到java类。
{ "SKU": ["A", "B", "C"], "Desc": ["Milk", "Bread", "Jam"] }
public class Inventory_Metrics {
public String[] SKU;
public String[] Desc;
}
@Path("/post")
@POST
@Consumes({MediaType.APPLICATION_FORM_URLENCODED, MediaType.APPLICATION_JSON})
@Produces(MediaType.APPLICATION_JSON)
public Response addInventory(String json) throws JsonParseException, JsonMappingException, IOException {
ObjectMapper mapper = new ObjectMapper();
Inventory_Metrics inv_met = mapper.readValue(json, Inventory_Metrics.class);
System.out.print(inv_met.SKU[0]);
return Response.ok().build();
}
SEVERE: Servlet.service() for servlet [Jersey REST Service] in context with path [/api] threw exception [org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of com.mycode.database.mapping.Inventory_Metrics out of START_ARRAY token
at [Source: java.io.StringReader@182856b6; line: 1, column: 1]] with root cause
org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of com.mycode.database.mapping.Inventory_Metrics out of START_ARRAY token
at [Source: java.io.StringReader@182856b6; line: 1, column: 1]
答案 0 :(得分:0)
关闭旧的无效json帖子数据的浏览器缓存。