这太过复杂了,Jackson通过其writer方法处理列表以及处理常规对象。假设我没有误解您的问题,这对您来说应该很好:
public void writeListToJsonArray() throws IOException { final List<Event> list = new ArrayList<Event>(2); list.add(new Event("a1","a2")); list.add(new Event("b1","b2")); final ByteArrayOutputStream out = new ByteArrayOutputStream(); final ObjectMapper mapper = new ObjectMapper(); mapper.writevalue(out, list); final byte[] data = out.toByteArray(); System.out.println(new String(data));}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)