| Nils Diewald | c471b18 | 2014-11-19 22:51:15 +0000 | [diff] [blame] | 1 | package de.ids_mannheim.korap.response; |
| 2 | |
| 3 | import de.ids_mannheim.korap.util.QueryException; |
| Akron | 74748c6 | 2016-06-29 00:22:43 +0200 | [diff] [blame] | 4 | import static de.ids_mannheim.korap.util.KrillString.quote; |
| Nils Diewald | c471b18 | 2014-11-19 22:51:15 +0000 | [diff] [blame] | 5 | import de.ids_mannheim.korap.response.Message; |
| 6 | |
| Akron | 7d45e6b | 2015-06-26 17:23:42 +0200 | [diff] [blame] | 7 | import com.fasterxml.jackson.annotation.JsonInclude.Include; |
| Nils Diewald | c471b18 | 2014-11-19 22:51:15 +0000 | [diff] [blame] | 8 | import com.fasterxml.jackson.annotation.*; |
| 9 | import com.fasterxml.jackson.databind.ObjectMapper; |
| 10 | import com.fasterxml.jackson.databind.JsonNode; |
| 11 | import com.fasterxml.jackson.databind.node.*; |
| 12 | |
| Nils Diewald | 2f2b067 | 2014-11-25 20:26:22 +0000 | [diff] [blame] | 13 | import java.lang.*; |
| 14 | import java.util.*; |
| Nils Diewald | c471b18 | 2014-11-19 22:51:15 +0000 | [diff] [blame] | 15 | |
| 16 | /** |
| Nils Diewald | 2f2b067 | 2014-11-25 20:26:22 +0000 | [diff] [blame] | 17 | * A list of messages for Notifications. |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 18 | * |
| Nils Diewald | 2f2b067 | 2014-11-25 20:26:22 +0000 | [diff] [blame] | 19 | * <p> |
| 20 | * <blockquote><pre> |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 21 | * Messages m = new Messages(); |
| 22 | * m.add(614, "This is a new message"); |
| Nils Diewald | 2f2b067 | 2014-11-25 20:26:22 +0000 | [diff] [blame] | 23 | * </pre></blockquote> |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 24 | * |
| Nils Diewald | c99ed5b | 2015-01-21 22:08:53 +0000 | [diff] [blame] | 25 | * @author diewald |
| 26 | * @see Notifications |
| 27 | * @see Message |
| Nils Diewald | c471b18 | 2014-11-19 22:51:15 +0000 | [diff] [blame] | 28 | */ |
| Akron | 7d45e6b | 2015-06-26 17:23:42 +0200 | [diff] [blame] | 29 | @JsonInclude(Include.NON_NULL) |
| 30 | @JsonIgnoreProperties(ignoreUnknown = true) |
| Nils Diewald | 2f2b067 | 2014-11-25 20:26:22 +0000 | [diff] [blame] | 31 | public class Messages implements Cloneable, Iterable<Message> { |
| Nils Diewald | c471b18 | 2014-11-19 22:51:15 +0000 | [diff] [blame] | 32 | |
| Nils Diewald | 2f2b067 | 2014-11-25 20:26:22 +0000 | [diff] [blame] | 33 | // Create object mapper for JSON generation |
| Nils Diewald | c471b18 | 2014-11-19 22:51:15 +0000 | [diff] [blame] | 34 | ObjectMapper mapper = new ObjectMapper(); |
| Nils Diewald | 2f2b067 | 2014-11-25 20:26:22 +0000 | [diff] [blame] | 35 | |
| 36 | // List of messages |
| Nils Diewald | c471b18 | 2014-11-19 22:51:15 +0000 | [diff] [blame] | 37 | private ArrayList<Message> messages; |
| 38 | |
| Nils Diewald | 2f2b067 | 2014-11-25 20:26:22 +0000 | [diff] [blame] | 39 | // Private class for iterator implementation |
| 40 | private class MessageIterator implements Iterator<Message> { |
| Nils Diewald | 44d5fa1 | 2015-01-15 21:31:52 +0000 | [diff] [blame] | 41 | int index; |
| Nils Diewald | 2f2b067 | 2014-11-25 20:26:22 +0000 | [diff] [blame] | 42 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 43 | |
| Nils Diewald | 44d5fa1 | 2015-01-15 21:31:52 +0000 | [diff] [blame] | 44 | // Constructor |
| Nils Diewald | 2f2b067 | 2014-11-25 20:26:22 +0000 | [diff] [blame] | 45 | public MessageIterator () { |
| 46 | this.index = 0; |
| 47 | }; |
| 48 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 49 | |
| Nils Diewald | 2f2b067 | 2014-11-25 20:26:22 +0000 | [diff] [blame] | 50 | @Override |
| Nils Diewald | 44d5fa1 | 2015-01-15 21:31:52 +0000 | [diff] [blame] | 51 | public boolean hasNext () { |
| Nils Diewald | 2f2b067 | 2014-11-25 20:26:22 +0000 | [diff] [blame] | 52 | return this.index < messages.size(); |
| 53 | }; |
| 54 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 55 | |
| Nils Diewald | 2f2b067 | 2014-11-25 20:26:22 +0000 | [diff] [blame] | 56 | @Override |
| Nils Diewald | 44d5fa1 | 2015-01-15 21:31:52 +0000 | [diff] [blame] | 57 | public Message next () { |
| Nils Diewald | 2f2b067 | 2014-11-25 20:26:22 +0000 | [diff] [blame] | 58 | return messages.get(this.index++); |
| 59 | }; |
| 60 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 61 | |
| Nils Diewald | 2f2b067 | 2014-11-25 20:26:22 +0000 | [diff] [blame] | 62 | @Override |
| 63 | public void remove () { |
| Nils Diewald | 44d5fa1 | 2015-01-15 21:31:52 +0000 | [diff] [blame] | 64 | messages.remove(this.index); |
| Nils Diewald | 2f2b067 | 2014-11-25 20:26:22 +0000 | [diff] [blame] | 65 | }; |
| 66 | }; |
| 67 | |
| Nils Diewald | 44d5fa1 | 2015-01-15 21:31:52 +0000 | [diff] [blame] | 68 | |
| Nils Diewald | 2f2b067 | 2014-11-25 20:26:22 +0000 | [diff] [blame] | 69 | /** |
| 70 | * Construct a new Messages object. |
| 71 | */ |
| Nils Diewald | c471b18 | 2014-11-19 22:51:15 +0000 | [diff] [blame] | 72 | public Messages () { |
| Nils Diewald | 44d5fa1 | 2015-01-15 21:31:52 +0000 | [diff] [blame] | 73 | this.messages = new ArrayList<Message>(3); |
| Nils Diewald | c471b18 | 2014-11-19 22:51:15 +0000 | [diff] [blame] | 74 | }; |
| 75 | |
| Nils Diewald | 44d5fa1 | 2015-01-15 21:31:52 +0000 | [diff] [blame] | 76 | |
| Nils Diewald | c471b18 | 2014-11-19 22:51:15 +0000 | [diff] [blame] | 77 | /** |
| Nils Diewald | 2f2b067 | 2014-11-25 20:26:22 +0000 | [diff] [blame] | 78 | * Get the iterator object. |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 79 | * |
| Nils Diewald | 2f2b067 | 2014-11-25 20:26:22 +0000 | [diff] [blame] | 80 | * @return Iterator for Message object. |
| 81 | */ |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 82 | public Iterator<Message> iterator () { |
| Nils Diewald | 2f2b067 | 2014-11-25 20:26:22 +0000 | [diff] [blame] | 83 | return new MessageIterator(); |
| 84 | }; |
| 85 | |
| Nils Diewald | 44d5fa1 | 2015-01-15 21:31:52 +0000 | [diff] [blame] | 86 | |
| Nils Diewald | 2f2b067 | 2014-11-25 20:26:22 +0000 | [diff] [blame] | 87 | /** |
| 88 | * Append a new message. |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 89 | * |
| 90 | * @param code |
| 91 | * Integer code representation of the warning |
| 92 | * @param msg |
| 93 | * String representation of the warning |
| 94 | * @param terms |
| 95 | * Optional strings of additional information |
| Nils Diewald | 2f2b067 | 2014-11-25 20:26:22 +0000 | [diff] [blame] | 96 | * @return New Message object |
| Nils Diewald | c471b18 | 2014-11-19 22:51:15 +0000 | [diff] [blame] | 97 | */ |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 98 | public Message add (int code, String message, String ... terms) { |
| Nils Diewald | 44d5fa1 | 2015-01-15 21:31:52 +0000 | [diff] [blame] | 99 | Message newMsg = new Message(code, message); |
| 100 | messages.add(newMsg); |
| 101 | if (terms != null) |
| 102 | for (String t : terms) |
| 103 | newMsg.addParameter(t); |
| 104 | return newMsg; |
| Nils Diewald | c471b18 | 2014-11-19 22:51:15 +0000 | [diff] [blame] | 105 | }; |
| 106 | |
| Nils Diewald | 44d5fa1 | 2015-01-15 21:31:52 +0000 | [diff] [blame] | 107 | |
| Nils Diewald | c471b18 | 2014-11-19 22:51:15 +0000 | [diff] [blame] | 108 | /** |
| Nils Diewald | 2f2b067 | 2014-11-25 20:26:22 +0000 | [diff] [blame] | 109 | * Append an existing message. |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 110 | * |
| 111 | * @param msg |
| 112 | * Message object to be added. Message will be cloned. |
| Nils Diewald | 2f2b067 | 2014-11-25 20:26:22 +0000 | [diff] [blame] | 113 | * @return Cloned Message object |
| Nils Diewald | c471b18 | 2014-11-19 22:51:15 +0000 | [diff] [blame] | 114 | */ |
| 115 | public Message add (Message msg) { |
| Nils Diewald | 44d5fa1 | 2015-01-15 21:31:52 +0000 | [diff] [blame] | 116 | try { |
| 117 | Message msgClone = (Message) msg.clone(); |
| 118 | messages.add(msgClone); |
| 119 | return msgClone; |
| 120 | } |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 121 | catch (CloneNotSupportedException e) {}; |
| Nils Diewald | 44d5fa1 | 2015-01-15 21:31:52 +0000 | [diff] [blame] | 122 | return (Message) null; |
| Nils Diewald | c471b18 | 2014-11-19 22:51:15 +0000 | [diff] [blame] | 123 | }; |
| 124 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 125 | |
| Nils Diewald | c471b18 | 2014-11-19 22:51:15 +0000 | [diff] [blame] | 126 | /** |
| Nils Diewald | 2f2b067 | 2014-11-25 20:26:22 +0000 | [diff] [blame] | 127 | * Append an existing message comming from a JsonNode. |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 128 | * |
| 129 | * @param node |
| 130 | * <code>JsonNode</code> representing a message |
| Nils Diewald | 2f2b067 | 2014-11-25 20:26:22 +0000 | [diff] [blame] | 131 | * @return New Message object |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 132 | * @throws QueryException |
| 133 | * if notification is not well formed (Error 750) |
| Nils Diewald | c471b18 | 2014-11-19 22:51:15 +0000 | [diff] [blame] | 134 | */ |
| 135 | public Message add (JsonNode msg) throws QueryException { |
| Nils Diewald | 44d5fa1 | 2015-01-15 21:31:52 +0000 | [diff] [blame] | 136 | if (!msg.isArray() || !msg.has(0)) |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 137 | throw new QueryException(750, |
| 138 | "Passed notifications are not well formed"); |
| Nils Diewald | c471b18 | 2014-11-19 22:51:15 +0000 | [diff] [blame] | 139 | |
| Nils Diewald | 44d5fa1 | 2015-01-15 21:31:52 +0000 | [diff] [blame] | 140 | // Valid message |
| 141 | Message newMsg = new Message(); |
| 142 | short i = 1; |
| 143 | if (msg.get(0).isNumber()) { |
| 144 | newMsg.setCode(msg.get(0).asInt()); |
| 145 | if (!msg.has(1)) |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 146 | throw new QueryException(750, |
| 147 | "Passed notifications are not well formed"); |
| Nils Diewald | 44d5fa1 | 2015-01-15 21:31:52 +0000 | [diff] [blame] | 148 | newMsg.setMessage(msg.get(1).asText()); |
| 149 | i++; |
| 150 | } |
| 151 | else { |
| 152 | newMsg.setMessage(msg.get(0).asText()); |
| 153 | }; |
| Nils Diewald | c471b18 | 2014-11-19 22:51:15 +0000 | [diff] [blame] | 154 | |
| Nils Diewald | 44d5fa1 | 2015-01-15 21:31:52 +0000 | [diff] [blame] | 155 | // Add parameters |
| 156 | while (msg.has(i)) |
| 157 | newMsg.addParameter(msg.get(i++).asText()); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 158 | |
| Nils Diewald | 44d5fa1 | 2015-01-15 21:31:52 +0000 | [diff] [blame] | 159 | // Add messages to list |
| 160 | this.add(newMsg); |
| 161 | return newMsg; |
| Nils Diewald | c471b18 | 2014-11-19 22:51:15 +0000 | [diff] [blame] | 162 | }; |
| 163 | |
| 164 | |
| 165 | /** |
| Nils Diewald | 2f2b067 | 2014-11-25 20:26:22 +0000 | [diff] [blame] | 166 | * Append existing messages. |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 167 | * |
| 168 | * @param msgs |
| 169 | * Messages object to be added. Messages will be |
| 170 | * cloned. |
| Nils Diewald | 2f2b067 | 2014-11-25 20:26:22 +0000 | [diff] [blame] | 171 | * @return Messages object for chaining. |
| Nils Diewald | c471b18 | 2014-11-19 22:51:15 +0000 | [diff] [blame] | 172 | */ |
| Nils Diewald | 2f2b067 | 2014-11-25 20:26:22 +0000 | [diff] [blame] | 173 | public Messages add (Messages msgs) { |
| Nils Diewald | 44d5fa1 | 2015-01-15 21:31:52 +0000 | [diff] [blame] | 174 | try { |
| 175 | for (Message msg : msgs.getMessages()) |
| 176 | this.add((Message) msg.clone()); |
| 177 | } |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 178 | catch (CloneNotSupportedException e) {}; |
| Nils Diewald | 44d5fa1 | 2015-01-15 21:31:52 +0000 | [diff] [blame] | 179 | return this; |
| Nils Diewald | c471b18 | 2014-11-19 22:51:15 +0000 | [diff] [blame] | 180 | }; |
| 181 | |
| Nils Diewald | 44d5fa1 | 2015-01-15 21:31:52 +0000 | [diff] [blame] | 182 | |
| Nils Diewald | c471b18 | 2014-11-19 22:51:15 +0000 | [diff] [blame] | 183 | /** |
| Nils Diewald | 2f2b067 | 2014-11-25 20:26:22 +0000 | [diff] [blame] | 184 | * Clear all messages. |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 185 | * |
| Nils Diewald | 2f2b067 | 2014-11-25 20:26:22 +0000 | [diff] [blame] | 186 | * @return Messages object for chaining |
| Nils Diewald | c471b18 | 2014-11-19 22:51:15 +0000 | [diff] [blame] | 187 | */ |
| Nils Diewald | 2f2b067 | 2014-11-25 20:26:22 +0000 | [diff] [blame] | 188 | public Messages clear () { |
| Nils Diewald | 44d5fa1 | 2015-01-15 21:31:52 +0000 | [diff] [blame] | 189 | this.messages.clear(); |
| 190 | return this; |
| Nils Diewald | c471b18 | 2014-11-19 22:51:15 +0000 | [diff] [blame] | 191 | }; |
| 192 | |
| Nils Diewald | 44d5fa1 | 2015-01-15 21:31:52 +0000 | [diff] [blame] | 193 | |
| Nils Diewald | 2f2b067 | 2014-11-25 20:26:22 +0000 | [diff] [blame] | 194 | /** |
| 195 | * Get the number of the messages. |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 196 | * |
| 197 | * @param Integer |
| 198 | * representing the number of messages in the list. |
| Nils Diewald | 2f2b067 | 2014-11-25 20:26:22 +0000 | [diff] [blame] | 199 | */ |
| Nils Diewald | c471b18 | 2014-11-19 22:51:15 +0000 | [diff] [blame] | 200 | public int size () { |
| Nils Diewald | 44d5fa1 | 2015-01-15 21:31:52 +0000 | [diff] [blame] | 201 | return this.messages.size(); |
| Nils Diewald | c471b18 | 2014-11-19 22:51:15 +0000 | [diff] [blame] | 202 | }; |
| 203 | |
| Nils Diewald | 2f2b067 | 2014-11-25 20:26:22 +0000 | [diff] [blame] | 204 | |
| 205 | /** |
| 206 | * Return a specific message based on an index. |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 207 | * |
| 208 | * @param index |
| 209 | * The index of the message in the list of messages. |
| 210 | * @return The message in case it exists, otherwise |
| 211 | * <code>null</code> |
| Nils Diewald | 2f2b067 | 2014-11-25 20:26:22 +0000 | [diff] [blame] | 212 | */ |
| Nils Diewald | c471b18 | 2014-11-19 22:51:15 +0000 | [diff] [blame] | 213 | @JsonIgnore |
| 214 | public Message get (int index) { |
| Nils Diewald | 44d5fa1 | 2015-01-15 21:31:52 +0000 | [diff] [blame] | 215 | if (index >= this.size()) |
| 216 | return (Message) null; |
| 217 | return this.messages.get(index); |
| Nils Diewald | c471b18 | 2014-11-19 22:51:15 +0000 | [diff] [blame] | 218 | }; |
| 219 | |
| Nils Diewald | 44d5fa1 | 2015-01-15 21:31:52 +0000 | [diff] [blame] | 220 | |
| Nils Diewald | 2f2b067 | 2014-11-25 20:26:22 +0000 | [diff] [blame] | 221 | /** |
| 222 | * Return all messages. |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 223 | * |
| Nils Diewald | 2f2b067 | 2014-11-25 20:26:22 +0000 | [diff] [blame] | 224 | * @return List of all Message objects |
| 225 | */ |
| Nils Diewald | c471b18 | 2014-11-19 22:51:15 +0000 | [diff] [blame] | 226 | @JsonIgnore |
| 227 | public List<Message> getMessages () { |
| Nils Diewald | 44d5fa1 | 2015-01-15 21:31:52 +0000 | [diff] [blame] | 228 | return this.messages; |
| Nils Diewald | c471b18 | 2014-11-19 22:51:15 +0000 | [diff] [blame] | 229 | }; |
| 230 | |
| Nils Diewald | 2f2b067 | 2014-11-25 20:26:22 +0000 | [diff] [blame] | 231 | |
| 232 | /** |
| 233 | * Create a clone of the Messages. |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 234 | * |
| 235 | * @return The cloned messages object |
| 236 | * @throws CloneNotSupportedException |
| 237 | * if messages can't be cloned |
| Nils Diewald | 2f2b067 | 2014-11-25 20:26:22 +0000 | [diff] [blame] | 238 | */ |
| 239 | public Object clone () throws CloneNotSupportedException { |
| Nils Diewald | 44d5fa1 | 2015-01-15 21:31:52 +0000 | [diff] [blame] | 240 | Messages clone = new Messages(); |
| 241 | for (Message m : this.messages) { |
| 242 | clone.add((Message) m.clone()); |
| 243 | }; |
| Nils Diewald | c471b18 | 2014-11-19 22:51:15 +0000 | [diff] [blame] | 244 | |
| Nils Diewald | 44d5fa1 | 2015-01-15 21:31:52 +0000 | [diff] [blame] | 245 | return clone; |
| Nils Diewald | c471b18 | 2014-11-19 22:51:15 +0000 | [diff] [blame] | 246 | }; |
| 247 | |
| Nils Diewald | 44d5fa1 | 2015-01-15 21:31:52 +0000 | [diff] [blame] | 248 | |
| Nils Diewald | c471b18 | 2014-11-19 22:51:15 +0000 | [diff] [blame] | 249 | /** |
| Nils Diewald | 2f2b067 | 2014-11-25 20:26:22 +0000 | [diff] [blame] | 250 | * Serialize Messages as a JsonNode. |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 251 | * |
| Nils Diewald | 2f2b067 | 2014-11-25 20:26:22 +0000 | [diff] [blame] | 252 | * @return JsonNode representation of all messages |
| Nils Diewald | c471b18 | 2014-11-19 22:51:15 +0000 | [diff] [blame] | 253 | */ |
| Nils Diewald | e1ecd5e | 2014-11-27 02:17:24 +0000 | [diff] [blame] | 254 | public JsonNode toJsonNode () { |
| Nils Diewald | 44d5fa1 | 2015-01-15 21:31:52 +0000 | [diff] [blame] | 255 | ArrayNode messageArray = mapper.createArrayNode(); |
| Akron | 7d45e6b | 2015-06-26 17:23:42 +0200 | [diff] [blame] | 256 | |
| 257 | for (Message msg : this.messages) { |
| 258 | |
| 259 | messageArray.add((JsonNode) msg.toJsonNode()); |
| 260 | }; |
| 261 | |
| Nils Diewald | 44d5fa1 | 2015-01-15 21:31:52 +0000 | [diff] [blame] | 262 | return (JsonNode) messageArray; |
| Nils Diewald | c471b18 | 2014-11-19 22:51:15 +0000 | [diff] [blame] | 263 | }; |
| 264 | |
| Nils Diewald | 2f2b067 | 2014-11-25 20:26:22 +0000 | [diff] [blame] | 265 | |
| Nils Diewald | c471b18 | 2014-11-19 22:51:15 +0000 | [diff] [blame] | 266 | /** |
| Nils Diewald | 2f2b067 | 2014-11-25 20:26:22 +0000 | [diff] [blame] | 267 | * Serialize Messages as a JSON string. |
| 268 | * <p> |
| 269 | * <blockquote><pre> |
| 270 | * [ |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 271 | * [123, "You are not allowed to serialize these messages"], |
| 272 | * [124, "Your request was invalid"] |
| Nils Diewald | 2f2b067 | 2014-11-25 20:26:22 +0000 | [diff] [blame] | 273 | * ] |
| 274 | * </pre></blockquote> |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 275 | * |
| Nils Diewald | 2f2b067 | 2014-11-25 20:26:22 +0000 | [diff] [blame] | 276 | * @return String representation of all messages |
| Nils Diewald | c471b18 | 2014-11-19 22:51:15 +0000 | [diff] [blame] | 277 | */ |
| Nils Diewald | e1ecd5e | 2014-11-27 02:17:24 +0000 | [diff] [blame] | 278 | public String toJsonString () { |
| Nils Diewald | 44d5fa1 | 2015-01-15 21:31:52 +0000 | [diff] [blame] | 279 | String msg = ""; |
| 280 | try { |
| 281 | return mapper.writeValueAsString(this.toJsonNode()); |
| 282 | } |
| 283 | catch (Exception e) { |
| Akron | 74748c6 | 2016-06-29 00:22:43 +0200 | [diff] [blame] | 284 | msg = ", " + quote(e.getLocalizedMessage()); |
| Nils Diewald | 44d5fa1 | 2015-01-15 21:31:52 +0000 | [diff] [blame] | 285 | }; |
| Nils Diewald | c471b18 | 2014-11-19 22:51:15 +0000 | [diff] [blame] | 286 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 287 | return "[620, " + "\"Unable to generate JSON\"" + msg + "]"; |
| Nils Diewald | c471b18 | 2014-11-19 22:51:15 +0000 | [diff] [blame] | 288 | }; |
| 289 | }; |