}
public static String toJson(Message resp)
{
Map<String, Object> map = new HashMap<String, Object>();
Header header = resp.getHeader();
map.put("opcode", Opcode.string(header.getOpcode()));
map.put("rcode", Rcode.string(header.getRcode()));
map.put("flags", header.printFlags().trim().split("\\s+"));
map.put("id", header.getID());
addRecords(resp, Section.QUESTION, map, "question");
addRecords(resp, Section.ANSWER, map, "answers");
addRecords(resp, Section.ADDITIONAL, map, "additional");
addRecords(resp, Section.AUTHORITY, map, "authority");